id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
20,300
|
poise/poise
|
lib/poise/utils.rb
|
Poise.Utils.check_block_arity!
|
def check_block_arity!(block, args)
# Convert the block to a lambda-style proc. You can't make this shit up.
obj = Object.new
obj.define_singleton_method(:block, &block)
block = obj.method(:block).to_proc
# Check
required_args = block.arity < 0 ? ~block.arity : block.arity
if args.length < required_args || (block.arity >= 0 && args.length > block.arity)
raise ArgumentError.new("wrong number of arguments (#{args.length} for #{required_args}#{block.arity < 0 ? '+' : ''})")
end
end
|
ruby
|
def check_block_arity!(block, args)
# Convert the block to a lambda-style proc. You can't make this shit up.
obj = Object.new
obj.define_singleton_method(:block, &block)
block = obj.method(:block).to_proc
# Check
required_args = block.arity < 0 ? ~block.arity : block.arity
if args.length < required_args || (block.arity >= 0 && args.length > block.arity)
raise ArgumentError.new("wrong number of arguments (#{args.length} for #{required_args}#{block.arity < 0 ? '+' : ''})")
end
end
|
[
"def",
"check_block_arity!",
"(",
"block",
",",
"args",
")",
"# Convert the block to a lambda-style proc. You can't make this shit up.",
"obj",
"=",
"Object",
".",
"new",
"obj",
".",
"define_singleton_method",
"(",
":block",
",",
"block",
")",
"block",
"=",
"obj",
".",
"method",
"(",
":block",
")",
".",
"to_proc",
"# Check",
"required_args",
"=",
"block",
".",
"arity",
"<",
"0",
"?",
"~",
"block",
".",
"arity",
":",
"block",
".",
"arity",
"if",
"args",
".",
"length",
"<",
"required_args",
"||",
"(",
"block",
".",
"arity",
">=",
"0",
"&&",
"args",
".",
"length",
">",
"block",
".",
"arity",
")",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"wrong number of arguments (#{args.length} for #{required_args}#{block.arity < 0 ? '+' : ''})\"",
")",
"end",
"end"
] |
Check that the given arguments match the given block. This is needed
because Ruby will nil-pad mismatched argspecs on blocks rather than error.
@since 2.3.0
@param block [Proc] Block to check.
@param args [Array<Object>] Arguments to check.
@return [void]
|
[
"Check",
"that",
"the",
"given",
"arguments",
"match",
"the",
"given",
"block",
".",
"This",
"is",
"needed",
"because",
"Ruby",
"will",
"nil",
"-",
"pad",
"mismatched",
"argspecs",
"on",
"blocks",
"rather",
"than",
"error",
"."
] |
07c33d4f844cf6e97cf349a12f06448d0db9a8d2
|
https://github.com/poise/poise/blob/07c33d4f844cf6e97cf349a12f06448d0db9a8d2/lib/poise/utils.rb#L168-L178
|
20,301
|
kontena/kong-client-ruby
|
lib/kong/consumer.rb
|
Kong.Consumer.oauth_apps
|
def oauth_apps
apps = []
response = client.get("#{@api_end_point}#{self.id}/oauth2") rescue nil
if response
response['data'].each do |attributes|
apps << Kong::OAuthApp.new(attributes)
end
end
apps
end
|
ruby
|
def oauth_apps
apps = []
response = client.get("#{@api_end_point}#{self.id}/oauth2") rescue nil
if response
response['data'].each do |attributes|
apps << Kong::OAuthApp.new(attributes)
end
end
apps
end
|
[
"def",
"oauth_apps",
"apps",
"=",
"[",
"]",
"response",
"=",
"client",
".",
"get",
"(",
"\"#{@api_end_point}#{self.id}/oauth2\"",
")",
"rescue",
"nil",
"if",
"response",
"response",
"[",
"'data'",
"]",
".",
"each",
"do",
"|",
"attributes",
"|",
"apps",
"<<",
"Kong",
"::",
"OAuthApp",
".",
"new",
"(",
"attributes",
")",
"end",
"end",
"apps",
"end"
] |
List OAuth applications
@return [Array<Kong::OAuthApp>]
|
[
"List",
"OAuth",
"applications"
] |
028c8913388f46c7b3a41984f36687d147f74442
|
https://github.com/kontena/kong-client-ruby/blob/028c8913388f46c7b3a41984f36687d147f74442/lib/kong/consumer.rb#L25-L34
|
20,302
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bgp_af.rb
|
Cisco.RouterBgpAF.dampening_half_time
|
def dampening_half_time
return nil if dampening.nil? || dampening_routemap_configured?
if dampening.is_a?(Array) && !dampening.empty?
dampening[0].to_i
else
default_dampening_half_time
end
end
|
ruby
|
def dampening_half_time
return nil if dampening.nil? || dampening_routemap_configured?
if dampening.is_a?(Array) && !dampening.empty?
dampening[0].to_i
else
default_dampening_half_time
end
end
|
[
"def",
"dampening_half_time",
"return",
"nil",
"if",
"dampening",
".",
"nil?",
"||",
"dampening_routemap_configured?",
"if",
"dampening",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"!",
"dampening",
".",
"empty?",
"dampening",
"[",
"0",
"]",
".",
"to_i",
"else",
"default_dampening_half_time",
"end",
"end"
] |
For all of the following dampening getters, half_time, reuse_time,
suppress_time, and max_suppress_time, return nil if dampening
is not configured, but also return nil if a dampening routemap
is configured because they are mutually exclusive.
|
[
"For",
"all",
"of",
"the",
"following",
"dampening",
"getters",
"half_time",
"reuse_time",
"suppress_time",
"and",
"max_suppress_time",
"return",
"nil",
"if",
"dampening",
"is",
"not",
"configured",
"but",
"also",
"return",
"nil",
"if",
"a",
"dampening",
"routemap",
"is",
"configured",
"because",
"they",
"are",
"mutually",
"exclusive",
"."
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bgp_af.rb#L229-L236
|
20,303
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bgp_af.rb
|
Cisco.RouterBgpAF.method_missing
|
def method_missing(*args)
name = args[0].to_s
if args.length == 1 # Getter
if name =~ /^default_(.*)$/
config_get_default('bgp_af', Regexp.last_match(1))
else
config_get('bgp_af', name, @get_args)
end
elsif args.length == 2 && name =~ /^(.*)=$/ # Setter
set_args_keys(state: args[1] ? '' : 'no')
config_set('bgp_af', Regexp.last_match(1), @set_args)
else
super
end
end
|
ruby
|
def method_missing(*args)
name = args[0].to_s
if args.length == 1 # Getter
if name =~ /^default_(.*)$/
config_get_default('bgp_af', Regexp.last_match(1))
else
config_get('bgp_af', name, @get_args)
end
elsif args.length == 2 && name =~ /^(.*)=$/ # Setter
set_args_keys(state: args[1] ? '' : 'no')
config_set('bgp_af', Regexp.last_match(1), @set_args)
else
super
end
end
|
[
"def",
"method_missing",
"(",
"*",
"args",
")",
"name",
"=",
"args",
"[",
"0",
"]",
".",
"to_s",
"if",
"args",
".",
"length",
"==",
"1",
"# Getter",
"if",
"name",
"=~",
"/",
"/",
"config_get_default",
"(",
"'bgp_af'",
",",
"Regexp",
".",
"last_match",
"(",
"1",
")",
")",
"else",
"config_get",
"(",
"'bgp_af'",
",",
"name",
",",
"@get_args",
")",
"end",
"elsif",
"args",
".",
"length",
"==",
"2",
"&&",
"name",
"=~",
"/",
"/",
"# Setter",
"set_args_keys",
"(",
"state",
":",
"args",
"[",
"1",
"]",
"?",
"''",
":",
"'no'",
")",
"config_set",
"(",
"'bgp_af'",
",",
"Regexp",
".",
"last_match",
"(",
"1",
")",
",",
"@set_args",
")",
"else",
"super",
"end",
"end"
] |
Universal Getter, Default Getter, and Setter
|
[
"Universal",
"Getter",
"Default",
"Getter",
"and",
"Setter"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bgp_af.rb#L508-L522
|
20,304
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bgp_af.rb
|
Cisco.RouterBgpAF.respond_to?
|
def respond_to?(method_sym, _include_private=false)
name = method_sym.to_s
key = :getter?
if name =~ /^(.*)=$/
name = Regexp.last_match(1)
# Use table_map_set() to set these properties
return false if name == 'table_map' || name == 'table_map_filter'
key = :setter?
elsif name =~ /^default_(.*)$/
name = Regexp.last_match(1)
key = :default_value?
end
begin
ref = node.cmd_ref.lookup('bgp_af', name)
ref.send(key)
rescue IndexError
super
end
end
|
ruby
|
def respond_to?(method_sym, _include_private=false)
name = method_sym.to_s
key = :getter?
if name =~ /^(.*)=$/
name = Regexp.last_match(1)
# Use table_map_set() to set these properties
return false if name == 'table_map' || name == 'table_map_filter'
key = :setter?
elsif name =~ /^default_(.*)$/
name = Regexp.last_match(1)
key = :default_value?
end
begin
ref = node.cmd_ref.lookup('bgp_af', name)
ref.send(key)
rescue IndexError
super
end
end
|
[
"def",
"respond_to?",
"(",
"method_sym",
",",
"_include_private",
"=",
"false",
")",
"name",
"=",
"method_sym",
".",
"to_s",
"key",
"=",
":getter?",
"if",
"name",
"=~",
"/",
"/",
"name",
"=",
"Regexp",
".",
"last_match",
"(",
"1",
")",
"# Use table_map_set() to set these properties",
"return",
"false",
"if",
"name",
"==",
"'table_map'",
"||",
"name",
"==",
"'table_map_filter'",
"key",
"=",
":setter?",
"elsif",
"name",
"=~",
"/",
"/",
"name",
"=",
"Regexp",
".",
"last_match",
"(",
"1",
")",
"key",
"=",
":default_value?",
"end",
"begin",
"ref",
"=",
"node",
".",
"cmd_ref",
".",
"lookup",
"(",
"'bgp_af'",
",",
"name",
")",
"ref",
".",
"send",
"(",
"key",
")",
"rescue",
"IndexError",
"super",
"end",
"end"
] |
Is the given name available in the YAML?
|
[
"Is",
"the",
"given",
"name",
"available",
"in",
"the",
"YAML?"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bgp_af.rb#L525-L543
|
20,305
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/ace.rb
|
Cisco.Ace.ace_get
|
def ace_get
str = config_get('acl', 'ace', @get_args)
return nil if str.nil?
remark = Regexp.new('(?<seqno>\d+) remark (?<remark>.*)').match(str)
return remark unless remark.nil?
# specialized icmp protocol handling
return icmp_ace_get(str) if str.include?('icmp')
# rubocop:disable Metrics/LineLength
regexp = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<src_port>range \S+ \S+|(lt|eq|gt|neq|portgroup) \S+)?'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_port>range \S+ \S+|(lt|eq|gt|neq|portgroup) \S+)?'\
' *(?<tcp_flags>(ack *|fin *|urg *|syn *|psh *|rst *)*)?'\
' *(?<established>established)?'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<http_method>http-method (\d+|connect|delete|get|head|post|put|trace))?'\
' *(?<tcp_option_length>tcp-option-length \d+)?'\
' *(?<redirect>redirect \S+)?'\
' *(?<log>log)?')
# rubocop:enable Metrics/LineLength
regexp.match(str)
end
|
ruby
|
def ace_get
str = config_get('acl', 'ace', @get_args)
return nil if str.nil?
remark = Regexp.new('(?<seqno>\d+) remark (?<remark>.*)').match(str)
return remark unless remark.nil?
# specialized icmp protocol handling
return icmp_ace_get(str) if str.include?('icmp')
# rubocop:disable Metrics/LineLength
regexp = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<src_port>range \S+ \S+|(lt|eq|gt|neq|portgroup) \S+)?'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_port>range \S+ \S+|(lt|eq|gt|neq|portgroup) \S+)?'\
' *(?<tcp_flags>(ack *|fin *|urg *|syn *|psh *|rst *)*)?'\
' *(?<established>established)?'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<http_method>http-method (\d+|connect|delete|get|head|post|put|trace))?'\
' *(?<tcp_option_length>tcp-option-length \d+)?'\
' *(?<redirect>redirect \S+)?'\
' *(?<log>log)?')
# rubocop:enable Metrics/LineLength
regexp.match(str)
end
|
[
"def",
"ace_get",
"str",
"=",
"config_get",
"(",
"'acl'",
",",
"'ace'",
",",
"@get_args",
")",
"return",
"nil",
"if",
"str",
".",
"nil?",
"remark",
"=",
"Regexp",
".",
"new",
"(",
"'(?<seqno>\\d+) remark (?<remark>.*)'",
")",
".",
"match",
"(",
"str",
")",
"return",
"remark",
"unless",
"remark",
".",
"nil?",
"# specialized icmp protocol handling",
"return",
"icmp_ace_get",
"(",
"str",
")",
"if",
"str",
".",
"include?",
"(",
"'icmp'",
")",
"# rubocop:disable Metrics/LineLength",
"regexp",
"=",
"Regexp",
".",
"new",
"(",
"'(?<seqno>\\d+) (?<action>\\S+)'",
"' *(?<proto>\\d+|\\S+)'",
"' *(?<src_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<src_port>range \\S+ \\S+|(lt|eq|gt|neq|portgroup) \\S+)?'",
"' *(?<dst_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<dst_port>range \\S+ \\S+|(lt|eq|gt|neq|portgroup) \\S+)?'",
"' *(?<tcp_flags>(ack *|fin *|urg *|syn *|psh *|rst *)*)?'",
"' *(?<established>established)?'",
"' *(?<precedence>precedence \\S+)?'",
"' *(?<dscp>dscp \\S+)?'",
"' *(?<time_range>time-range \\S+)?'",
"' *(?<packet_length>packet-length (range \\d+ \\d+|(lt|eq|gt|neq) \\d+))?'",
"' *(?<ttl>ttl \\d+)?'",
"' *(?<http_method>http-method (\\d+|connect|delete|get|head|post|put|trace))?'",
"' *(?<tcp_option_length>tcp-option-length \\d+)?'",
"' *(?<redirect>redirect \\S+)?'",
"' *(?<log>log)?'",
")",
"# rubocop:enable Metrics/LineLength",
"regexp",
".",
"match",
"(",
"str",
")",
"end"
] |
common ace getter
|
[
"common",
"ace",
"getter"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/ace.rb#L70-L100
|
20,306
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/ace.rb
|
Cisco.Ace.icmp_ace_get
|
def icmp_ace_get(str)
# rubocop:disable Metrics/LineLength
# fragments is nvgen at a different location than all other
# proto_option so get rid of it so as not to mess up other fields
str.sub!('fragments ', '')
regexp = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<proto_option>\S+)?'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<vlan>vlan \d+)?'\
' *(?<set_erspan_gre_proto>set-erspan-gre-proto \d+)?'\
' *(?<set_erspan_dscp>set-erspan-dscp \d+)?'\
' *(?<redirect>redirect \S+)?')
regexp_no_proto_option = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<vlan>vlan \d+)?'\
' *(?<set_erspan_gre_proto>set-erspan-gre-proto \d+)?'\
' *(?<set_erspan_dscp>set-erspan-dscp \d+)?'\
' *(?<redirect>redirect \S+)?')
temp = regexp.match(str)
po = temp[:proto_option]
if po.nil?
return temp
# redirect can be proto_option or an actual redirect to interface
elsif po.strip.match(/redirect$/)
if str.match(/Ethernet|port-channel/)
# if proto_option is given as redirect and also redirect to intf
# we need to do extra processing
return temp if check_redirect_repeat(str)
return regexp_no_proto_option.match(str)
end
# the reserved keywords check
elsif po.strip.match(/precedence$|dscp$|time-range$|packet-length$|ttl$|vlan$|set-erspan-gre-proto$|set-erspan-dscp$|log$/)
return regexp_no_proto_option.match(str)
else
return temp
end
# rubocop:enable Metrics/LineLength
end
|
ruby
|
def icmp_ace_get(str)
# rubocop:disable Metrics/LineLength
# fragments is nvgen at a different location than all other
# proto_option so get rid of it so as not to mess up other fields
str.sub!('fragments ', '')
regexp = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<proto_option>\S+)?'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<vlan>vlan \d+)?'\
' *(?<set_erspan_gre_proto>set-erspan-gre-proto \d+)?'\
' *(?<set_erspan_dscp>set-erspan-dscp \d+)?'\
' *(?<redirect>redirect \S+)?')
regexp_no_proto_option = Regexp.new('(?<seqno>\d+) (?<action>\S+)'\
' *(?<proto>\d+|\S+)'\
' *(?<src_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<dst_addr>any|host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+|addrgroup \S+)'\
' *(?<precedence>precedence \S+)?'\
' *(?<dscp>dscp \S+)?'\
' *(?<time_range>time-range \S+)?'\
' *(?<packet_length>packet-length (range \d+ \d+|(lt|eq|gt|neq) \d+))?'\
' *(?<ttl>ttl \d+)?'\
' *(?<vlan>vlan \d+)?'\
' *(?<set_erspan_gre_proto>set-erspan-gre-proto \d+)?'\
' *(?<set_erspan_dscp>set-erspan-dscp \d+)?'\
' *(?<redirect>redirect \S+)?')
temp = regexp.match(str)
po = temp[:proto_option]
if po.nil?
return temp
# redirect can be proto_option or an actual redirect to interface
elsif po.strip.match(/redirect$/)
if str.match(/Ethernet|port-channel/)
# if proto_option is given as redirect and also redirect to intf
# we need to do extra processing
return temp if check_redirect_repeat(str)
return regexp_no_proto_option.match(str)
end
# the reserved keywords check
elsif po.strip.match(/precedence$|dscp$|time-range$|packet-length$|ttl$|vlan$|set-erspan-gre-proto$|set-erspan-dscp$|log$/)
return regexp_no_proto_option.match(str)
else
return temp
end
# rubocop:enable Metrics/LineLength
end
|
[
"def",
"icmp_ace_get",
"(",
"str",
")",
"# rubocop:disable Metrics/LineLength",
"# fragments is nvgen at a different location than all other",
"# proto_option so get rid of it so as not to mess up other fields",
"str",
".",
"sub!",
"(",
"'fragments '",
",",
"''",
")",
"regexp",
"=",
"Regexp",
".",
"new",
"(",
"'(?<seqno>\\d+) (?<action>\\S+)'",
"' *(?<proto>\\d+|\\S+)'",
"' *(?<src_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<dst_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<proto_option>\\S+)?'",
"' *(?<precedence>precedence \\S+)?'",
"' *(?<dscp>dscp \\S+)?'",
"' *(?<time_range>time-range \\S+)?'",
"' *(?<packet_length>packet-length (range \\d+ \\d+|(lt|eq|gt|neq) \\d+))?'",
"' *(?<ttl>ttl \\d+)?'",
"' *(?<vlan>vlan \\d+)?'",
"' *(?<set_erspan_gre_proto>set-erspan-gre-proto \\d+)?'",
"' *(?<set_erspan_dscp>set-erspan-dscp \\d+)?'",
"' *(?<redirect>redirect \\S+)?'",
")",
"regexp_no_proto_option",
"=",
"Regexp",
".",
"new",
"(",
"'(?<seqno>\\d+) (?<action>\\S+)'",
"' *(?<proto>\\d+|\\S+)'",
"' *(?<src_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<dst_addr>any|host \\S+|[:\\.0-9a-fA-F]+ [:\\.0-9a-fA-F]+|[:\\.0-9a-fA-F]+\\/\\d+|addrgroup \\S+)'",
"' *(?<precedence>precedence \\S+)?'",
"' *(?<dscp>dscp \\S+)?'",
"' *(?<time_range>time-range \\S+)?'",
"' *(?<packet_length>packet-length (range \\d+ \\d+|(lt|eq|gt|neq) \\d+))?'",
"' *(?<ttl>ttl \\d+)?'",
"' *(?<vlan>vlan \\d+)?'",
"' *(?<set_erspan_gre_proto>set-erspan-gre-proto \\d+)?'",
"' *(?<set_erspan_dscp>set-erspan-dscp \\d+)?'",
"' *(?<redirect>redirect \\S+)?'",
")",
"temp",
"=",
"regexp",
".",
"match",
"(",
"str",
")",
"po",
"=",
"temp",
"[",
":proto_option",
"]",
"if",
"po",
".",
"nil?",
"return",
"temp",
"# redirect can be proto_option or an actual redirect to interface",
"elsif",
"po",
".",
"strip",
".",
"match",
"(",
"/",
"/",
")",
"if",
"str",
".",
"match",
"(",
"/",
"/",
")",
"# if proto_option is given as redirect and also redirect to intf",
"# we need to do extra processing",
"return",
"temp",
"if",
"check_redirect_repeat",
"(",
"str",
")",
"return",
"regexp_no_proto_option",
".",
"match",
"(",
"str",
")",
"end",
"# the reserved keywords check",
"elsif",
"po",
".",
"strip",
".",
"match",
"(",
"/",
"/",
")",
"return",
"regexp_no_proto_option",
".",
"match",
"(",
"str",
")",
"else",
"return",
"temp",
"end",
"# rubocop:enable Metrics/LineLength",
"end"
] |
icmp ace getter
|
[
"icmp",
"ace",
"getter"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/ace.rb#L103-L154
|
20,307
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface.rb
|
Cisco.Interface.hsrp_delay_minimum=
|
def hsrp_delay_minimum=(val)
Feature.hsrp_enable if val
config_set('interface', 'hsrp_delay', name: @name,
minimum: 'minimum', min: val, reload: '', rel: '')
end
|
ruby
|
def hsrp_delay_minimum=(val)
Feature.hsrp_enable if val
config_set('interface', 'hsrp_delay', name: @name,
minimum: 'minimum', min: val, reload: '', rel: '')
end
|
[
"def",
"hsrp_delay_minimum",
"=",
"(",
"val",
")",
"Feature",
".",
"hsrp_enable",
"if",
"val",
"config_set",
"(",
"'interface'",
",",
"'hsrp_delay'",
",",
"name",
":",
"@name",
",",
"minimum",
":",
"'minimum'",
",",
"min",
":",
"val",
",",
"reload",
":",
"''",
",",
"rel",
":",
"''",
")",
"end"
] |
hsrp delay minimum and reload are in the same CLI
but both can be set independent of each other
|
[
"hsrp",
"delay",
"minimum",
"and",
"reload",
"are",
"in",
"the",
"same",
"CLI",
"but",
"both",
"can",
"be",
"set",
"independent",
"of",
"each",
"other"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface.rb#L337-L341
|
20,308
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/stp_global.rb
|
Cisco.StpGlobal.bd_total_range_with_vlans
|
def bd_total_range_with_vlans
hash = Vlan.vlans
arr = []
hash.keys.each do |id|
arr << id.to_i
end
Utils.array_to_str(arr)
ret_arr = []
ret_arr << Utils.array_to_str(arr)
end
|
ruby
|
def bd_total_range_with_vlans
hash = Vlan.vlans
arr = []
hash.keys.each do |id|
arr << id.to_i
end
Utils.array_to_str(arr)
ret_arr = []
ret_arr << Utils.array_to_str(arr)
end
|
[
"def",
"bd_total_range_with_vlans",
"hash",
"=",
"Vlan",
".",
"vlans",
"arr",
"=",
"[",
"]",
"hash",
".",
"keys",
".",
"each",
"do",
"|",
"id",
"|",
"arr",
"<<",
"id",
".",
"to_i",
"end",
"Utils",
".",
"array_to_str",
"(",
"arr",
")",
"ret_arr",
"=",
"[",
"]",
"ret_arr",
"<<",
"Utils",
".",
"array_to_str",
"(",
"arr",
")",
"end"
] |
bridge-domain and vlans are mutually exclusive
so when there are vlans, we need to remove them
from the bd range while restting
|
[
"bridge",
"-",
"domain",
"and",
"vlans",
"are",
"mutually",
"exclusive",
"so",
"when",
"there",
"are",
"vlans",
"we",
"need",
"to",
"remove",
"them",
"from",
"the",
"bd",
"range",
"while",
"restting"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/stp_global.rb#L652-L661
|
20,309
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/itd_device_group_node.rb
|
Cisco.ItdDeviceGroupNode.hs_weight
|
def hs_weight(hs, wt)
if hs != hot_standby && hot_standby == default_hot_standby
self.lweight = wt unless weight == wt
self.lhot_standby = hs
elsif hs != hot_standby && hot_standby != default_hot_standby
self.lhot_standby = hs
self.lweight = wt unless weight == wt
elsif wt != weight && weight == default_weight
self.lweight = wt
elsif wt != weight && weight != default_weight
self.lweight = wt
end
set_args_keys_default
end
|
ruby
|
def hs_weight(hs, wt)
if hs != hot_standby && hot_standby == default_hot_standby
self.lweight = wt unless weight == wt
self.lhot_standby = hs
elsif hs != hot_standby && hot_standby != default_hot_standby
self.lhot_standby = hs
self.lweight = wt unless weight == wt
elsif wt != weight && weight == default_weight
self.lweight = wt
elsif wt != weight && weight != default_weight
self.lweight = wt
end
set_args_keys_default
end
|
[
"def",
"hs_weight",
"(",
"hs",
",",
"wt",
")",
"if",
"hs",
"!=",
"hot_standby",
"&&",
"hot_standby",
"==",
"default_hot_standby",
"self",
".",
"lweight",
"=",
"wt",
"unless",
"weight",
"==",
"wt",
"self",
".",
"lhot_standby",
"=",
"hs",
"elsif",
"hs",
"!=",
"hot_standby",
"&&",
"hot_standby",
"!=",
"default_hot_standby",
"self",
".",
"lhot_standby",
"=",
"hs",
"self",
".",
"lweight",
"=",
"wt",
"unless",
"weight",
"==",
"wt",
"elsif",
"wt",
"!=",
"weight",
"&&",
"weight",
"==",
"default_weight",
"self",
".",
"lweight",
"=",
"wt",
"elsif",
"wt",
"!=",
"weight",
"&&",
"weight",
"!=",
"default_weight",
"self",
".",
"lweight",
"=",
"wt",
"end",
"set_args_keys_default",
"end"
] |
Call this for setting hot_standby and weight together because
the CLI is pretty weird and it accepts these params in a very
particular way and they cannot even be reset unless proper
order is followed
|
[
"Call",
"this",
"for",
"setting",
"hot_standby",
"and",
"weight",
"together",
"because",
"the",
"CLI",
"is",
"pretty",
"weird",
"and",
"it",
"accepts",
"these",
"params",
"in",
"a",
"very",
"particular",
"way",
"and",
"they",
"cannot",
"even",
"be",
"reset",
"unless",
"proper",
"order",
"is",
"followed"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/itd_device_group_node.rb#L125-L138
|
20,310
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bridge_domain_vni.rb
|
Cisco.BridgeDomainVNI.curr_bd_vni_hash
|
def curr_bd_vni_hash
final_bd_vni = {}
curr_vni = config_get('bridge_domain_vni', 'member_vni')
curr_bd_vni = config_get('bridge_domain_vni', 'member_vni_bd')
return final_bd_vni if curr_vni.empty? || curr_bd_vni.empty?
curr_vni_list = BridgeDomainVNI.string_to_array(curr_vni)
curr_bd_vni_list = BridgeDomainVNI.string_to_array(curr_bd_vni)
hash_map = Hash[curr_bd_vni_list.zip(curr_vni_list.map)]
@bd_ids_list.each do |bd|
final_bd_vni[bd.to_i] = hash_map[bd.to_i] if hash_map.key?(bd.to_i)
end
final_bd_vni
end
|
ruby
|
def curr_bd_vni_hash
final_bd_vni = {}
curr_vni = config_get('bridge_domain_vni', 'member_vni')
curr_bd_vni = config_get('bridge_domain_vni', 'member_vni_bd')
return final_bd_vni if curr_vni.empty? || curr_bd_vni.empty?
curr_vni_list = BridgeDomainVNI.string_to_array(curr_vni)
curr_bd_vni_list = BridgeDomainVNI.string_to_array(curr_bd_vni)
hash_map = Hash[curr_bd_vni_list.zip(curr_vni_list.map)]
@bd_ids_list.each do |bd|
final_bd_vni[bd.to_i] = hash_map[bd.to_i] if hash_map.key?(bd.to_i)
end
final_bd_vni
end
|
[
"def",
"curr_bd_vni_hash",
"final_bd_vni",
"=",
"{",
"}",
"curr_vni",
"=",
"config_get",
"(",
"'bridge_domain_vni'",
",",
"'member_vni'",
")",
"curr_bd_vni",
"=",
"config_get",
"(",
"'bridge_domain_vni'",
",",
"'member_vni_bd'",
")",
"return",
"final_bd_vni",
"if",
"curr_vni",
".",
"empty?",
"||",
"curr_bd_vni",
".",
"empty?",
"curr_vni_list",
"=",
"BridgeDomainVNI",
".",
"string_to_array",
"(",
"curr_vni",
")",
"curr_bd_vni_list",
"=",
"BridgeDomainVNI",
".",
"string_to_array",
"(",
"curr_bd_vni",
")",
"hash_map",
"=",
"Hash",
"[",
"curr_bd_vni_list",
".",
"zip",
"(",
"curr_vni_list",
".",
"map",
")",
"]",
"@bd_ids_list",
".",
"each",
"do",
"|",
"bd",
"|",
"final_bd_vni",
"[",
"bd",
".",
"to_i",
"]",
"=",
"hash_map",
"[",
"bd",
".",
"to_i",
"]",
"if",
"hash_map",
".",
"key?",
"(",
"bd",
".",
"to_i",
")",
"end",
"final_bd_vni",
"end"
] |
Example clis;
system bridge-domain 101-200
bridge-domain 101-200
bridge-domain 101-110,120,141-145,180
member vni 6001-6011,5041-5044,8000,9000
config_get('bridge_domain_vni', 'member_vni')
will get the current member vni in this case
6001-6011,5041-5044,8000,9000
config_get('bridge_domain_vni', 'member_vni_bd')
will get the current bd's mapped to member vni in this case
101-110,120,141-145,180
The @bd_ids_list which is created when the BridgeDomainVNI object is
initialized which could be 101-110 bd range.
hash_map will have 101=>6001,102=>6002...120=>6011,141=>5041...180=>9000
And the final_bd_vni hash will be based of the initialized list
101=>6001,102=>6002,103=>6003....110=>6010 only.
|
[
"Example",
"clis",
";",
"system",
"bridge",
"-",
"domain",
"101",
"-",
"200",
"bridge",
"-",
"domain",
"101",
"-",
"200",
"bridge",
"-",
"domain",
"101",
"-",
"110",
"120",
"141",
"-",
"145",
"180",
"member",
"vni",
"6001",
"-",
"6011",
"5041",
"-",
"5044",
"8000",
"9000"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bridge_domain_vni.rb#L88-L102
|
20,311
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/node.rb
|
Cisco.Node.massage_structured
|
def massage_structured(get_args, ref)
# Nothing to do unless nxapi_structured.
return [get_args, ref] unless
ref.hash['get_data_format'] == :nxapi_structured
# The CmdRef object will contain a get_value Array with 2 values.
# The first value is the key to identify the correct row in the table
# of structured output and the second is the key to identify the data
# to retrieve.
#
# Example: Get vlanshowbr-vlanname in the row that contains a specific
# vlan_id.
# "get_value"=>["vlanshowbr-vlanid-utf <vlan_id>", "vlanshowbr-vlanname"]
#
# TBD: Why do we need to check is_a?(Array) here?
if ref.hash['get_value'].is_a?(Array) && ref.hash['get_value'].size >= 2
# Replace the get_value hash entry with the value after any tokens
# specified in the yaml file have been replaced and set get_args[:value]
# to nil so that the structured table data can be retrieved properly.
ref.hash['get_value'] = get_args[:value]
ref.hash['drill_down'] = true
get_args[:value] = nil
cache_flush
end
[get_args, ref]
end
|
ruby
|
def massage_structured(get_args, ref)
# Nothing to do unless nxapi_structured.
return [get_args, ref] unless
ref.hash['get_data_format'] == :nxapi_structured
# The CmdRef object will contain a get_value Array with 2 values.
# The first value is the key to identify the correct row in the table
# of structured output and the second is the key to identify the data
# to retrieve.
#
# Example: Get vlanshowbr-vlanname in the row that contains a specific
# vlan_id.
# "get_value"=>["vlanshowbr-vlanid-utf <vlan_id>", "vlanshowbr-vlanname"]
#
# TBD: Why do we need to check is_a?(Array) here?
if ref.hash['get_value'].is_a?(Array) && ref.hash['get_value'].size >= 2
# Replace the get_value hash entry with the value after any tokens
# specified in the yaml file have been replaced and set get_args[:value]
# to nil so that the structured table data can be retrieved properly.
ref.hash['get_value'] = get_args[:value]
ref.hash['drill_down'] = true
get_args[:value] = nil
cache_flush
end
[get_args, ref]
end
|
[
"def",
"massage_structured",
"(",
"get_args",
",",
"ref",
")",
"# Nothing to do unless nxapi_structured.",
"return",
"[",
"get_args",
",",
"ref",
"]",
"unless",
"ref",
".",
"hash",
"[",
"'get_data_format'",
"]",
"==",
":nxapi_structured",
"# The CmdRef object will contain a get_value Array with 2 values.",
"# The first value is the key to identify the correct row in the table",
"# of structured output and the second is the key to identify the data",
"# to retrieve.",
"#",
"# Example: Get vlanshowbr-vlanname in the row that contains a specific",
"# vlan_id.",
"# \"get_value\"=>[\"vlanshowbr-vlanid-utf <vlan_id>\", \"vlanshowbr-vlanname\"]",
"#",
"# TBD: Why do we need to check is_a?(Array) here?",
"if",
"ref",
".",
"hash",
"[",
"'get_value'",
"]",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"ref",
".",
"hash",
"[",
"'get_value'",
"]",
".",
"size",
">=",
"2",
"# Replace the get_value hash entry with the value after any tokens",
"# specified in the yaml file have been replaced and set get_args[:value]",
"# to nil so that the structured table data can be retrieved properly.",
"ref",
".",
"hash",
"[",
"'get_value'",
"]",
"=",
"get_args",
"[",
":value",
"]",
"ref",
".",
"hash",
"[",
"'drill_down'",
"]",
"=",
"true",
"get_args",
"[",
":value",
"]",
"=",
"nil",
"cache_flush",
"end",
"[",
"get_args",
",",
"ref",
"]",
"end"
] |
The yaml file may specifiy an Array as the get_value to drill down into
nxapi_structured table output. The table may contain multiple rows but
only one of the rows has the interesting data.
|
[
"The",
"yaml",
"file",
"may",
"specifiy",
"an",
"Array",
"as",
"the",
"get_value",
"to",
"drill",
"down",
"into",
"nxapi_structured",
"table",
"output",
".",
"The",
"table",
"may",
"contain",
"multiple",
"rows",
"but",
"only",
"one",
"of",
"the",
"rows",
"has",
"the",
"interesting",
"data",
"."
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/node.rb#L70-L95
|
20,312
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/node.rb
|
Cisco.Node.massage
|
def massage(value, ref)
Cisco::Logger.debug "Massaging '#{value}' (#{value.inspect})"
value = drill_down_structured(value, ref)
if value.is_a?(Array) && !ref.multiple
fail "Expected zero/one value but got '#{value}'" if value.length > 1
value = value[0]
end
if (value.nil? || value.to_s.empty?) &&
ref.default_value? && ref.auto_default
Cisco::Logger.debug "Default: #{ref.default_value}"
return ref.default_value
end
if ref.multiple && ref.hash['get_data_format'] == :nxapi_structured
return value if value.nil?
value = [value.to_s] if value.is_a?(String) || value.is_a?(Fixnum)
end
return value unless ref.kind
value = massage_kind(value, ref)
Cisco::Logger.debug "Massaged to '#{value}'"
value
end
|
ruby
|
def massage(value, ref)
Cisco::Logger.debug "Massaging '#{value}' (#{value.inspect})"
value = drill_down_structured(value, ref)
if value.is_a?(Array) && !ref.multiple
fail "Expected zero/one value but got '#{value}'" if value.length > 1
value = value[0]
end
if (value.nil? || value.to_s.empty?) &&
ref.default_value? && ref.auto_default
Cisco::Logger.debug "Default: #{ref.default_value}"
return ref.default_value
end
if ref.multiple && ref.hash['get_data_format'] == :nxapi_structured
return value if value.nil?
value = [value.to_s] if value.is_a?(String) || value.is_a?(Fixnum)
end
return value unless ref.kind
value = massage_kind(value, ref)
Cisco::Logger.debug "Massaged to '#{value}'"
value
end
|
[
"def",
"massage",
"(",
"value",
",",
"ref",
")",
"Cisco",
"::",
"Logger",
".",
"debug",
"\"Massaging '#{value}' (#{value.inspect})\"",
"value",
"=",
"drill_down_structured",
"(",
"value",
",",
"ref",
")",
"if",
"value",
".",
"is_a?",
"(",
"Array",
")",
"&&",
"!",
"ref",
".",
"multiple",
"fail",
"\"Expected zero/one value but got '#{value}'\"",
"if",
"value",
".",
"length",
">",
"1",
"value",
"=",
"value",
"[",
"0",
"]",
"end",
"if",
"(",
"value",
".",
"nil?",
"||",
"value",
".",
"to_s",
".",
"empty?",
")",
"&&",
"ref",
".",
"default_value?",
"&&",
"ref",
".",
"auto_default",
"Cisco",
"::",
"Logger",
".",
"debug",
"\"Default: #{ref.default_value}\"",
"return",
"ref",
".",
"default_value",
"end",
"if",
"ref",
".",
"multiple",
"&&",
"ref",
".",
"hash",
"[",
"'get_data_format'",
"]",
"==",
":nxapi_structured",
"return",
"value",
"if",
"value",
".",
"nil?",
"value",
"=",
"[",
"value",
".",
"to_s",
"]",
"if",
"value",
".",
"is_a?",
"(",
"String",
")",
"||",
"value",
".",
"is_a?",
"(",
"Fixnum",
")",
"end",
"return",
"value",
"unless",
"ref",
".",
"kind",
"value",
"=",
"massage_kind",
"(",
"value",
",",
"ref",
")",
"Cisco",
"::",
"Logger",
".",
"debug",
"\"Massaged to '#{value}'\"",
"value",
"end"
] |
Attempt to massage the given value into the format specified by the
given CmdRef object.
|
[
"Attempt",
"to",
"massage",
"the",
"given",
"value",
"into",
"the",
"format",
"specified",
"by",
"the",
"given",
"CmdRef",
"object",
"."
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/node.rb#L140-L160
|
20,313
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/command_reference.rb
|
Cisco.CommandReference.lookup
|
def lookup(feature, name)
value = @hash[feature]
value = value[name] if value.is_a? Hash
fail IndexError, "No CmdRef defined for #{feature}, #{name}" if value.nil?
value
end
|
ruby
|
def lookup(feature, name)
value = @hash[feature]
value = value[name] if value.is_a? Hash
fail IndexError, "No CmdRef defined for #{feature}, #{name}" if value.nil?
value
end
|
[
"def",
"lookup",
"(",
"feature",
",",
"name",
")",
"value",
"=",
"@hash",
"[",
"feature",
"]",
"value",
"=",
"value",
"[",
"name",
"]",
"if",
"value",
".",
"is_a?",
"Hash",
"fail",
"IndexError",
",",
"\"No CmdRef defined for #{feature}, #{name}\"",
"if",
"value",
".",
"nil?",
"value",
"end"
] |
Get the command reference
|
[
"Get",
"the",
"command",
"reference"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/command_reference.rb#L424-L429
|
20,314
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/command_reference.rb
|
Cisco.CommandReference.validate_yaml
|
def validate_yaml(node, filename, depth=0, parents=nil)
return unless node && (mapping?(node) || node.children)
# Psych wraps everything in a Document instance, which we ignore.
unless node.class.ancestors.any? { |name| /Document/ =~ name.to_s }
depth += 1
end
debug "Validating #{node.class} at depth #{depth}"
# No special validation for non-mapping nodes - just recurse
unless mapping?(node)
node.children.each do |child|
validate_yaml(child, filename, depth, parents)
end
return
end
# For Mappings, we validate more extensively:
# 1. no duplicate keys are allowed (Psych doesn't catch this)
# 2. Features must be listed in alphabetical order for maintainability
# Take advantage of our known YAML structure to assign labels by depth
label = %w(feature name param).fetch(depth, 'key')
# Get the key nodes and value nodes under this mapping
key_children, val_children = get_keys_values_from_map(node)
# Get an array of key names
key_arr = key_children.map(&:value)
# Make sure no duplicate key names.
# If searching from the start of the array finds a name at one index,
# but searching from the end of the array finds it at a different one,
# then we have a duplicate.
dup = key_arr.detect { |e| key_arr.index(e) != key_arr.rindex(e) }
if dup
msg = "Duplicate #{label} '#{dup}'#{parents} in #{filename}!"
fail msg
end
# Enforce alphabetical ordering of features (only).
# We can extend this later to enforce ordering of names if desired
# by checking at depth 2 as well.
if depth == 1
last_key = nil
key_arr.each do |key|
if last_key && key < last_key
fail "features out of order in #{filename}: (#{last_key} > #{key})"
end
last_key = key
end
end
# Recurse to the children. We get a little fancy here so as to be able
# to provide more meaningful debug/error messages, such as:
# Duplicate param 'default_value' under feature 'foo', name 'bar'
key_children.zip(val_children).each do |key_node, val_node|
if parents
new_parents = parents + ", #{label} '#{key_node.value}'"
else
new_parents = " under #{label} '#{key_node.value}'"
end
validate_yaml(key_node, filename, depth, new_parents) # unnecessary?
validate_yaml(val_node, filename, depth, new_parents)
end
end
|
ruby
|
def validate_yaml(node, filename, depth=0, parents=nil)
return unless node && (mapping?(node) || node.children)
# Psych wraps everything in a Document instance, which we ignore.
unless node.class.ancestors.any? { |name| /Document/ =~ name.to_s }
depth += 1
end
debug "Validating #{node.class} at depth #{depth}"
# No special validation for non-mapping nodes - just recurse
unless mapping?(node)
node.children.each do |child|
validate_yaml(child, filename, depth, parents)
end
return
end
# For Mappings, we validate more extensively:
# 1. no duplicate keys are allowed (Psych doesn't catch this)
# 2. Features must be listed in alphabetical order for maintainability
# Take advantage of our known YAML structure to assign labels by depth
label = %w(feature name param).fetch(depth, 'key')
# Get the key nodes and value nodes under this mapping
key_children, val_children = get_keys_values_from_map(node)
# Get an array of key names
key_arr = key_children.map(&:value)
# Make sure no duplicate key names.
# If searching from the start of the array finds a name at one index,
# but searching from the end of the array finds it at a different one,
# then we have a duplicate.
dup = key_arr.detect { |e| key_arr.index(e) != key_arr.rindex(e) }
if dup
msg = "Duplicate #{label} '#{dup}'#{parents} in #{filename}!"
fail msg
end
# Enforce alphabetical ordering of features (only).
# We can extend this later to enforce ordering of names if desired
# by checking at depth 2 as well.
if depth == 1
last_key = nil
key_arr.each do |key|
if last_key && key < last_key
fail "features out of order in #{filename}: (#{last_key} > #{key})"
end
last_key = key
end
end
# Recurse to the children. We get a little fancy here so as to be able
# to provide more meaningful debug/error messages, such as:
# Duplicate param 'default_value' under feature 'foo', name 'bar'
key_children.zip(val_children).each do |key_node, val_node|
if parents
new_parents = parents + ", #{label} '#{key_node.value}'"
else
new_parents = " under #{label} '#{key_node.value}'"
end
validate_yaml(key_node, filename, depth, new_parents) # unnecessary?
validate_yaml(val_node, filename, depth, new_parents)
end
end
|
[
"def",
"validate_yaml",
"(",
"node",
",",
"filename",
",",
"depth",
"=",
"0",
",",
"parents",
"=",
"nil",
")",
"return",
"unless",
"node",
"&&",
"(",
"mapping?",
"(",
"node",
")",
"||",
"node",
".",
"children",
")",
"# Psych wraps everything in a Document instance, which we ignore.",
"unless",
"node",
".",
"class",
".",
"ancestors",
".",
"any?",
"{",
"|",
"name",
"|",
"/",
"/",
"=~",
"name",
".",
"to_s",
"}",
"depth",
"+=",
"1",
"end",
"debug",
"\"Validating #{node.class} at depth #{depth}\"",
"# No special validation for non-mapping nodes - just recurse",
"unless",
"mapping?",
"(",
"node",
")",
"node",
".",
"children",
".",
"each",
"do",
"|",
"child",
"|",
"validate_yaml",
"(",
"child",
",",
"filename",
",",
"depth",
",",
"parents",
")",
"end",
"return",
"end",
"# For Mappings, we validate more extensively:",
"# 1. no duplicate keys are allowed (Psych doesn't catch this)",
"# 2. Features must be listed in alphabetical order for maintainability",
"# Take advantage of our known YAML structure to assign labels by depth",
"label",
"=",
"%w(",
"feature",
"name",
"param",
")",
".",
"fetch",
"(",
"depth",
",",
"'key'",
")",
"# Get the key nodes and value nodes under this mapping",
"key_children",
",",
"val_children",
"=",
"get_keys_values_from_map",
"(",
"node",
")",
"# Get an array of key names",
"key_arr",
"=",
"key_children",
".",
"map",
"(",
":value",
")",
"# Make sure no duplicate key names.",
"# If searching from the start of the array finds a name at one index,",
"# but searching from the end of the array finds it at a different one,",
"# then we have a duplicate.",
"dup",
"=",
"key_arr",
".",
"detect",
"{",
"|",
"e",
"|",
"key_arr",
".",
"index",
"(",
"e",
")",
"!=",
"key_arr",
".",
"rindex",
"(",
"e",
")",
"}",
"if",
"dup",
"msg",
"=",
"\"Duplicate #{label} '#{dup}'#{parents} in #{filename}!\"",
"fail",
"msg",
"end",
"# Enforce alphabetical ordering of features (only).",
"# We can extend this later to enforce ordering of names if desired",
"# by checking at depth 2 as well.",
"if",
"depth",
"==",
"1",
"last_key",
"=",
"nil",
"key_arr",
".",
"each",
"do",
"|",
"key",
"|",
"if",
"last_key",
"&&",
"key",
"<",
"last_key",
"fail",
"\"features out of order in #{filename}: (#{last_key} > #{key})\"",
"end",
"last_key",
"=",
"key",
"end",
"end",
"# Recurse to the children. We get a little fancy here so as to be able",
"# to provide more meaningful debug/error messages, such as:",
"# Duplicate param 'default_value' under feature 'foo', name 'bar'",
"key_children",
".",
"zip",
"(",
"val_children",
")",
".",
"each",
"do",
"|",
"key_node",
",",
"val_node",
"|",
"if",
"parents",
"new_parents",
"=",
"parents",
"+",
"\", #{label} '#{key_node.value}'\"",
"else",
"new_parents",
"=",
"\" under #{label} '#{key_node.value}'\"",
"end",
"validate_yaml",
"(",
"key_node",
",",
"filename",
",",
"depth",
",",
"new_parents",
")",
"# unnecessary?",
"validate_yaml",
"(",
"val_node",
",",
"filename",
",",
"depth",
",",
"new_parents",
")",
"end",
"end"
] |
Validate the YAML node tree before converting it into Ruby
data structures.
@raise RuntimeError if the node tree is not valid by our constraints.
@param node Node to be validated, then recurse to its children.
@param filename File that YAML was parsed from, for messages
@param depth Depth into the node tree
@param parents String describing parents of this node, for messages
|
[
"Validate",
"the",
"YAML",
"node",
"tree",
"before",
"converting",
"it",
"into",
"Ruby",
"data",
"structures",
"."
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/command_reference.rb#L621-L684
|
20,315
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/command_reference.rb
|
Cisco.CommandReference.load_yaml
|
def load_yaml(yaml_file)
fail "File #{yaml_file} doesn't exist." unless File.exist?(yaml_file)
# Parse YAML file into a tree of nodes
# Psych::SyntaxError doesn't inherit from StandardError in some versions,
# so we want to explicitly catch it if using Psych.
rescue_errors = [::StandardError, ::Psych::SyntaxError]
yaml_parsed = File.open(yaml_file, 'r') do |f|
begin
YAML.parse(f)
rescue *rescue_errors => e
raise "unable to parse #{yaml_file}: #{e}"
end
end
return {} unless yaml_parsed
# Validate the node tree
validate_yaml(yaml_parsed, yaml_file)
# If validation passed, convert the node tree to a Ruby Hash.
yaml_parsed.transform
end
|
ruby
|
def load_yaml(yaml_file)
fail "File #{yaml_file} doesn't exist." unless File.exist?(yaml_file)
# Parse YAML file into a tree of nodes
# Psych::SyntaxError doesn't inherit from StandardError in some versions,
# so we want to explicitly catch it if using Psych.
rescue_errors = [::StandardError, ::Psych::SyntaxError]
yaml_parsed = File.open(yaml_file, 'r') do |f|
begin
YAML.parse(f)
rescue *rescue_errors => e
raise "unable to parse #{yaml_file}: #{e}"
end
end
return {} unless yaml_parsed
# Validate the node tree
validate_yaml(yaml_parsed, yaml_file)
# If validation passed, convert the node tree to a Ruby Hash.
yaml_parsed.transform
end
|
[
"def",
"load_yaml",
"(",
"yaml_file",
")",
"fail",
"\"File #{yaml_file} doesn't exist.\"",
"unless",
"File",
".",
"exist?",
"(",
"yaml_file",
")",
"# Parse YAML file into a tree of nodes",
"# Psych::SyntaxError doesn't inherit from StandardError in some versions,",
"# so we want to explicitly catch it if using Psych.",
"rescue_errors",
"=",
"[",
"::",
"StandardError",
",",
"::",
"Psych",
"::",
"SyntaxError",
"]",
"yaml_parsed",
"=",
"File",
".",
"open",
"(",
"yaml_file",
",",
"'r'",
")",
"do",
"|",
"f",
"|",
"begin",
"YAML",
".",
"parse",
"(",
"f",
")",
"rescue",
"rescue_errors",
"=>",
"e",
"raise",
"\"unable to parse #{yaml_file}: #{e}\"",
"end",
"end",
"return",
"{",
"}",
"unless",
"yaml_parsed",
"# Validate the node tree",
"validate_yaml",
"(",
"yaml_parsed",
",",
"yaml_file",
")",
"# If validation passed, convert the node tree to a Ruby Hash.",
"yaml_parsed",
".",
"transform",
"end"
] |
Read in yaml file.
The expectation is that a file corresponds to a feature
|
[
"Read",
"in",
"yaml",
"file",
".",
"The",
"expectation",
"is",
"that",
"a",
"file",
"corresponds",
"to",
"a",
"feature"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/command_reference.rb#L689-L707
|
20,316
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.message_digest_key_set
|
def message_digest_key_set(keyid, algtype, enctype, enc)
current_keyid = message_digest_key_id
if keyid == default_message_digest_key_id && current_keyid != keyid
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, 'no', current_keyid,
'', '', '')
elsif keyid != default_message_digest_key_id
fail TypeError unless enc.is_a?(String)
fail ArgumentError unless enc.length > 0
enctype = Encryption.symbol_to_cli(enctype)
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, '', keyid, algtype, enctype, enc)
end
end
|
ruby
|
def message_digest_key_set(keyid, algtype, enctype, enc)
current_keyid = message_digest_key_id
if keyid == default_message_digest_key_id && current_keyid != keyid
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, 'no', current_keyid,
'', '', '')
elsif keyid != default_message_digest_key_id
fail TypeError unless enc.is_a?(String)
fail ArgumentError unless enc.length > 0
enctype = Encryption.symbol_to_cli(enctype)
config_set('interface_ospf', 'message_digest_key_set',
@interface.name, '', keyid, algtype, enctype, enc)
end
end
|
[
"def",
"message_digest_key_set",
"(",
"keyid",
",",
"algtype",
",",
"enctype",
",",
"enc",
")",
"current_keyid",
"=",
"message_digest_key_id",
"if",
"keyid",
"==",
"default_message_digest_key_id",
"&&",
"current_keyid",
"!=",
"keyid",
"config_set",
"(",
"'interface_ospf'",
",",
"'message_digest_key_set'",
",",
"@interface",
".",
"name",
",",
"'no'",
",",
"current_keyid",
",",
"''",
",",
"''",
",",
"''",
")",
"elsif",
"keyid",
"!=",
"default_message_digest_key_id",
"fail",
"TypeError",
"unless",
"enc",
".",
"is_a?",
"(",
"String",
")",
"fail",
"ArgumentError",
"unless",
"enc",
".",
"length",
">",
"0",
"enctype",
"=",
"Encryption",
".",
"symbol_to_cli",
"(",
"enctype",
")",
"config_set",
"(",
"'interface_ospf'",
",",
"'message_digest_key_set'",
",",
"@interface",
".",
"name",
",",
"''",
",",
"keyid",
",",
"algtype",
",",
"enctype",
",",
"enc",
")",
"end",
"end"
] |
interface %s
%s ip ospf message-digest-key %d %s %d %s
|
[
"interface",
"%s",
"%s",
"ip",
"ospf",
"message",
"-",
"digest",
"-",
"key",
"%d",
"%s",
"%d",
"%s"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L160-L173
|
20,317
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.bfd
|
def bfd
val = config_get('interface_ospf', 'bfd', @interface.name)
return if val.nil?
val.include?('disable') ? false : true
end
|
ruby
|
def bfd
val = config_get('interface_ospf', 'bfd', @interface.name)
return if val.nil?
val.include?('disable') ? false : true
end
|
[
"def",
"bfd",
"val",
"=",
"config_get",
"(",
"'interface_ospf'",
",",
"'bfd'",
",",
"@interface",
".",
"name",
")",
"return",
"if",
"val",
".",
"nil?",
"val",
".",
"include?",
"(",
"'disable'",
")",
"?",
"false",
":",
"true",
"end"
] |
CLI can be either of the following or none
ip ospf bfd
ip ospf bfd disable
|
[
"CLI",
"can",
"be",
"either",
"of",
"the",
"following",
"or",
"none",
"ip",
"ospf",
"bfd",
"ip",
"ospf",
"bfd",
"disable"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L226-L230
|
20,318
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.bfd=
|
def bfd=(val)
return if val == bfd
Feature.bfd_enable
state = (val == default_bfd) ? 'no' : ''
disable = val ? '' : 'disable'
config_set('interface_ospf', 'bfd', @interface.name,
state, disable)
end
|
ruby
|
def bfd=(val)
return if val == bfd
Feature.bfd_enable
state = (val == default_bfd) ? 'no' : ''
disable = val ? '' : 'disable'
config_set('interface_ospf', 'bfd', @interface.name,
state, disable)
end
|
[
"def",
"bfd",
"=",
"(",
"val",
")",
"return",
"if",
"val",
"==",
"bfd",
"Feature",
".",
"bfd_enable",
"state",
"=",
"(",
"val",
"==",
"default_bfd",
")",
"?",
"'no'",
":",
"''",
"disable",
"=",
"val",
"?",
"''",
":",
"'disable'",
"config_set",
"(",
"'interface_ospf'",
",",
"'bfd'",
",",
"@interface",
".",
"name",
",",
"state",
",",
"disable",
")",
"end"
] |
interface %s
%s ip ospf bfd %s
|
[
"interface",
"%s",
"%s",
"ip",
"ospf",
"bfd",
"%s"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L234-L241
|
20,319
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.network_type=
|
def network_type=(type)
no_cmd = (type == default_network_type) ? 'no' : ''
network = (type == default_network_type) ? '' : type
network = 'point-to-point' if type.to_s == 'p2p'
config_set('interface_ospf', 'network_type', @interface.name,
no_cmd, network)
end
|
ruby
|
def network_type=(type)
no_cmd = (type == default_network_type) ? 'no' : ''
network = (type == default_network_type) ? '' : type
network = 'point-to-point' if type.to_s == 'p2p'
config_set('interface_ospf', 'network_type', @interface.name,
no_cmd, network)
end
|
[
"def",
"network_type",
"=",
"(",
"type",
")",
"no_cmd",
"=",
"(",
"type",
"==",
"default_network_type",
")",
"?",
"'no'",
":",
"''",
"network",
"=",
"(",
"type",
"==",
"default_network_type",
")",
"?",
"''",
":",
"type",
"network",
"=",
"'point-to-point'",
"if",
"type",
".",
"to_s",
"==",
"'p2p'",
"config_set",
"(",
"'interface_ospf'",
",",
"'network_type'",
",",
"@interface",
".",
"name",
",",
"no_cmd",
",",
"network",
")",
"end"
] |
interface %s
%s ip ospf network %s
|
[
"interface",
"%s",
"%s",
"ip",
"ospf",
"network",
"%s"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L281-L287
|
20,320
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.passive_interface=
|
def passive_interface=(enable)
fail TypeError unless enable == true || enable == false
config_set('interface_ospf', 'passive_interface', @interface.name,
enable ? '' : 'no')
end
|
ruby
|
def passive_interface=(enable)
fail TypeError unless enable == true || enable == false
config_set('interface_ospf', 'passive_interface', @interface.name,
enable ? '' : 'no')
end
|
[
"def",
"passive_interface",
"=",
"(",
"enable",
")",
"fail",
"TypeError",
"unless",
"enable",
"==",
"true",
"||",
"enable",
"==",
"false",
"config_set",
"(",
"'interface_ospf'",
",",
"'passive_interface'",
",",
"@interface",
".",
"name",
",",
"enable",
"?",
"''",
":",
"'no'",
")",
"end"
] |
interface %s
%s ip ospf passive-interface
|
[
"interface",
"%s",
"%s",
"ip",
"ospf",
"passive",
"-",
"interface"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L299-L303
|
20,321
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.priority=
|
def priority=(val)
no_cmd = (val == default_priority) ? 'no' : ''
pri = (val == default_priority) ? '' : val
config_set('interface_ospf', 'priority',
@interface.name, no_cmd, pri)
end
|
ruby
|
def priority=(val)
no_cmd = (val == default_priority) ? 'no' : ''
pri = (val == default_priority) ? '' : val
config_set('interface_ospf', 'priority',
@interface.name, no_cmd, pri)
end
|
[
"def",
"priority",
"=",
"(",
"val",
")",
"no_cmd",
"=",
"(",
"val",
"==",
"default_priority",
")",
"?",
"'no'",
":",
"''",
"pri",
"=",
"(",
"val",
"==",
"default_priority",
")",
"?",
"''",
":",
"val",
"config_set",
"(",
"'interface_ospf'",
",",
"'priority'",
",",
"@interface",
".",
"name",
",",
"no_cmd",
",",
"pri",
")",
"end"
] |
interface %s
ip ospf priority %d
|
[
"interface",
"%s",
"ip",
"ospf",
"priority",
"%d"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L311-L316
|
20,322
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/interface_ospf.rb
|
Cisco.InterfaceOspf.transmit_delay=
|
def transmit_delay=(val)
no_cmd = (val == default_transmit_delay) ? 'no' : ''
delay = (val == default_transmit_delay) ? '' : val
config_set('interface_ospf', 'transmit_delay',
@interface.name, no_cmd, delay)
end
|
ruby
|
def transmit_delay=(val)
no_cmd = (val == default_transmit_delay) ? 'no' : ''
delay = (val == default_transmit_delay) ? '' : val
config_set('interface_ospf', 'transmit_delay',
@interface.name, no_cmd, delay)
end
|
[
"def",
"transmit_delay",
"=",
"(",
"val",
")",
"no_cmd",
"=",
"(",
"val",
"==",
"default_transmit_delay",
")",
"?",
"'no'",
":",
"''",
"delay",
"=",
"(",
"val",
"==",
"default_transmit_delay",
")",
"?",
"''",
":",
"val",
"config_set",
"(",
"'interface_ospf'",
",",
"'transmit_delay'",
",",
"@interface",
".",
"name",
",",
"no_cmd",
",",
"delay",
")",
"end"
] |
interface %s
ip ospf transmit-delay %d
|
[
"interface",
"%s",
"ip",
"ospf",
"transmit",
"-",
"delay",
"%d"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/interface_ospf.rb#L343-L348
|
20,323
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bfd_global.rb
|
Cisco.BfdGlobal.destroy
|
def destroy
return unless Feature.bfd_enabled?
[:interval,
:ipv4_interval,
:ipv6_interval,
:fabricpath_interval,
:echo_interface,
:echo_rx_interval,
:ipv4_echo_rx_interval,
:ipv6_echo_rx_interval,
:fabricpath_vlan,
:slow_timer,
:ipv4_slow_timer,
:ipv6_slow_timer,
:fabricpath_slow_timer,
:startup_timer,
].each do |prop|
send("#{prop}=", send("default_#{prop}")) if
send prop
end
set_args_keys_default
end
|
ruby
|
def destroy
return unless Feature.bfd_enabled?
[:interval,
:ipv4_interval,
:ipv6_interval,
:fabricpath_interval,
:echo_interface,
:echo_rx_interval,
:ipv4_echo_rx_interval,
:ipv6_echo_rx_interval,
:fabricpath_vlan,
:slow_timer,
:ipv4_slow_timer,
:ipv6_slow_timer,
:fabricpath_slow_timer,
:startup_timer,
].each do |prop|
send("#{prop}=", send("default_#{prop}")) if
send prop
end
set_args_keys_default
end
|
[
"def",
"destroy",
"return",
"unless",
"Feature",
".",
"bfd_enabled?",
"[",
":interval",
",",
":ipv4_interval",
",",
":ipv6_interval",
",",
":fabricpath_interval",
",",
":echo_interface",
",",
":echo_rx_interval",
",",
":ipv4_echo_rx_interval",
",",
":ipv6_echo_rx_interval",
",",
":fabricpath_vlan",
",",
":slow_timer",
",",
":ipv4_slow_timer",
",",
":ipv6_slow_timer",
",",
":fabricpath_slow_timer",
",",
":startup_timer",
",",
"]",
".",
"each",
"do",
"|",
"prop",
"|",
"send",
"(",
"\"#{prop}=\"",
",",
"send",
"(",
"\"default_#{prop}\"",
")",
")",
"if",
"send",
"prop",
"end",
"set_args_keys_default",
"end"
] |
Reset everything back to default
|
[
"Reset",
"everything",
"back",
"to",
"default"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bfd_global.rb#L34-L55
|
20,324
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/vtp.rb
|
Cisco.Vtp.domain=
|
def domain=(d)
d = d.to_s
fail ArgumentError unless d.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
config_set('vtp', 'domain', domain: d)
end
|
ruby
|
def domain=(d)
d = d.to_s
fail ArgumentError unless d.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
config_set('vtp', 'domain', domain: d)
end
|
[
"def",
"domain",
"=",
"(",
"d",
")",
"d",
"=",
"d",
".",
"to_s",
"fail",
"ArgumentError",
"unless",
"d",
".",
"length",
".",
"between?",
"(",
"1",
",",
"MAX_VTP_DOMAIN_NAME_SIZE",
")",
"config_set",
"(",
"'vtp'",
",",
"'domain'",
",",
"domain",
":",
"d",
")",
"end"
] |
Set vtp domain name
|
[
"Set",
"vtp",
"domain",
"name"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/vtp.rb#L55-L59
|
20,325
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/vtp.rb
|
Cisco.Vtp.password
|
def password
# Unfortunately nxapi returns "\\" when the password is not set
password = config_get('vtp', 'password') if Feature.vtp_enabled?
return '' if password.nil? || password == '\\'
password
rescue Cisco::RequestNotSupported => e
# Certain platforms generate a Cisco::RequestNotSupported when the
# vtp password is not set. We catch this specific error and
# return empty '' for the password.
return '' if e.message[/Structured output not supported/]
end
|
ruby
|
def password
# Unfortunately nxapi returns "\\" when the password is not set
password = config_get('vtp', 'password') if Feature.vtp_enabled?
return '' if password.nil? || password == '\\'
password
rescue Cisco::RequestNotSupported => e
# Certain platforms generate a Cisco::RequestNotSupported when the
# vtp password is not set. We catch this specific error and
# return empty '' for the password.
return '' if e.message[/Structured output not supported/]
end
|
[
"def",
"password",
"# Unfortunately nxapi returns \"\\\\\" when the password is not set",
"password",
"=",
"config_get",
"(",
"'vtp'",
",",
"'password'",
")",
"if",
"Feature",
".",
"vtp_enabled?",
"return",
"''",
"if",
"password",
".",
"nil?",
"||",
"password",
"==",
"'\\\\'",
"password",
"rescue",
"Cisco",
"::",
"RequestNotSupported",
"=>",
"e",
"# Certain platforms generate a Cisco::RequestNotSupported when the",
"# vtp password is not set. We catch this specific error and",
"# return empty '' for the password.",
"return",
"''",
"if",
"e",
".",
"message",
"[",
"/",
"/",
"]",
"end"
] |
Get vtp password
|
[
"Get",
"vtp",
"password"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/vtp.rb#L62-L72
|
20,326
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/vtp.rb
|
Cisco.Vtp.password=
|
def password=(password)
fail TypeError if password.nil?
fail TypeError unless password.is_a? String
fail ArgumentError if password.length > MAX_VTP_PASSWORD_SIZE
Feature.vtp_enable
state = (password == default_password) ? 'no' : ''
config_set('vtp', 'password', state: state, password: password)
end
|
ruby
|
def password=(password)
fail TypeError if password.nil?
fail TypeError unless password.is_a? String
fail ArgumentError if password.length > MAX_VTP_PASSWORD_SIZE
Feature.vtp_enable
state = (password == default_password) ? 'no' : ''
config_set('vtp', 'password', state: state, password: password)
end
|
[
"def",
"password",
"=",
"(",
"password",
")",
"fail",
"TypeError",
"if",
"password",
".",
"nil?",
"fail",
"TypeError",
"unless",
"password",
".",
"is_a?",
"String",
"fail",
"ArgumentError",
"if",
"password",
".",
"length",
">",
"MAX_VTP_PASSWORD_SIZE",
"Feature",
".",
"vtp_enable",
"state",
"=",
"(",
"password",
"==",
"default_password",
")",
"?",
"'no'",
":",
"''",
"config_set",
"(",
"'vtp'",
",",
"'password'",
",",
"state",
":",
"state",
",",
"password",
":",
"password",
")",
"end"
] |
Set vtp password
|
[
"Set",
"vtp",
"password"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/vtp.rb#L75-L82
|
20,327
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/vtp.rb
|
Cisco.Vtp.filename=
|
def filename=(uri)
fail TypeError if uri.nil?
Feature.vtp_enable
uri = uri.to_s
state = uri.empty? ? 'no' : ''
config_set('vtp', 'filename', state: state, uri: uri)
end
|
ruby
|
def filename=(uri)
fail TypeError if uri.nil?
Feature.vtp_enable
uri = uri.to_s
state = uri.empty? ? 'no' : ''
config_set('vtp', 'filename', state: state, uri: uri)
end
|
[
"def",
"filename",
"=",
"(",
"uri",
")",
"fail",
"TypeError",
"if",
"uri",
".",
"nil?",
"Feature",
".",
"vtp_enable",
"uri",
"=",
"uri",
".",
"to_s",
"state",
"=",
"uri",
".",
"empty?",
"?",
"'no'",
":",
"''",
"config_set",
"(",
"'vtp'",
",",
"'filename'",
",",
"state",
":",
"state",
",",
"uri",
":",
"uri",
")",
"end"
] |
Set vtp filename
|
[
"Set",
"vtp",
"filename"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/vtp.rb#L96-L102
|
20,328
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bgp.rb
|
Cisco.RouterBgp.graceful_restart=
|
def graceful_restart=(enable)
if platform == :ios_xr && @vrf != 'default'
fail Cisco::UnsupportedError.new('bgp', 'graceful_restart', 'set',
'graceful_restart is not ' \
'configurable ' \
'on a per-VRF basis on IOS XR')
end
@set_args[:state] = (enable ? '' : 'no')
config_set('bgp', 'graceful_restart', @set_args)
set_args_keys_default
end
|
ruby
|
def graceful_restart=(enable)
if platform == :ios_xr && @vrf != 'default'
fail Cisco::UnsupportedError.new('bgp', 'graceful_restart', 'set',
'graceful_restart is not ' \
'configurable ' \
'on a per-VRF basis on IOS XR')
end
@set_args[:state] = (enable ? '' : 'no')
config_set('bgp', 'graceful_restart', @set_args)
set_args_keys_default
end
|
[
"def",
"graceful_restart",
"=",
"(",
"enable",
")",
"if",
"platform",
"==",
":ios_xr",
"&&",
"@vrf",
"!=",
"'default'",
"fail",
"Cisco",
"::",
"UnsupportedError",
".",
"new",
"(",
"'bgp'",
",",
"'graceful_restart'",
",",
"'set'",
",",
"'graceful_restart is not '",
"'configurable '",
"'on a per-VRF basis on IOS XR'",
")",
"end",
"@set_args",
"[",
":state",
"]",
"=",
"(",
"enable",
"?",
"''",
":",
"'no'",
")",
"config_set",
"(",
"'bgp'",
",",
"'graceful_restart'",
",",
"@set_args",
")",
"set_args_keys_default",
"end"
] |
Graceful Restart Setters
|
[
"Graceful",
"Restart",
"Setters"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bgp.rb#L632-L642
|
20,329
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/bgp.rb
|
Cisco.RouterBgp.timer_bgp_keepalive_hold_set
|
def timer_bgp_keepalive_hold_set(keepalive, hold)
if keepalive == default_timer_bgp_keepalive &&
hold == default_timer_bgp_holdtime
@set_args[:state] = 'no'
@set_args[:keepalive] = keepalive
@set_args[:hold] = hold
else
@set_args[:state] = ''
@set_args[:keepalive] = keepalive
@set_args[:hold] = hold
end
config_set('bgp', 'timer_bgp_keepalive_hold', @set_args)
set_args_keys_default
end
|
ruby
|
def timer_bgp_keepalive_hold_set(keepalive, hold)
if keepalive == default_timer_bgp_keepalive &&
hold == default_timer_bgp_holdtime
@set_args[:state] = 'no'
@set_args[:keepalive] = keepalive
@set_args[:hold] = hold
else
@set_args[:state] = ''
@set_args[:keepalive] = keepalive
@set_args[:hold] = hold
end
config_set('bgp', 'timer_bgp_keepalive_hold', @set_args)
set_args_keys_default
end
|
[
"def",
"timer_bgp_keepalive_hold_set",
"(",
"keepalive",
",",
"hold",
")",
"if",
"keepalive",
"==",
"default_timer_bgp_keepalive",
"&&",
"hold",
"==",
"default_timer_bgp_holdtime",
"@set_args",
"[",
":state",
"]",
"=",
"'no'",
"@set_args",
"[",
":keepalive",
"]",
"=",
"keepalive",
"@set_args",
"[",
":hold",
"]",
"=",
"hold",
"else",
"@set_args",
"[",
":state",
"]",
"=",
"''",
"@set_args",
"[",
":keepalive",
"]",
"=",
"keepalive",
"@set_args",
"[",
":hold",
"]",
"=",
"hold",
"end",
"config_set",
"(",
"'bgp'",
",",
"'timer_bgp_keepalive_hold'",
",",
"@set_args",
")",
"set_args_keys_default",
"end"
] |
BGP Timers Setters
|
[
"BGP",
"Timers",
"Setters"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/bgp.rb#L933-L946
|
20,330
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.match_community
|
def match_community
str = config_get('route_map', 'match_community', @get_args)
if str.empty?
val = default_match_community
else
val = str.split
val.delete('exact-match')
end
val
end
|
ruby
|
def match_community
str = config_get('route_map', 'match_community', @get_args)
if str.empty?
val = default_match_community
else
val = str.split
val.delete('exact-match')
end
val
end
|
[
"def",
"match_community",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'match_community'",
",",
"@get_args",
")",
"if",
"str",
".",
"empty?",
"val",
"=",
"default_match_community",
"else",
"val",
"=",
"str",
".",
"split",
"val",
".",
"delete",
"(",
"'exact-match'",
")",
"end",
"val",
"end"
] |
match community public private exact-match
|
[
"match",
"community",
"public",
"private",
"exact",
"-",
"match"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L156-L165
|
20,331
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.match_metric
|
def match_metric
str = config_get('route_map', 'match_metric', @get_args)
return default_match_metric if str.empty?
rarr = []
larr = []
metrics = str.split
deviation = false
metrics.each do |metric|
deviation = true if metric == '+-'
if !larr.empty? && !deviation
larr << '0'
rarr << larr
larr = []
end
next if metric == '+-'
if !larr.empty? && deviation
larr << metric
rarr << larr
larr = []
deviation = false
next
end
larr << metric if larr.empty?
end
unless larr.empty?
larr << '0'
rarr << larr
end
rarr
end
|
ruby
|
def match_metric
str = config_get('route_map', 'match_metric', @get_args)
return default_match_metric if str.empty?
rarr = []
larr = []
metrics = str.split
deviation = false
metrics.each do |metric|
deviation = true if metric == '+-'
if !larr.empty? && !deviation
larr << '0'
rarr << larr
larr = []
end
next if metric == '+-'
if !larr.empty? && deviation
larr << metric
rarr << larr
larr = []
deviation = false
next
end
larr << metric if larr.empty?
end
unless larr.empty?
larr << '0'
rarr << larr
end
rarr
end
|
[
"def",
"match_metric",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'match_metric'",
",",
"@get_args",
")",
"return",
"default_match_metric",
"if",
"str",
".",
"empty?",
"rarr",
"=",
"[",
"]",
"larr",
"=",
"[",
"]",
"metrics",
"=",
"str",
".",
"split",
"deviation",
"=",
"false",
"metrics",
".",
"each",
"do",
"|",
"metric",
"|",
"deviation",
"=",
"true",
"if",
"metric",
"==",
"'+-'",
"if",
"!",
"larr",
".",
"empty?",
"&&",
"!",
"deviation",
"larr",
"<<",
"'0'",
"rarr",
"<<",
"larr",
"larr",
"=",
"[",
"]",
"end",
"next",
"if",
"metric",
"==",
"'+-'",
"if",
"!",
"larr",
".",
"empty?",
"&&",
"deviation",
"larr",
"<<",
"metric",
"rarr",
"<<",
"larr",
"larr",
"=",
"[",
"]",
"deviation",
"=",
"false",
"next",
"end",
"larr",
"<<",
"metric",
"if",
"larr",
".",
"empty?",
"end",
"unless",
"larr",
".",
"empty?",
"larr",
"<<",
"'0'",
"rarr",
"<<",
"larr",
"end",
"rarr",
"end"
] |
match metric 1 8 224 +- 9 23 5 +- 8 6
|
[
"match",
"metric",
"1",
"8",
"224",
"+",
"-",
"9",
"23",
"5",
"+",
"-",
"8",
"6"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L847-L876
|
20,332
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.match_ospf_area
|
def match_ospf_area
str = config_get('route_map', 'match_ospf_area', @get_args)
return if str.nil?
str.empty? ? default_match_ospf_area : str.split
end
|
ruby
|
def match_ospf_area
str = config_get('route_map', 'match_ospf_area', @get_args)
return if str.nil?
str.empty? ? default_match_ospf_area : str.split
end
|
[
"def",
"match_ospf_area",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'match_ospf_area'",
",",
"@get_args",
")",
"return",
"if",
"str",
".",
"nil?",
"str",
".",
"empty?",
"?",
"default_match_ospf_area",
":",
"str",
".",
"split",
"end"
] |
match ospf-area 10 7
|
[
"match",
"ospf",
"-",
"area",
"10",
"7"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1107-L1111
|
20,333
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.match_mac_list
|
def match_mac_list
str = config_get('route_map', 'match_mac_list', @get_args)
return if str.nil?
str.empty? ? default_match_mac_list : str.split
end
|
ruby
|
def match_mac_list
str = config_get('route_map', 'match_mac_list', @get_args)
return if str.nil?
str.empty? ? default_match_mac_list : str.split
end
|
[
"def",
"match_mac_list",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'match_mac_list'",
",",
"@get_args",
")",
"return",
"if",
"str",
".",
"nil?",
"str",
".",
"empty?",
"?",
"default_match_mac_list",
":",
"str",
".",
"split",
"end"
] |
match mac-list m1 m2
|
[
"match",
"mac",
"-",
"list",
"m1",
"m2"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1139-L1143
|
20,334
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.match_evpn_route_type_get
|
def match_evpn_route_type_get
arr = config_get('route_map', 'match_evpn_route_type', @get_args)
return nil if arr.nil?
hash = {}
hash[:type1] = false
hash[:type3] = false
hash[:type4] = false
hash[:type5] = false
hash[:type6] = false
hash[:type_all] = false
hash[:type2_all] = false
hash[:type2_mac_ip] = false
hash[:type2_mac_only] = false
return hash if arr.empty?
hash[:type1] = true if arr.include?('1')
hash[:type3] = true if arr.include?('3')
hash[:type4] = true if arr.include?('4')
hash[:type5] = true if arr.include?('5')
hash[:type6] = true if arr.include?('6')
hash[:type_all] = true if arr.include?('all')
hash[:type2_all] = true if arr.include?('2 all')
hash[:type2_mac_ip] = true if arr.include?('2 mac-ip')
hash[:type2_mac_only] = true if arr.include?('2 mac-only')
hash
end
|
ruby
|
def match_evpn_route_type_get
arr = config_get('route_map', 'match_evpn_route_type', @get_args)
return nil if arr.nil?
hash = {}
hash[:type1] = false
hash[:type3] = false
hash[:type4] = false
hash[:type5] = false
hash[:type6] = false
hash[:type_all] = false
hash[:type2_all] = false
hash[:type2_mac_ip] = false
hash[:type2_mac_only] = false
return hash if arr.empty?
hash[:type1] = true if arr.include?('1')
hash[:type3] = true if arr.include?('3')
hash[:type4] = true if arr.include?('4')
hash[:type5] = true if arr.include?('5')
hash[:type6] = true if arr.include?('6')
hash[:type_all] = true if arr.include?('all')
hash[:type2_all] = true if arr.include?('2 all')
hash[:type2_mac_ip] = true if arr.include?('2 mac-ip')
hash[:type2_mac_only] = true if arr.include?('2 mac-only')
hash
end
|
[
"def",
"match_evpn_route_type_get",
"arr",
"=",
"config_get",
"(",
"'route_map'",
",",
"'match_evpn_route_type'",
",",
"@get_args",
")",
"return",
"nil",
"if",
"arr",
".",
"nil?",
"hash",
"=",
"{",
"}",
"hash",
"[",
":type1",
"]",
"=",
"false",
"hash",
"[",
":type3",
"]",
"=",
"false",
"hash",
"[",
":type4",
"]",
"=",
"false",
"hash",
"[",
":type5",
"]",
"=",
"false",
"hash",
"[",
":type6",
"]",
"=",
"false",
"hash",
"[",
":type_all",
"]",
"=",
"false",
"hash",
"[",
":type2_all",
"]",
"=",
"false",
"hash",
"[",
":type2_mac_ip",
"]",
"=",
"false",
"hash",
"[",
":type2_mac_only",
"]",
"=",
"false",
"return",
"hash",
"if",
"arr",
".",
"empty?",
"hash",
"[",
":type1",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'1'",
")",
"hash",
"[",
":type3",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'3'",
")",
"hash",
"[",
":type4",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'4'",
")",
"hash",
"[",
":type5",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'5'",
")",
"hash",
"[",
":type6",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'6'",
")",
"hash",
"[",
":type_all",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'all'",
")",
"hash",
"[",
":type2_all",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'2 all'",
")",
"hash",
"[",
":type2_mac_ip",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'2 mac-ip'",
")",
"hash",
"[",
":type2_mac_only",
"]",
"=",
"true",
"if",
"arr",
".",
"include?",
"(",
"'2 mac-only'",
")",
"hash",
"end"
] |
match evpn route-type 1
match evpn route-type 2 all
match evpn route-type 2 mac-ip
match evpn route-type 2 mac-only
match evpn route-type 3 etc.
|
[
"match",
"evpn",
"route",
"-",
"type",
"1",
"match",
"evpn",
"route",
"-",
"type",
"2",
"all",
"match",
"evpn",
"route",
"-",
"type",
"2",
"mac",
"-",
"ip",
"match",
"evpn",
"route",
"-",
"type",
"2",
"mac",
"-",
"only",
"match",
"evpn",
"route",
"-",
"type",
"3",
"etc",
"."
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1214-L1238
|
20,335
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_metric_get
|
def set_metric_get
hash = {}
hash[:additive] = false
hash[:bandwidth] = false
hash[:delay] = false
hash[:reliability] = false
hash[:effective_bandwidth] = false
hash[:mtu] = false
str = config_get('route_map', 'set_metric', @get_args)
return hash if str.nil?
arr = str.split
hash[:additive] = true if arr[0].include?('+')
hash[:bandwidth] = arr[0].delete('+').to_i
return hash if arr.size == 1
hash[:delay] = arr[1].to_i
hash[:reliability] = arr[2].to_i
hash[:effective_bandwidth] = arr[3].to_i
hash[:mtu] = arr[4].to_i
hash
end
|
ruby
|
def set_metric_get
hash = {}
hash[:additive] = false
hash[:bandwidth] = false
hash[:delay] = false
hash[:reliability] = false
hash[:effective_bandwidth] = false
hash[:mtu] = false
str = config_get('route_map', 'set_metric', @get_args)
return hash if str.nil?
arr = str.split
hash[:additive] = true if arr[0].include?('+')
hash[:bandwidth] = arr[0].delete('+').to_i
return hash if arr.size == 1
hash[:delay] = arr[1].to_i
hash[:reliability] = arr[2].to_i
hash[:effective_bandwidth] = arr[3].to_i
hash[:mtu] = arr[4].to_i
hash
end
|
[
"def",
"set_metric_get",
"hash",
"=",
"{",
"}",
"hash",
"[",
":additive",
"]",
"=",
"false",
"hash",
"[",
":bandwidth",
"]",
"=",
"false",
"hash",
"[",
":delay",
"]",
"=",
"false",
"hash",
"[",
":reliability",
"]",
"=",
"false",
"hash",
"[",
":effective_bandwidth",
"]",
"=",
"false",
"hash",
"[",
":mtu",
"]",
"=",
"false",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_metric'",
",",
"@get_args",
")",
"return",
"hash",
"if",
"str",
".",
"nil?",
"arr",
"=",
"str",
".",
"split",
"hash",
"[",
":additive",
"]",
"=",
"true",
"if",
"arr",
"[",
"0",
"]",
".",
"include?",
"(",
"'+'",
")",
"hash",
"[",
":bandwidth",
"]",
"=",
"arr",
"[",
"0",
"]",
".",
"delete",
"(",
"'+'",
")",
".",
"to_i",
"return",
"hash",
"if",
"arr",
".",
"size",
"==",
"1",
"hash",
"[",
":delay",
"]",
"=",
"arr",
"[",
"1",
"]",
".",
"to_i",
"hash",
"[",
":reliability",
"]",
"=",
"arr",
"[",
"2",
"]",
".",
"to_i",
"hash",
"[",
":effective_bandwidth",
"]",
"=",
"arr",
"[",
"3",
"]",
".",
"to_i",
"hash",
"[",
":mtu",
"]",
"=",
"arr",
"[",
"4",
"]",
".",
"to_i",
"hash",
"end"
] |
set metric 44 55 66 77 88
set metric +33
|
[
"set",
"metric",
"44",
"55",
"66",
"77",
"88",
"set",
"metric",
"+",
"33"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1556-L1575
|
20,336
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_dampening_get
|
def set_dampening_get
hash = {}
hash[:half_life] = false
hash[:reuse] = false
hash[:suppress] = false
hash[:max] = false
str = config_get('route_map', 'set_dampening', @get_args)
return hash if str.nil?
arr = str.split
hash[:half_life] = arr[0].to_i
hash[:reuse] = arr[1].to_i
hash[:suppress] = arr[2].to_i
hash[:max] = arr[3].to_i
hash
end
|
ruby
|
def set_dampening_get
hash = {}
hash[:half_life] = false
hash[:reuse] = false
hash[:suppress] = false
hash[:max] = false
str = config_get('route_map', 'set_dampening', @get_args)
return hash if str.nil?
arr = str.split
hash[:half_life] = arr[0].to_i
hash[:reuse] = arr[1].to_i
hash[:suppress] = arr[2].to_i
hash[:max] = arr[3].to_i
hash
end
|
[
"def",
"set_dampening_get",
"hash",
"=",
"{",
"}",
"hash",
"[",
":half_life",
"]",
"=",
"false",
"hash",
"[",
":reuse",
"]",
"=",
"false",
"hash",
"[",
":suppress",
"]",
"=",
"false",
"hash",
"[",
":max",
"]",
"=",
"false",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_dampening'",
",",
"@get_args",
")",
"return",
"hash",
"if",
"str",
".",
"nil?",
"arr",
"=",
"str",
".",
"split",
"hash",
"[",
":half_life",
"]",
"=",
"arr",
"[",
"0",
"]",
".",
"to_i",
"hash",
"[",
":reuse",
"]",
"=",
"arr",
"[",
"1",
"]",
".",
"to_i",
"hash",
"[",
":suppress",
"]",
"=",
"arr",
"[",
"2",
"]",
".",
"to_i",
"hash",
"[",
":max",
"]",
"=",
"arr",
"[",
"3",
"]",
".",
"to_i",
"hash",
"end"
] |
set dampening 6 22 44 55
|
[
"set",
"dampening",
"6",
"22",
"44",
"55"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1648-L1662
|
20,337
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_as_path_prepend
|
def set_as_path_prepend
arr = []
match = config_get('route_map', 'set_as_path_prepend', @get_args)
if arr
match.each do |line|
next if line.include?('last-as')
arr = line.strip.split
end
end
arr
end
|
ruby
|
def set_as_path_prepend
arr = []
match = config_get('route_map', 'set_as_path_prepend', @get_args)
if arr
match.each do |line|
next if line.include?('last-as')
arr = line.strip.split
end
end
arr
end
|
[
"def",
"set_as_path_prepend",
"arr",
"=",
"[",
"]",
"match",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_as_path_prepend'",
",",
"@get_args",
")",
"if",
"arr",
"match",
".",
"each",
"do",
"|",
"line",
"|",
"next",
"if",
"line",
".",
"include?",
"(",
"'last-as'",
")",
"arr",
"=",
"line",
".",
"strip",
".",
"split",
"end",
"end",
"arr",
"end"
] |
set as-path prepend 55.77 44 33.5
set as-path prepend last-as 1
|
[
"set",
"as",
"-",
"path",
"prepend",
"55",
".",
"77",
"44",
"33",
".",
"5",
"set",
"as",
"-",
"path",
"prepend",
"last",
"-",
"as",
"1"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1794-L1804
|
20,338
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv4_default_next_hop
|
def set_ipv4_default_next_hop
str = config_get('route_map', 'set_ipv4_default_next_hop', @get_args)
return if str.nil?
if str.empty?
val = default_set_ipv4_default_next_hop
else
val = str.split
val.delete('load-share')
end
val
end
|
ruby
|
def set_ipv4_default_next_hop
str = config_get('route_map', 'set_ipv4_default_next_hop', @get_args)
return if str.nil?
if str.empty?
val = default_set_ipv4_default_next_hop
else
val = str.split
val.delete('load-share')
end
val
end
|
[
"def",
"set_ipv4_default_next_hop",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv4_default_next_hop'",
",",
"@get_args",
")",
"return",
"if",
"str",
".",
"nil?",
"if",
"str",
".",
"empty?",
"val",
"=",
"default_set_ipv4_default_next_hop",
"else",
"val",
"=",
"str",
".",
"split",
"val",
".",
"delete",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ip default next-hop 1.1.1.1 2.2.2.2 3.3.3.3
|
[
"set",
"ip",
"default",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1870-L1880
|
20,339
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv4_next_hop
|
def set_ipv4_next_hop
arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
val = default_set_ipv4_next_hop
arr.each do |str|
next if str.empty?
next if str.include?('peer-address')
next if str.include?('unchanged')
next if str.include?('redist-unchanged')
val = str.split
val.delete('load-share')
end
val
end
|
ruby
|
def set_ipv4_next_hop
arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
val = default_set_ipv4_next_hop
arr.each do |str|
next if str.empty?
next if str.include?('peer-address')
next if str.include?('unchanged')
next if str.include?('redist-unchanged')
val = str.split
val.delete('load-share')
end
val
end
|
[
"def",
"set_ipv4_next_hop",
"arr",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv4_next_hop'",
",",
"@get_args",
")",
"val",
"=",
"default_set_ipv4_next_hop",
"arr",
".",
"each",
"do",
"|",
"str",
"|",
"next",
"if",
"str",
".",
"empty?",
"next",
"if",
"str",
".",
"include?",
"(",
"'peer-address'",
")",
"next",
"if",
"str",
".",
"include?",
"(",
"'unchanged'",
")",
"next",
"if",
"str",
".",
"include?",
"(",
"'redist-unchanged'",
")",
"val",
"=",
"str",
".",
"split",
"val",
".",
"delete",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ip next-hop 1.1.1.1 2.2.2.2 3.3.3.3
|
[
"set",
"ip",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1922-L1934
|
20,340
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv4_next_hop_load_share
|
def set_ipv4_next_hop_load_share
arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
val = default_set_ipv4_next_hop_load_share
arr.each do |str|
next if str.empty?
return true if str.include?('load-share')
end
val
end
|
ruby
|
def set_ipv4_next_hop_load_share
arr = config_get('route_map', 'set_ipv4_next_hop', @get_args)
val = default_set_ipv4_next_hop_load_share
arr.each do |str|
next if str.empty?
return true if str.include?('load-share')
end
val
end
|
[
"def",
"set_ipv4_next_hop_load_share",
"arr",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv4_next_hop'",
",",
"@get_args",
")",
"val",
"=",
"default_set_ipv4_next_hop_load_share",
"arr",
".",
"each",
"do",
"|",
"str",
"|",
"next",
"if",
"str",
".",
"empty?",
"return",
"true",
"if",
"str",
".",
"include?",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ip next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
set ip next-hop load-share
|
[
"set",
"ip",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3",
"load",
"-",
"share",
"set",
"ip",
"next",
"-",
"hop",
"load",
"-",
"share"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L1963-L1971
|
20,341
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv6_default_next_hop
|
def set_ipv6_default_next_hop
str = config_get('route_map', 'set_ipv6_default_next_hop', @get_args)
return if str.nil?
if str.empty?
val = default_set_ipv6_default_next_hop
else
val = str.split
val.delete('load-share')
end
val
end
|
ruby
|
def set_ipv6_default_next_hop
str = config_get('route_map', 'set_ipv6_default_next_hop', @get_args)
return if str.nil?
if str.empty?
val = default_set_ipv6_default_next_hop
else
val = str.split
val.delete('load-share')
end
val
end
|
[
"def",
"set_ipv6_default_next_hop",
"str",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv6_default_next_hop'",
",",
"@get_args",
")",
"return",
"if",
"str",
".",
"nil?",
"if",
"str",
".",
"empty?",
"val",
"=",
"default_set_ipv6_default_next_hop",
"else",
"val",
"=",
"str",
".",
"split",
"val",
".",
"delete",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ipv6 default next-hop 1.1.1.1 2.2.2.2 3.3.3.3
|
[
"set",
"ipv6",
"default",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L2057-L2067
|
20,342
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv6_next_hop
|
def set_ipv6_next_hop
arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
val = default_set_ipv6_next_hop
arr.each do |str|
next if str.empty?
next if str.include?('peer-address')
next if str.include?('unchanged')
next if str.include?('redist-unchanged')
val = str.split
val.delete('load-share')
end
val
end
|
ruby
|
def set_ipv6_next_hop
arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
val = default_set_ipv6_next_hop
arr.each do |str|
next if str.empty?
next if str.include?('peer-address')
next if str.include?('unchanged')
next if str.include?('redist-unchanged')
val = str.split
val.delete('load-share')
end
val
end
|
[
"def",
"set_ipv6_next_hop",
"arr",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv6_next_hop'",
",",
"@get_args",
")",
"val",
"=",
"default_set_ipv6_next_hop",
"arr",
".",
"each",
"do",
"|",
"str",
"|",
"next",
"if",
"str",
".",
"empty?",
"next",
"if",
"str",
".",
"include?",
"(",
"'peer-address'",
")",
"next",
"if",
"str",
".",
"include?",
"(",
"'unchanged'",
")",
"next",
"if",
"str",
".",
"include?",
"(",
"'redist-unchanged'",
")",
"val",
"=",
"str",
".",
"split",
"val",
".",
"delete",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ipv6 next-hop 1.1.1.1 2.2.2.2 3.3.3.3
|
[
"set",
"ipv6",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L2109-L2121
|
20,343
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_ipv6_next_hop_load_share
|
def set_ipv6_next_hop_load_share
arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
val = default_set_ipv6_next_hop_load_share
arr.each do |str|
next if str.empty?
return true if str.include?('load-share')
end
val
end
|
ruby
|
def set_ipv6_next_hop_load_share
arr = config_get('route_map', 'set_ipv6_next_hop', @get_args)
val = default_set_ipv6_next_hop_load_share
arr.each do |str|
next if str.empty?
return true if str.include?('load-share')
end
val
end
|
[
"def",
"set_ipv6_next_hop_load_share",
"arr",
"=",
"config_get",
"(",
"'route_map'",
",",
"'set_ipv6_next_hop'",
",",
"@get_args",
")",
"val",
"=",
"default_set_ipv6_next_hop_load_share",
"arr",
".",
"each",
"do",
"|",
"str",
"|",
"next",
"if",
"str",
".",
"empty?",
"return",
"true",
"if",
"str",
".",
"include?",
"(",
"'load-share'",
")",
"end",
"val",
"end"
] |
set ipv6 default next-hop 1.1.1.1 2.2.2.2 3.3.3.3 load-share
set ipv6 default next-hop load-share
|
[
"set",
"ipv6",
"default",
"next",
"-",
"hop",
"1",
".",
"1",
".",
"1",
".",
"1",
"2",
".",
"2",
".",
"2",
".",
"2",
"3",
".",
"3",
".",
"3",
".",
"3",
"load",
"-",
"share",
"set",
"ipv6",
"default",
"next",
"-",
"hop",
"load",
"-",
"share"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L2150-L2158
|
20,344
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/route_map.rb
|
Cisco.RouteMap.set_extcommunity_cost_set
|
def set_extcommunity_cost_set(igp, pre)
str = ''
# reset first
if set_extcommunity_cost_device
cpre = set_extcommunity_cost_pre_bestpath
cigp = set_extcommunity_cost_igp
cpre.each do |id, val|
str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
end
cigp.each do |id, val|
str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
end
end
set_args_keys(state: 'no', string: str)
config_set('route_map', 'set_extcommunity_cost', @set_args)
return if igp.empty? && pre.empty?
str = ''
pre.each do |id, val|
str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
end
igp.each do |id, val|
str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
end
set_args_keys(state: '', string: str)
config_set('route_map', 'set_extcommunity_cost', @set_args)
end
|
ruby
|
def set_extcommunity_cost_set(igp, pre)
str = ''
# reset first
if set_extcommunity_cost_device
cpre = set_extcommunity_cost_pre_bestpath
cigp = set_extcommunity_cost_igp
cpre.each do |id, val|
str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
end
cigp.each do |id, val|
str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
end
end
set_args_keys(state: 'no', string: str)
config_set('route_map', 'set_extcommunity_cost', @set_args)
return if igp.empty? && pre.empty?
str = ''
pre.each do |id, val|
str.concat('pre-bestpath ' + id.to_s + ' ' + val.to_s + ' ')
end
igp.each do |id, val|
str.concat('igp ' + id.to_s + ' ' + val.to_s + ' ')
end
set_args_keys(state: '', string: str)
config_set('route_map', 'set_extcommunity_cost', @set_args)
end
|
[
"def",
"set_extcommunity_cost_set",
"(",
"igp",
",",
"pre",
")",
"str",
"=",
"''",
"# reset first",
"if",
"set_extcommunity_cost_device",
"cpre",
"=",
"set_extcommunity_cost_pre_bestpath",
"cigp",
"=",
"set_extcommunity_cost_igp",
"cpre",
".",
"each",
"do",
"|",
"id",
",",
"val",
"|",
"str",
".",
"concat",
"(",
"'pre-bestpath '",
"+",
"id",
".",
"to_s",
"+",
"' '",
"+",
"val",
".",
"to_s",
"+",
"' '",
")",
"end",
"cigp",
".",
"each",
"do",
"|",
"id",
",",
"val",
"|",
"str",
".",
"concat",
"(",
"'igp '",
"+",
"id",
".",
"to_s",
"+",
"' '",
"+",
"val",
".",
"to_s",
"+",
"' '",
")",
"end",
"end",
"set_args_keys",
"(",
"state",
":",
"'no'",
",",
"string",
":",
"str",
")",
"config_set",
"(",
"'route_map'",
",",
"'set_extcommunity_cost'",
",",
"@set_args",
")",
"return",
"if",
"igp",
".",
"empty?",
"&&",
"pre",
".",
"empty?",
"str",
"=",
"''",
"pre",
".",
"each",
"do",
"|",
"id",
",",
"val",
"|",
"str",
".",
"concat",
"(",
"'pre-bestpath '",
"+",
"id",
".",
"to_s",
"+",
"' '",
"+",
"val",
".",
"to_s",
"+",
"' '",
")",
"end",
"igp",
".",
"each",
"do",
"|",
"id",
",",
"val",
"|",
"str",
".",
"concat",
"(",
"'igp '",
"+",
"id",
".",
"to_s",
"+",
"' '",
"+",
"val",
".",
"to_s",
"+",
"' '",
")",
"end",
"set_args_keys",
"(",
"state",
":",
"''",
",",
"string",
":",
"str",
")",
"config_set",
"(",
"'route_map'",
",",
"'set_extcommunity_cost'",
",",
"@set_args",
")",
"end"
] |
set extcommunity cost igp 0 22 igp 3 23
set extcommunity cost pre-bestpath 1 222 pre-bestpath 2 54
set extcommunity cost pre-bestpath 1 222 pre-bestpath 2 54 igp 0 22
|
[
"set",
"extcommunity",
"cost",
"igp",
"0",
"22",
"igp",
"3",
"23",
"set",
"extcommunity",
"cost",
"pre",
"-",
"bestpath",
"1",
"222",
"pre",
"-",
"bestpath",
"2",
"54",
"set",
"extcommunity",
"cost",
"pre",
"-",
"bestpath",
"1",
"222",
"pre",
"-",
"bestpath",
"2",
"54",
"igp",
"0",
"22"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/route_map.rb#L2475-L2500
|
20,345
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/overlay_global.rb
|
Cisco.OverlayGlobal.anycast_gateway_mac
|
def anycast_gateway_mac
mac = config_get('overlay_global', 'anycast_gateway_mac')
mac.nil? || mac.empty? ? default_anycast_gateway_mac : mac.downcase
end
|
ruby
|
def anycast_gateway_mac
mac = config_get('overlay_global', 'anycast_gateway_mac')
mac.nil? || mac.empty? ? default_anycast_gateway_mac : mac.downcase
end
|
[
"def",
"anycast_gateway_mac",
"mac",
"=",
"config_get",
"(",
"'overlay_global'",
",",
"'anycast_gateway_mac'",
")",
"mac",
".",
"nil?",
"||",
"mac",
".",
"empty?",
"?",
"default_anycast_gateway_mac",
":",
"mac",
".",
"downcase",
"end"
] |
anycast-gateway-mac
|
[
"anycast",
"-",
"gateway",
"-",
"mac"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/overlay_global.rb#L118-L121
|
20,346
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/tacacs_server.rb
|
Cisco.TacacsServer.encryption_key_set
|
def encryption_key_set(enctype, password)
password = Utils.add_quotes(password)
# if enctype is TACACS_SERVER_ENC_UNKNOWN, we will unset the key
if enctype == TACACS_SERVER_ENC_UNKNOWN
# if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we
# need to unset it. Otherwise the box is not configured with key, we
# don't need to do anything
if encryption_type != TACACS_SERVER_ENC_UNKNOWN
config_set('tacacs_server', 'encryption', state: 'no',
option: encryption_type,
key: encryption_password)
end
else
config_set('tacacs_server', 'encryption', state: '', option: enctype,
key: password)
end
end
|
ruby
|
def encryption_key_set(enctype, password)
password = Utils.add_quotes(password)
# if enctype is TACACS_SERVER_ENC_UNKNOWN, we will unset the key
if enctype == TACACS_SERVER_ENC_UNKNOWN
# if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we
# need to unset it. Otherwise the box is not configured with key, we
# don't need to do anything
if encryption_type != TACACS_SERVER_ENC_UNKNOWN
config_set('tacacs_server', 'encryption', state: 'no',
option: encryption_type,
key: encryption_password)
end
else
config_set('tacacs_server', 'encryption', state: '', option: enctype,
key: password)
end
end
|
[
"def",
"encryption_key_set",
"(",
"enctype",
",",
"password",
")",
"password",
"=",
"Utils",
".",
"add_quotes",
"(",
"password",
")",
"# if enctype is TACACS_SERVER_ENC_UNKNOWN, we will unset the key",
"if",
"enctype",
"==",
"TACACS_SERVER_ENC_UNKNOWN",
"# if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we",
"# need to unset it. Otherwise the box is not configured with key, we",
"# don't need to do anything",
"if",
"encryption_type",
"!=",
"TACACS_SERVER_ENC_UNKNOWN",
"config_set",
"(",
"'tacacs_server'",
",",
"'encryption'",
",",
"state",
":",
"'no'",
",",
"option",
":",
"encryption_type",
",",
"key",
":",
"encryption_password",
")",
"end",
"else",
"config_set",
"(",
"'tacacs_server'",
",",
"'encryption'",
",",
"state",
":",
"''",
",",
"option",
":",
"enctype",
",",
"key",
":",
"password",
")",
"end",
"end"
] |
Set encryption type and password
|
[
"Set",
"encryption",
"type",
"and",
"password"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/tacacs_server.rb#L155-L171
|
20,347
|
cisco/cisco-network-node-utils
|
lib/cisco_node_utils/itd_service.rb
|
Cisco.ItdService.ingress_interface=
|
def ingress_interface=(list)
ingress_interface_cleanup
@set_args[:state] = ''
list.each do |intf, next_hop|
@set_args[:interface] = intf
@set_args[:next] = ''
@set_args[:nhop] = ''
unless next_hop == '' || next_hop == 'default'
@set_args[:next] = 'next-hop'
@set_args[:nhop] = next_hop
end
config_set('itd_service', 'ingress_interface', @set_args)
end
set_args_keys_default
end
|
ruby
|
def ingress_interface=(list)
ingress_interface_cleanup
@set_args[:state] = ''
list.each do |intf, next_hop|
@set_args[:interface] = intf
@set_args[:next] = ''
@set_args[:nhop] = ''
unless next_hop == '' || next_hop == 'default'
@set_args[:next] = 'next-hop'
@set_args[:nhop] = next_hop
end
config_set('itd_service', 'ingress_interface', @set_args)
end
set_args_keys_default
end
|
[
"def",
"ingress_interface",
"=",
"(",
"list",
")",
"ingress_interface_cleanup",
"@set_args",
"[",
":state",
"]",
"=",
"''",
"list",
".",
"each",
"do",
"|",
"intf",
",",
"next_hop",
"|",
"@set_args",
"[",
":interface",
"]",
"=",
"intf",
"@set_args",
"[",
":next",
"]",
"=",
"''",
"@set_args",
"[",
":nhop",
"]",
"=",
"''",
"unless",
"next_hop",
"==",
"''",
"||",
"next_hop",
"==",
"'default'",
"@set_args",
"[",
":next",
"]",
"=",
"'next-hop'",
"@set_args",
"[",
":nhop",
"]",
"=",
"next_hop",
"end",
"config_set",
"(",
"'itd_service'",
",",
"'ingress_interface'",
",",
"@set_args",
")",
"end",
"set_args_keys_default",
"end"
] |
only one next-hop is allowed per interface but
due to nxos issues, it allows more than one;
so the workaround is to clean up the current ingress
intf and configure all of them again
|
[
"only",
"one",
"next",
"-",
"hop",
"is",
"allowed",
"per",
"interface",
"but",
"due",
"to",
"nxos",
"issues",
"it",
"allows",
"more",
"than",
"one",
";",
"so",
"the",
"workaround",
"is",
"to",
"clean",
"up",
"the",
"current",
"ingress",
"intf",
"and",
"configure",
"all",
"of",
"them",
"again"
] |
a617a9ef9d6bd18f35f2e2f2591033e1ddd46145
|
https://github.com/cisco/cisco-network-node-utils/blob/a617a9ef9d6bd18f35f2e2f2591033e1ddd46145/lib/cisco_node_utils/itd_service.rb#L199-L213
|
20,348
|
emancu/toml-rb
|
lib/toml-rb/keygroup.rb
|
TomlRB.Keygroup.ensure_key_not_defined
|
def ensure_key_not_defined(visited_keys)
fail ValueOverwriteError.new(full_key) if visited_keys.include?(full_key)
visited_keys << full_key
end
|
ruby
|
def ensure_key_not_defined(visited_keys)
fail ValueOverwriteError.new(full_key) if visited_keys.include?(full_key)
visited_keys << full_key
end
|
[
"def",
"ensure_key_not_defined",
"(",
"visited_keys",
")",
"fail",
"ValueOverwriteError",
".",
"new",
"(",
"full_key",
")",
"if",
"visited_keys",
".",
"include?",
"(",
"full_key",
")",
"visited_keys",
"<<",
"full_key",
"end"
] |
Fail if the key was already defined with a ValueOverwriteError
|
[
"Fail",
"if",
"the",
"key",
"was",
"already",
"defined",
"with",
"a",
"ValueOverwriteError"
] |
1b649547ed1cc1855b11eb7880c1ad03b8ab52e9
|
https://github.com/emancu/toml-rb/blob/1b649547ed1cc1855b11eb7880c1ad03b8ab52e9/lib/toml-rb/keygroup.rb#L21-L24
|
20,349
|
samnissen/watir-screenshot-stitch
|
lib/watir-screenshot-stitch.rb
|
Watir.Screenshot.save_stitch
|
def save_stitch(path, opts = {})
return @browser.screenshot.save(path) if base64_capable?
@options = opts
@path = path
calculate_dimensions
return self.save(@path) if (one_shot? || bug_shot?)
build_canvas
gather_slices
stitch_together
@combined_screenshot.write @path
end
|
ruby
|
def save_stitch(path, opts = {})
return @browser.screenshot.save(path) if base64_capable?
@options = opts
@path = path
calculate_dimensions
return self.save(@path) if (one_shot? || bug_shot?)
build_canvas
gather_slices
stitch_together
@combined_screenshot.write @path
end
|
[
"def",
"save_stitch",
"(",
"path",
",",
"opts",
"=",
"{",
"}",
")",
"return",
"@browser",
".",
"screenshot",
".",
"save",
"(",
"path",
")",
"if",
"base64_capable?",
"@options",
"=",
"opts",
"@path",
"=",
"path",
"calculate_dimensions",
"return",
"self",
".",
"save",
"(",
"@path",
")",
"if",
"(",
"one_shot?",
"||",
"bug_shot?",
")",
"build_canvas",
"gather_slices",
"stitch_together",
"@combined_screenshot",
".",
"write",
"@path",
"end"
] |
Represents stitched together screenshot and writes to file.
@example
opts = {:page_height_limit => 5000}
browser.screenshot.save_stitch("path/abc.png", browser, opts)
@param [String] path
@deprecated
@param [Watir::Browser] browser
@param [Hash] opts
|
[
"Represents",
"stitched",
"together",
"screenshot",
"and",
"writes",
"to",
"file",
"."
] |
4cb9ac14ec974751b185391f6832bfb7e205f531
|
https://github.com/samnissen/watir-screenshot-stitch/blob/4cb9ac14ec974751b185391f6832bfb7e205f531/lib/watir-screenshot-stitch.rb#L57-L70
|
20,350
|
samnissen/watir-screenshot-stitch
|
lib/watir-screenshot-stitch.rb
|
Watir.Screenshot.base64_canvas
|
def base64_canvas
return self.base64 if base64_capable?
output = nil
return self.base64 if one_shot? || bug_shot?
@browser.execute_script html2canvas_payload
@browser.execute_script h2c_activator
@browser.wait_until(timeout: MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME) {
output = @browser.execute_script "return window.canvasImgContentDecoded;"
}
raise "Could not generate screenshot blob within #{MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME} seconds" unless output
output.sub!(/^data\:image\/png\;base64,/, '')
end
|
ruby
|
def base64_canvas
return self.base64 if base64_capable?
output = nil
return self.base64 if one_shot? || bug_shot?
@browser.execute_script html2canvas_payload
@browser.execute_script h2c_activator
@browser.wait_until(timeout: MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME) {
output = @browser.execute_script "return window.canvasImgContentDecoded;"
}
raise "Could not generate screenshot blob within #{MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME} seconds" unless output
output.sub!(/^data\:image\/png\;base64,/, '')
end
|
[
"def",
"base64_canvas",
"return",
"self",
".",
"base64",
"if",
"base64_capable?",
"output",
"=",
"nil",
"return",
"self",
".",
"base64",
"if",
"one_shot?",
"||",
"bug_shot?",
"@browser",
".",
"execute_script",
"html2canvas_payload",
"@browser",
".",
"execute_script",
"h2c_activator",
"@browser",
".",
"wait_until",
"(",
"timeout",
":",
"MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME",
")",
"{",
"output",
"=",
"@browser",
".",
"execute_script",
"\"return window.canvasImgContentDecoded;\"",
"}",
"raise",
"\"Could not generate screenshot blob within #{MAXIMUM_SCREENSHOT_GENERATION_WAIT_TIME} seconds\"",
"unless",
"output",
"output",
".",
"sub!",
"(",
"/",
"\\:",
"\\/",
"\\;",
"/",
",",
"''",
")",
"end"
] |
Employs html2canvas to produce a Base64 encoded string
of a full page screenshot.
@example
browser.screenshot.base64_canvas(browser)
#=> '7HWJ43tZDscPleeUuPW6HhN3x+z7vU/lufmH0qNTtTum94IBWMT46evImci1vnFGT'
@deprecated
@param [Watir::Browser] browser
@return [String]
|
[
"Employs",
"html2canvas",
"to",
"produce",
"a",
"Base64",
"encoded",
"string",
"of",
"a",
"full",
"page",
"screenshot",
"."
] |
4cb9ac14ec974751b185391f6832bfb7e205f531
|
https://github.com/samnissen/watir-screenshot-stitch/blob/4cb9ac14ec974751b185391f6832bfb7e205f531/lib/watir-screenshot-stitch.rb#L86-L102
|
20,351
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.setup_zk
|
def setup_zk
@zk = ZK.new(@zkservers) if @zkservers
@zk.register(redis_nodes_path) { |event| handle_zk_event(event) }
if @safe_mode
@zk.on_expired_session { purge_clients }
end
@zk.on_connected { @zk.stat(redis_nodes_path, :watch => true) }
@zk.stat(redis_nodes_path, :watch => true)
update_znode_timestamp
end
|
ruby
|
def setup_zk
@zk = ZK.new(@zkservers) if @zkservers
@zk.register(redis_nodes_path) { |event| handle_zk_event(event) }
if @safe_mode
@zk.on_expired_session { purge_clients }
end
@zk.on_connected { @zk.stat(redis_nodes_path, :watch => true) }
@zk.stat(redis_nodes_path, :watch => true)
update_znode_timestamp
end
|
[
"def",
"setup_zk",
"@zk",
"=",
"ZK",
".",
"new",
"(",
"@zkservers",
")",
"if",
"@zkservers",
"@zk",
".",
"register",
"(",
"redis_nodes_path",
")",
"{",
"|",
"event",
"|",
"handle_zk_event",
"(",
"event",
")",
"}",
"if",
"@safe_mode",
"@zk",
".",
"on_expired_session",
"{",
"purge_clients",
"}",
"end",
"@zk",
".",
"on_connected",
"{",
"@zk",
".",
"stat",
"(",
"redis_nodes_path",
",",
":watch",
"=>",
"true",
")",
"}",
"@zk",
".",
"stat",
"(",
"redis_nodes_path",
",",
":watch",
"=>",
"true",
")",
"update_znode_timestamp",
"end"
] |
Sets up the underlying ZooKeeper connection.
|
[
"Sets",
"up",
"the",
"underlying",
"ZooKeeper",
"connection",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L188-L197
|
20,352
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.handle_zk_event
|
def handle_zk_event(event)
update_znode_timestamp
if event.node_created? || event.node_changed?
build_clients
elsif event.node_deleted?
purge_clients
@zk.stat(redis_nodes_path, :watch => true)
else
logger.error("Unknown ZK node event: #{event.inspect}")
end
ensure
@zk.stat(redis_nodes_path, :watch => true)
end
|
ruby
|
def handle_zk_event(event)
update_znode_timestamp
if event.node_created? || event.node_changed?
build_clients
elsif event.node_deleted?
purge_clients
@zk.stat(redis_nodes_path, :watch => true)
else
logger.error("Unknown ZK node event: #{event.inspect}")
end
ensure
@zk.stat(redis_nodes_path, :watch => true)
end
|
[
"def",
"handle_zk_event",
"(",
"event",
")",
"update_znode_timestamp",
"if",
"event",
".",
"node_created?",
"||",
"event",
".",
"node_changed?",
"build_clients",
"elsif",
"event",
".",
"node_deleted?",
"purge_clients",
"@zk",
".",
"stat",
"(",
"redis_nodes_path",
",",
":watch",
"=>",
"true",
")",
"else",
"logger",
".",
"error",
"(",
"\"Unknown ZK node event: #{event.inspect}\"",
")",
"end",
"ensure",
"@zk",
".",
"stat",
"(",
"redis_nodes_path",
",",
":watch",
"=>",
"true",
")",
"end"
] |
Handles a ZK event.
@param [ZK::Event] event the ZK event to handle
|
[
"Handles",
"a",
"ZK",
"event",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L202-L214
|
20,353
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.dispatch
|
def dispatch(method, *args, &block)
if @safe_mode && !recently_heard_from_node_manager?
build_clients
end
verify_supported!(method)
tries = 0
begin
client_for(method).send(method, *args, &block)
rescue *CONNECTIVITY_ERRORS => ex
logger.error("Error while handling `#{method}` - #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
if tries < @max_retries
tries += 1
free_client
build_clients
sleep(RETRY_WAIT_TIME)
retry
end
raise
ensure
free_client
end
end
|
ruby
|
def dispatch(method, *args, &block)
if @safe_mode && !recently_heard_from_node_manager?
build_clients
end
verify_supported!(method)
tries = 0
begin
client_for(method).send(method, *args, &block)
rescue *CONNECTIVITY_ERRORS => ex
logger.error("Error while handling `#{method}` - #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
if tries < @max_retries
tries += 1
free_client
build_clients
sleep(RETRY_WAIT_TIME)
retry
end
raise
ensure
free_client
end
end
|
[
"def",
"dispatch",
"(",
"method",
",",
"*",
"args",
",",
"&",
"block",
")",
"if",
"@safe_mode",
"&&",
"!",
"recently_heard_from_node_manager?",
"build_clients",
"end",
"verify_supported!",
"(",
"method",
")",
"tries",
"=",
"0",
"begin",
"client_for",
"(",
"method",
")",
".",
"send",
"(",
"method",
",",
"args",
",",
"block",
")",
"rescue",
"CONNECTIVITY_ERRORS",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error while handling `#{method}` - #{ex.inspect}\"",
")",
"logger",
".",
"error",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"if",
"tries",
"<",
"@max_retries",
"tries",
"+=",
"1",
"free_client",
"build_clients",
"sleep",
"(",
"RETRY_WAIT_TIME",
")",
"retry",
"end",
"raise",
"ensure",
"free_client",
"end",
"end"
] |
Dispatches a redis operation to a master or slave.
@param [Symbol] method the method to dispatch
@param [Array] args the arguments to pass to the method
@param [Proc] block an optional block to pass to the method
@return [Object] the result of dispatching the command
|
[
"Dispatches",
"a",
"redis",
"operation",
"to",
"a",
"master",
"or",
"slave",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L230-L254
|
20,354
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.fetch_nodes
|
def fetch_nodes
data = @zk.get(redis_nodes_path, :watch => true).first
nodes = symbolize_keys(decode(data))
logger.debug("Fetched nodes: #{nodes.inspect}")
nodes
rescue Zookeeper::Exceptions::InheritedConnectionError, ZK::Exceptions::InterruptedSession => ex
logger.debug { "Caught #{ex.class} '#{ex.message}' - reopening ZK client" }
@zk.reopen
retry
rescue *ZK_ERRORS => ex
logger.warn { "Caught #{ex.class} '#{ex.message}' - retrying" }
sleep(RETRY_WAIT_TIME)
retry
end
|
ruby
|
def fetch_nodes
data = @zk.get(redis_nodes_path, :watch => true).first
nodes = symbolize_keys(decode(data))
logger.debug("Fetched nodes: #{nodes.inspect}")
nodes
rescue Zookeeper::Exceptions::InheritedConnectionError, ZK::Exceptions::InterruptedSession => ex
logger.debug { "Caught #{ex.class} '#{ex.message}' - reopening ZK client" }
@zk.reopen
retry
rescue *ZK_ERRORS => ex
logger.warn { "Caught #{ex.class} '#{ex.message}' - retrying" }
sleep(RETRY_WAIT_TIME)
retry
end
|
[
"def",
"fetch_nodes",
"data",
"=",
"@zk",
".",
"get",
"(",
"redis_nodes_path",
",",
":watch",
"=>",
"true",
")",
".",
"first",
"nodes",
"=",
"symbolize_keys",
"(",
"decode",
"(",
"data",
")",
")",
"logger",
".",
"debug",
"(",
"\"Fetched nodes: #{nodes.inspect}\"",
")",
"nodes",
"rescue",
"Zookeeper",
"::",
"Exceptions",
"::",
"InheritedConnectionError",
",",
"ZK",
"::",
"Exceptions",
"::",
"InterruptedSession",
"=>",
"ex",
"logger",
".",
"debug",
"{",
"\"Caught #{ex.class} '#{ex.message}' - reopening ZK client\"",
"}",
"@zk",
".",
"reopen",
"retry",
"rescue",
"ZK_ERRORS",
"=>",
"ex",
"logger",
".",
"warn",
"{",
"\"Caught #{ex.class} '#{ex.message}' - retrying\"",
"}",
"sleep",
"(",
"RETRY_WAIT_TIME",
")",
"retry",
"end"
] |
Fetches the known redis nodes from ZooKeeper.
@return [Hash] the known master/slave redis servers
|
[
"Fetches",
"the",
"known",
"redis",
"nodes",
"from",
"ZooKeeper",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L322-L336
|
20,355
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.new_clients_for
|
def new_clients_for(*nodes)
nodes.map do |node|
host, port = node.split(':')
opts = {:host => host, :port => port}
opts.update(:db => @db) if @db
opts.update(:password => @password) if @password
client = Redis.new(@redis_client_options.merge(opts))
if @namespace
client = Redis::Namespace.new(@namespace, :redis => client)
end
@node_addresses[client] = node
client
end
end
|
ruby
|
def new_clients_for(*nodes)
nodes.map do |node|
host, port = node.split(':')
opts = {:host => host, :port => port}
opts.update(:db => @db) if @db
opts.update(:password => @password) if @password
client = Redis.new(@redis_client_options.merge(opts))
if @namespace
client = Redis::Namespace.new(@namespace, :redis => client)
end
@node_addresses[client] = node
client
end
end
|
[
"def",
"new_clients_for",
"(",
"*",
"nodes",
")",
"nodes",
".",
"map",
"do",
"|",
"node",
"|",
"host",
",",
"port",
"=",
"node",
".",
"split",
"(",
"':'",
")",
"opts",
"=",
"{",
":host",
"=>",
"host",
",",
":port",
"=>",
"port",
"}",
"opts",
".",
"update",
"(",
":db",
"=>",
"@db",
")",
"if",
"@db",
"opts",
".",
"update",
"(",
":password",
"=>",
"@password",
")",
"if",
"@password",
"client",
"=",
"Redis",
".",
"new",
"(",
"@redis_client_options",
".",
"merge",
"(",
"opts",
")",
")",
"if",
"@namespace",
"client",
"=",
"Redis",
"::",
"Namespace",
".",
"new",
"(",
"@namespace",
",",
":redis",
"=>",
"client",
")",
"end",
"@node_addresses",
"[",
"client",
"]",
"=",
"node",
"client",
"end",
"end"
] |
Builds new Redis clients for the specified nodes.
@param [Array<String>] nodes the array of redis host:port pairs
@return [Array<Redis>] the array of corresponding Redis clients
|
[
"Builds",
"new",
"Redis",
"clients",
"for",
"the",
"specified",
"nodes",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L342-L355
|
20,356
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.verify_role!
|
def verify_role!(node, role)
current_role = node.info['role']
if current_role.to_sym != role
raise InvalidNodeRoleError.new(address_for(node), role, current_role)
end
role
end
|
ruby
|
def verify_role!(node, role)
current_role = node.info['role']
if current_role.to_sym != role
raise InvalidNodeRoleError.new(address_for(node), role, current_role)
end
role
end
|
[
"def",
"verify_role!",
"(",
"node",
",",
"role",
")",
"current_role",
"=",
"node",
".",
"info",
"[",
"'role'",
"]",
"if",
"current_role",
".",
"to_sym",
"!=",
"role",
"raise",
"InvalidNodeRoleError",
".",
"new",
"(",
"address_for",
"(",
"node",
")",
",",
"role",
",",
"current_role",
")",
"end",
"role",
"end"
] |
Verifies the actual role for a redis node.
@param [Redis] node the redis node to check
@param [Symbol] role the role to verify
@return [Symbol] the verified role
@raise [InvalidNodeRoleError] if the role is invalid
|
[
"Verifies",
"the",
"actual",
"role",
"for",
"a",
"redis",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L374-L380
|
20,357
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.nodes_changed?
|
def nodes_changed?(new_nodes)
return true if address_for(@master) != new_nodes[:master]
return true if different?(addresses_for(@slaves), new_nodes[:slaves])
false
end
|
ruby
|
def nodes_changed?(new_nodes)
return true if address_for(@master) != new_nodes[:master]
return true if different?(addresses_for(@slaves), new_nodes[:slaves])
false
end
|
[
"def",
"nodes_changed?",
"(",
"new_nodes",
")",
"return",
"true",
"if",
"address_for",
"(",
"@master",
")",
"!=",
"new_nodes",
"[",
":master",
"]",
"return",
"true",
"if",
"different?",
"(",
"addresses_for",
"(",
"@slaves",
")",
",",
"new_nodes",
"[",
":slaves",
"]",
")",
"false",
"end"
] |
Determines if the currently known redis servers is different
from the nodes returned by ZooKeeper.
@param [Array<String>] new_nodes the new redis nodes
@return [Boolean] true if nodes are different, false otherwise
|
[
"Determines",
"if",
"the",
"currently",
"known",
"redis",
"servers",
"is",
"different",
"from",
"the",
"nodes",
"returned",
"by",
"ZooKeeper",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L413-L417
|
20,358
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.client_for
|
def client_for(method)
stack = Thread.current[@current_client_key] ||= []
client = if stack.last
stack.last
elsif @master_only
master
elsif REDIS_READ_OPS.include?(method)
slave
else
master
end
stack << client
client
end
|
ruby
|
def client_for(method)
stack = Thread.current[@current_client_key] ||= []
client = if stack.last
stack.last
elsif @master_only
master
elsif REDIS_READ_OPS.include?(method)
slave
else
master
end
stack << client
client
end
|
[
"def",
"client_for",
"(",
"method",
")",
"stack",
"=",
"Thread",
".",
"current",
"[",
"@current_client_key",
"]",
"||=",
"[",
"]",
"client",
"=",
"if",
"stack",
".",
"last",
"stack",
".",
"last",
"elsif",
"@master_only",
"master",
"elsif",
"REDIS_READ_OPS",
".",
"include?",
"(",
"method",
")",
"slave",
"else",
"master",
"end",
"stack",
"<<",
"client",
"client",
"end"
] |
Acquires a client to use for the specified operation.
@param [Symbol] method the method for which to retrieve a client
@return [Redis] a redis client to use
@note
This method stores a stack of clients used to handle the case
where the same RedisFailover::Client instance is referenced by
nested blocks (e.g., block passed to multi).
|
[
"Acquires",
"a",
"client",
"to",
"use",
"for",
"the",
"specified",
"operation",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L464-L478
|
20,359
|
ryanlecompte/redis_failover
|
lib/redis_failover/client.rb
|
RedisFailover.Client.parse_options
|
def parse_options(options)
@zk, @zkservers = options.values_at(:zk, :zkservers)
if [@zk, @zkservers].all? || [@zk, @zkservers].none?
raise ArgumentError, 'must specify :zk or :zkservers'
end
@root_znode = options.fetch(:znode_path, Util::DEFAULT_ROOT_ZNODE_PATH)
@namespace = options[:namespace]
@password = options[:password]
@db = options[:db]
@retry = options.fetch(:retry_failure, true)
@max_retries = @retry ? options.fetch(:max_retries, 3) : 0
@safe_mode = options.fetch(:safe_mode, true)
@master_only = options.fetch(:master_only, false)
@verify_role = options.fetch(:verify_role, true)
@redis_client_options = Redis::Client::DEFAULTS.keys.each_with_object({}) do |key, hash|
hash[key] = options[key]
end
end
|
ruby
|
def parse_options(options)
@zk, @zkservers = options.values_at(:zk, :zkservers)
if [@zk, @zkservers].all? || [@zk, @zkservers].none?
raise ArgumentError, 'must specify :zk or :zkservers'
end
@root_znode = options.fetch(:znode_path, Util::DEFAULT_ROOT_ZNODE_PATH)
@namespace = options[:namespace]
@password = options[:password]
@db = options[:db]
@retry = options.fetch(:retry_failure, true)
@max_retries = @retry ? options.fetch(:max_retries, 3) : 0
@safe_mode = options.fetch(:safe_mode, true)
@master_only = options.fetch(:master_only, false)
@verify_role = options.fetch(:verify_role, true)
@redis_client_options = Redis::Client::DEFAULTS.keys.each_with_object({}) do |key, hash|
hash[key] = options[key]
end
end
|
[
"def",
"parse_options",
"(",
"options",
")",
"@zk",
",",
"@zkservers",
"=",
"options",
".",
"values_at",
"(",
":zk",
",",
":zkservers",
")",
"if",
"[",
"@zk",
",",
"@zkservers",
"]",
".",
"all?",
"||",
"[",
"@zk",
",",
"@zkservers",
"]",
".",
"none?",
"raise",
"ArgumentError",
",",
"'must specify :zk or :zkservers'",
"end",
"@root_znode",
"=",
"options",
".",
"fetch",
"(",
":znode_path",
",",
"Util",
"::",
"DEFAULT_ROOT_ZNODE_PATH",
")",
"@namespace",
"=",
"options",
"[",
":namespace",
"]",
"@password",
"=",
"options",
"[",
":password",
"]",
"@db",
"=",
"options",
"[",
":db",
"]",
"@retry",
"=",
"options",
".",
"fetch",
"(",
":retry_failure",
",",
"true",
")",
"@max_retries",
"=",
"@retry",
"?",
"options",
".",
"fetch",
"(",
":max_retries",
",",
"3",
")",
":",
"0",
"@safe_mode",
"=",
"options",
".",
"fetch",
"(",
":safe_mode",
",",
"true",
")",
"@master_only",
"=",
"options",
".",
"fetch",
"(",
":master_only",
",",
"false",
")",
"@verify_role",
"=",
"options",
".",
"fetch",
"(",
":verify_role",
",",
"true",
")",
"@redis_client_options",
"=",
"Redis",
"::",
"Client",
"::",
"DEFAULTS",
".",
"keys",
".",
"each_with_object",
"(",
"{",
"}",
")",
"do",
"|",
"key",
",",
"hash",
"|",
"hash",
"[",
"key",
"]",
"=",
"options",
"[",
"key",
"]",
"end",
"end"
] |
Parses the configuration operations.
@param [Hash] options the configuration options
|
[
"Parses",
"the",
"configuration",
"operations",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/client.rb#L491-L510
|
20,360
|
ryanlecompte/redis_failover
|
lib/redis_failover/node.rb
|
RedisFailover.Node.make_slave!
|
def make_slave!(node)
perform_operation do |redis|
unless slave_of?(node)
redis.slaveof(node.host, node.port)
logger.info("#{self} is now a slave of #{node}")
wakeup
end
end
end
|
ruby
|
def make_slave!(node)
perform_operation do |redis|
unless slave_of?(node)
redis.slaveof(node.host, node.port)
logger.info("#{self} is now a slave of #{node}")
wakeup
end
end
end
|
[
"def",
"make_slave!",
"(",
"node",
")",
"perform_operation",
"do",
"|",
"redis",
"|",
"unless",
"slave_of?",
"(",
"node",
")",
"redis",
".",
"slaveof",
"(",
"node",
".",
"host",
",",
"node",
".",
"port",
")",
"logger",
".",
"info",
"(",
"\"#{self} is now a slave of #{node}\"",
")",
"wakeup",
"end",
"end",
"end"
] |
Makes this node a slave of the given node.
@param [Node] node the node of which to become a slave
|
[
"Makes",
"this",
"node",
"a",
"slave",
"of",
"the",
"given",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node.rb#L80-L88
|
20,361
|
ryanlecompte/redis_failover
|
lib/redis_failover/node.rb
|
RedisFailover.Node.perform_operation
|
def perform_operation
redis = nil
Timeout.timeout(MAX_OP_WAIT_TIME) do
redis = new_client
yield redis
end
rescue Exception => ex
raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
ensure
if redis
begin
redis.client.disconnect
rescue Exception => ex
raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
end
end
end
|
ruby
|
def perform_operation
redis = nil
Timeout.timeout(MAX_OP_WAIT_TIME) do
redis = new_client
yield redis
end
rescue Exception => ex
raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
ensure
if redis
begin
redis.client.disconnect
rescue Exception => ex
raise NodeUnavailableError, "#{ex.class}: #{ex.message}", ex.backtrace
end
end
end
|
[
"def",
"perform_operation",
"redis",
"=",
"nil",
"Timeout",
".",
"timeout",
"(",
"MAX_OP_WAIT_TIME",
")",
"do",
"redis",
"=",
"new_client",
"yield",
"redis",
"end",
"rescue",
"Exception",
"=>",
"ex",
"raise",
"NodeUnavailableError",
",",
"\"#{ex.class}: #{ex.message}\"",
",",
"ex",
".",
"backtrace",
"ensure",
"if",
"redis",
"begin",
"redis",
".",
"client",
".",
"disconnect",
"rescue",
"Exception",
"=>",
"ex",
"raise",
"NodeUnavailableError",
",",
"\"#{ex.class}: #{ex.message}\"",
",",
"ex",
".",
"backtrace",
"end",
"end",
"end"
] |
Safely performs a redis operation within a given timeout window.
@yield [Redis] the redis client to use for the operation
@raise [NodeUnavailableError] if node is currently unreachable
|
[
"Safely",
"performs",
"a",
"redis",
"operation",
"within",
"a",
"given",
"timeout",
"window",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node.rb#L172-L188
|
20,362
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.setup_zk
|
def setup_zk
unless @zk
@zk = ZK.new("#{@options[:zkservers]}#{@options[:chroot] || ''}")
@zk.register(manual_failover_path) do |event|
handle_manual_failover_update(event)
end
@zk.on_connected { @zk.stat(manual_failover_path, :watch => true) }
end
create_path(@root_znode)
create_path(current_state_root)
@zk.stat(manual_failover_path, :watch => true)
end
|
ruby
|
def setup_zk
unless @zk
@zk = ZK.new("#{@options[:zkservers]}#{@options[:chroot] || ''}")
@zk.register(manual_failover_path) do |event|
handle_manual_failover_update(event)
end
@zk.on_connected { @zk.stat(manual_failover_path, :watch => true) }
end
create_path(@root_znode)
create_path(current_state_root)
@zk.stat(manual_failover_path, :watch => true)
end
|
[
"def",
"setup_zk",
"unless",
"@zk",
"@zk",
"=",
"ZK",
".",
"new",
"(",
"\"#{@options[:zkservers]}#{@options[:chroot] || ''}\"",
")",
"@zk",
".",
"register",
"(",
"manual_failover_path",
")",
"do",
"|",
"event",
"|",
"handle_manual_failover_update",
"(",
"event",
")",
"end",
"@zk",
".",
"on_connected",
"{",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"}",
"end",
"create_path",
"(",
"@root_znode",
")",
"create_path",
"(",
"current_state_root",
")",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"end"
] |
Configures the ZooKeeper client.
|
[
"Configures",
"the",
"ZooKeeper",
"client",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L110-L122
|
20,363
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.handle_unavailable
|
def handle_unavailable(node, snapshots)
# no-op if we already know about this node
return if @unavailable.include?(node)
logger.info("Handling unavailable node: #{node}")
@unavailable << node
# find a new master if this node was a master
if node == @master
logger.info("Demoting currently unavailable master #{node}.")
promote_new_master(snapshots)
else
@slaves.delete(node)
end
end
|
ruby
|
def handle_unavailable(node, snapshots)
# no-op if we already know about this node
return if @unavailable.include?(node)
logger.info("Handling unavailable node: #{node}")
@unavailable << node
# find a new master if this node was a master
if node == @master
logger.info("Demoting currently unavailable master #{node}.")
promote_new_master(snapshots)
else
@slaves.delete(node)
end
end
|
[
"def",
"handle_unavailable",
"(",
"node",
",",
"snapshots",
")",
"# no-op if we already know about this node",
"return",
"if",
"@unavailable",
".",
"include?",
"(",
"node",
")",
"logger",
".",
"info",
"(",
"\"Handling unavailable node: #{node}\"",
")",
"@unavailable",
"<<",
"node",
"# find a new master if this node was a master",
"if",
"node",
"==",
"@master",
"logger",
".",
"info",
"(",
"\"Demoting currently unavailable master #{node}.\"",
")",
"promote_new_master",
"(",
"snapshots",
")",
"else",
"@slaves",
".",
"delete",
"(",
"node",
")",
"end",
"end"
] |
Handles an unavailable node.
@param [Node] node the unavailable node
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
|
[
"Handles",
"an",
"unavailable",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L128-L141
|
20,364
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.handle_available
|
def handle_available(node, snapshots)
reconcile(node)
# no-op if we already know about this node
return if @master == node || (@master && @slaves.include?(node))
logger.info("Handling available node: #{node}")
if @master
# master already exists, make a slave
node.make_slave!(@master)
@slaves << node
else
# no master exists, make this the new master
promote_new_master(snapshots, node)
end
@unavailable.delete(node)
end
|
ruby
|
def handle_available(node, snapshots)
reconcile(node)
# no-op if we already know about this node
return if @master == node || (@master && @slaves.include?(node))
logger.info("Handling available node: #{node}")
if @master
# master already exists, make a slave
node.make_slave!(@master)
@slaves << node
else
# no master exists, make this the new master
promote_new_master(snapshots, node)
end
@unavailable.delete(node)
end
|
[
"def",
"handle_available",
"(",
"node",
",",
"snapshots",
")",
"reconcile",
"(",
"node",
")",
"# no-op if we already know about this node",
"return",
"if",
"@master",
"==",
"node",
"||",
"(",
"@master",
"&&",
"@slaves",
".",
"include?",
"(",
"node",
")",
")",
"logger",
".",
"info",
"(",
"\"Handling available node: #{node}\"",
")",
"if",
"@master",
"# master already exists, make a slave",
"node",
".",
"make_slave!",
"(",
"@master",
")",
"@slaves",
"<<",
"node",
"else",
"# no master exists, make this the new master",
"promote_new_master",
"(",
"snapshots",
",",
"node",
")",
"end",
"@unavailable",
".",
"delete",
"(",
"node",
")",
"end"
] |
Handles an available node.
@param [Node] node the available node
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
|
[
"Handles",
"an",
"available",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L147-L164
|
20,365
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.handle_syncing
|
def handle_syncing(node, snapshots)
reconcile(node)
if node.syncing_with_master? && node.prohibits_stale_reads?
logger.info("Node #{node} not ready yet, still syncing with master.")
force_unavailable_slave(node)
else
# otherwise, we can use this node
handle_available(node, snapshots)
end
end
|
ruby
|
def handle_syncing(node, snapshots)
reconcile(node)
if node.syncing_with_master? && node.prohibits_stale_reads?
logger.info("Node #{node} not ready yet, still syncing with master.")
force_unavailable_slave(node)
else
# otherwise, we can use this node
handle_available(node, snapshots)
end
end
|
[
"def",
"handle_syncing",
"(",
"node",
",",
"snapshots",
")",
"reconcile",
"(",
"node",
")",
"if",
"node",
".",
"syncing_with_master?",
"&&",
"node",
".",
"prohibits_stale_reads?",
"logger",
".",
"info",
"(",
"\"Node #{node} not ready yet, still syncing with master.\"",
")",
"force_unavailable_slave",
"(",
"node",
")",
"else",
"# otherwise, we can use this node",
"handle_available",
"(",
"node",
",",
"snapshots",
")",
"end",
"end"
] |
Handles a node that is currently syncing.
@param [Node] node the syncing node
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
|
[
"Handles",
"a",
"node",
"that",
"is",
"currently",
"syncing",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L170-L180
|
20,366
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.handle_manual_failover
|
def handle_manual_failover(node, snapshots)
# no-op if node to be failed over is already master
return if @master == node
logger.info("Handling manual failover")
# ensure we can talk to the node
node.ping
# make current master a slave, and promote new master
@slaves << @master if @master
@slaves.delete(node)
promote_new_master(snapshots, node)
end
|
ruby
|
def handle_manual_failover(node, snapshots)
# no-op if node to be failed over is already master
return if @master == node
logger.info("Handling manual failover")
# ensure we can talk to the node
node.ping
# make current master a slave, and promote new master
@slaves << @master if @master
@slaves.delete(node)
promote_new_master(snapshots, node)
end
|
[
"def",
"handle_manual_failover",
"(",
"node",
",",
"snapshots",
")",
"# no-op if node to be failed over is already master",
"return",
"if",
"@master",
"==",
"node",
"logger",
".",
"info",
"(",
"\"Handling manual failover\"",
")",
"# ensure we can talk to the node",
"node",
".",
"ping",
"# make current master a slave, and promote new master",
"@slaves",
"<<",
"@master",
"if",
"@master",
"@slaves",
".",
"delete",
"(",
"node",
")",
"promote_new_master",
"(",
"snapshots",
",",
"node",
")",
"end"
] |
Handles a manual failover request to the given node.
@param [Node] node the candidate node for failover
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
|
[
"Handles",
"a",
"manual",
"failover",
"request",
"to",
"the",
"given",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L186-L198
|
20,367
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.promote_new_master
|
def promote_new_master(snapshots, node = nil)
delete_path(redis_nodes_path)
@master = nil
# make a specific node or selected candidate the new master
candidate = node || failover_strategy_candidate(snapshots)
if candidate.nil?
logger.error('Failed to promote a new master, no candidate available.')
else
@slaves.delete(candidate)
@unavailable.delete(candidate)
redirect_slaves_to(candidate)
candidate.make_master!
@master = candidate
write_current_redis_nodes
@master_promotion_attempts = 0
logger.info("Successfully promoted #{candidate} to master.")
end
end
|
ruby
|
def promote_new_master(snapshots, node = nil)
delete_path(redis_nodes_path)
@master = nil
# make a specific node or selected candidate the new master
candidate = node || failover_strategy_candidate(snapshots)
if candidate.nil?
logger.error('Failed to promote a new master, no candidate available.')
else
@slaves.delete(candidate)
@unavailable.delete(candidate)
redirect_slaves_to(candidate)
candidate.make_master!
@master = candidate
write_current_redis_nodes
@master_promotion_attempts = 0
logger.info("Successfully promoted #{candidate} to master.")
end
end
|
[
"def",
"promote_new_master",
"(",
"snapshots",
",",
"node",
"=",
"nil",
")",
"delete_path",
"(",
"redis_nodes_path",
")",
"@master",
"=",
"nil",
"# make a specific node or selected candidate the new master",
"candidate",
"=",
"node",
"||",
"failover_strategy_candidate",
"(",
"snapshots",
")",
"if",
"candidate",
".",
"nil?",
"logger",
".",
"error",
"(",
"'Failed to promote a new master, no candidate available.'",
")",
"else",
"@slaves",
".",
"delete",
"(",
"candidate",
")",
"@unavailable",
".",
"delete",
"(",
"candidate",
")",
"redirect_slaves_to",
"(",
"candidate",
")",
"candidate",
".",
"make_master!",
"@master",
"=",
"candidate",
"write_current_redis_nodes",
"@master_promotion_attempts",
"=",
"0",
"logger",
".",
"info",
"(",
"\"Successfully promoted #{candidate} to master.\"",
")",
"end",
"end"
] |
Promotes a new master.
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
@param [Node] node the optional node to promote
|
[
"Promotes",
"a",
"new",
"master",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L204-L223
|
20,368
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.find_existing_master
|
def find_existing_master
if data = @zk.get(redis_nodes_path).first
nodes = symbolize_keys(decode(data))
master = node_from(nodes[:master])
logger.info("Master from existing znode config: #{master || 'none'}")
# Check for case where a node previously thought to be the master was
# somehow manually reconfigured to be a slave outside of the node manager's
# control.
begin
if master && master.slave?
raise InvalidNodeRoleError.new(master, :master, :slave)
end
rescue RedisFailover::NodeUnavailableError => ex
logger.warn("Failed to check whether existing master has invalid role: #{ex.inspect}")
end
master
end
rescue ZK::Exceptions::NoNode
# blank slate, no last known master
nil
end
|
ruby
|
def find_existing_master
if data = @zk.get(redis_nodes_path).first
nodes = symbolize_keys(decode(data))
master = node_from(nodes[:master])
logger.info("Master from existing znode config: #{master || 'none'}")
# Check for case where a node previously thought to be the master was
# somehow manually reconfigured to be a slave outside of the node manager's
# control.
begin
if master && master.slave?
raise InvalidNodeRoleError.new(master, :master, :slave)
end
rescue RedisFailover::NodeUnavailableError => ex
logger.warn("Failed to check whether existing master has invalid role: #{ex.inspect}")
end
master
end
rescue ZK::Exceptions::NoNode
# blank slate, no last known master
nil
end
|
[
"def",
"find_existing_master",
"if",
"data",
"=",
"@zk",
".",
"get",
"(",
"redis_nodes_path",
")",
".",
"first",
"nodes",
"=",
"symbolize_keys",
"(",
"decode",
"(",
"data",
")",
")",
"master",
"=",
"node_from",
"(",
"nodes",
"[",
":master",
"]",
")",
"logger",
".",
"info",
"(",
"\"Master from existing znode config: #{master || 'none'}\"",
")",
"# Check for case where a node previously thought to be the master was",
"# somehow manually reconfigured to be a slave outside of the node manager's",
"# control.",
"begin",
"if",
"master",
"&&",
"master",
".",
"slave?",
"raise",
"InvalidNodeRoleError",
".",
"new",
"(",
"master",
",",
":master",
",",
":slave",
")",
"end",
"rescue",
"RedisFailover",
"::",
"NodeUnavailableError",
"=>",
"ex",
"logger",
".",
"warn",
"(",
"\"Failed to check whether existing master has invalid role: #{ex.inspect}\"",
")",
"end",
"master",
"end",
"rescue",
"ZK",
"::",
"Exceptions",
"::",
"NoNode",
"# blank slate, no last known master",
"nil",
"end"
] |
Seeds the initial node master from an existing znode config.
|
[
"Seeds",
"the",
"initial",
"node",
"master",
"from",
"an",
"existing",
"znode",
"config",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L254-L275
|
20,369
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.node_from
|
def node_from(node_string)
return if node_string.nil?
host, port = node_string.split(':', 2)
Node.new(:host => host, :port => port, :password => @options[:password])
end
|
ruby
|
def node_from(node_string)
return if node_string.nil?
host, port = node_string.split(':', 2)
Node.new(:host => host, :port => port, :password => @options[:password])
end
|
[
"def",
"node_from",
"(",
"node_string",
")",
"return",
"if",
"node_string",
".",
"nil?",
"host",
",",
"port",
"=",
"node_string",
".",
"split",
"(",
"':'",
",",
"2",
")",
"Node",
".",
"new",
"(",
":host",
"=>",
"host",
",",
":port",
"=>",
"port",
",",
":password",
"=>",
"@options",
"[",
":password",
"]",
")",
"end"
] |
Creates a Node instance from a string.
@param [String] node_string a string representation of a node (e.g., host:port)
@return [Node] the Node representation
|
[
"Creates",
"a",
"Node",
"instance",
"from",
"a",
"string",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L281-L285
|
20,370
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.guess_master
|
def guess_master(nodes)
master_nodes = nodes.select { |node| node.master? }
raise NoMasterError if master_nodes.empty?
raise MultipleMastersError.new(master_nodes) if master_nodes.size > 1
master_nodes.first
end
|
ruby
|
def guess_master(nodes)
master_nodes = nodes.select { |node| node.master? }
raise NoMasterError if master_nodes.empty?
raise MultipleMastersError.new(master_nodes) if master_nodes.size > 1
master_nodes.first
end
|
[
"def",
"guess_master",
"(",
"nodes",
")",
"master_nodes",
"=",
"nodes",
".",
"select",
"{",
"|",
"node",
"|",
"node",
".",
"master?",
"}",
"raise",
"NoMasterError",
"if",
"master_nodes",
".",
"empty?",
"raise",
"MultipleMastersError",
".",
"new",
"(",
"master_nodes",
")",
"if",
"master_nodes",
".",
"size",
">",
"1",
"master_nodes",
".",
"first",
"end"
] |
Searches for the master node.
@param [Array<Node>] nodes the nodes to search
@return [Node] the found master node, nil if not found
|
[
"Searches",
"for",
"the",
"master",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L302-L307
|
20,371
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.redirect_slaves_to
|
def redirect_slaves_to(node)
@slaves.dup.each do |slave|
begin
slave.make_slave!(node)
rescue NodeUnavailableError
logger.info("Failed to redirect unreachable slave #{slave} to #{node}")
force_unavailable_slave(slave)
end
end
end
|
ruby
|
def redirect_slaves_to(node)
@slaves.dup.each do |slave|
begin
slave.make_slave!(node)
rescue NodeUnavailableError
logger.info("Failed to redirect unreachable slave #{slave} to #{node}")
force_unavailable_slave(slave)
end
end
end
|
[
"def",
"redirect_slaves_to",
"(",
"node",
")",
"@slaves",
".",
"dup",
".",
"each",
"do",
"|",
"slave",
"|",
"begin",
"slave",
".",
"make_slave!",
"(",
"node",
")",
"rescue",
"NodeUnavailableError",
"logger",
".",
"info",
"(",
"\"Failed to redirect unreachable slave #{slave} to #{node}\"",
")",
"force_unavailable_slave",
"(",
"slave",
")",
"end",
"end",
"end"
] |
Redirects all slaves to the specified node.
@param [Node] node the node to which slaves are redirected
|
[
"Redirects",
"all",
"slaves",
"to",
"the",
"specified",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L312-L321
|
20,372
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.reconcile
|
def reconcile(node)
return if @master == node && node.master?
return if @master && node.slave_of?(@master)
logger.info("Reconciling node #{node}")
if @master == node && !node.master?
# we think the node is a master, but the node doesn't
node.make_master!
return
end
# verify that node is a slave for the current master
if @master && !node.slave_of?(@master)
node.make_slave!(@master)
end
end
|
ruby
|
def reconcile(node)
return if @master == node && node.master?
return if @master && node.slave_of?(@master)
logger.info("Reconciling node #{node}")
if @master == node && !node.master?
# we think the node is a master, but the node doesn't
node.make_master!
return
end
# verify that node is a slave for the current master
if @master && !node.slave_of?(@master)
node.make_slave!(@master)
end
end
|
[
"def",
"reconcile",
"(",
"node",
")",
"return",
"if",
"@master",
"==",
"node",
"&&",
"node",
".",
"master?",
"return",
"if",
"@master",
"&&",
"node",
".",
"slave_of?",
"(",
"@master",
")",
"logger",
".",
"info",
"(",
"\"Reconciling node #{node}\"",
")",
"if",
"@master",
"==",
"node",
"&&",
"!",
"node",
".",
"master?",
"# we think the node is a master, but the node doesn't",
"node",
".",
"make_master!",
"return",
"end",
"# verify that node is a slave for the current master",
"if",
"@master",
"&&",
"!",
"node",
".",
"slave_of?",
"(",
"@master",
")",
"node",
".",
"make_slave!",
"(",
"@master",
")",
"end",
"end"
] |
It's possible that a newly available node may have been restarted
and completely lost its dynamically set run-time role by the node
manager. This method ensures that the node resumes its role as
determined by the manager.
@param [Node] node the node to reconcile
|
[
"It",
"s",
"possible",
"that",
"a",
"newly",
"available",
"node",
"may",
"have",
"been",
"restarted",
"and",
"completely",
"lost",
"its",
"dynamically",
"set",
"run",
"-",
"time",
"role",
"by",
"the",
"node",
"manager",
".",
"This",
"method",
"ensures",
"that",
"the",
"node",
"resumes",
"its",
"role",
"as",
"determined",
"by",
"the",
"manager",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L337-L352
|
20,373
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.delete_path
|
def delete_path(path)
@zk.delete(path)
logger.info("Deleted ZK node #{path}")
rescue ZK::Exceptions::NoNode => ex
logger.info("Tried to delete missing znode: #{ex.inspect}")
end
|
ruby
|
def delete_path(path)
@zk.delete(path)
logger.info("Deleted ZK node #{path}")
rescue ZK::Exceptions::NoNode => ex
logger.info("Tried to delete missing znode: #{ex.inspect}")
end
|
[
"def",
"delete_path",
"(",
"path",
")",
"@zk",
".",
"delete",
"(",
"path",
")",
"logger",
".",
"info",
"(",
"\"Deleted ZK node #{path}\"",
")",
"rescue",
"ZK",
"::",
"Exceptions",
"::",
"NoNode",
"=>",
"ex",
"logger",
".",
"info",
"(",
"\"Tried to delete missing znode: #{ex.inspect}\"",
")",
"end"
] |
Deletes the znode path containing the redis nodes.
@param [String] path the znode path to delete
|
[
"Deletes",
"the",
"znode",
"path",
"containing",
"the",
"redis",
"nodes",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L375-L380
|
20,374
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.create_path
|
def create_path(path, options = {})
unless @zk.exists?(path)
@zk.create(path,
options[:initial_value],
:ephemeral => options.fetch(:ephemeral, false))
logger.info("Created ZK node #{path}")
end
rescue ZK::Exceptions::NodeExists
# best effort
end
|
ruby
|
def create_path(path, options = {})
unless @zk.exists?(path)
@zk.create(path,
options[:initial_value],
:ephemeral => options.fetch(:ephemeral, false))
logger.info("Created ZK node #{path}")
end
rescue ZK::Exceptions::NodeExists
# best effort
end
|
[
"def",
"create_path",
"(",
"path",
",",
"options",
"=",
"{",
"}",
")",
"unless",
"@zk",
".",
"exists?",
"(",
"path",
")",
"@zk",
".",
"create",
"(",
"path",
",",
"options",
"[",
":initial_value",
"]",
",",
":ephemeral",
"=>",
"options",
".",
"fetch",
"(",
":ephemeral",
",",
"false",
")",
")",
"logger",
".",
"info",
"(",
"\"Created ZK node #{path}\"",
")",
"end",
"rescue",
"ZK",
"::",
"Exceptions",
"::",
"NodeExists",
"# best effort",
"end"
] |
Creates a znode path.
@param [String] path the znode path to create
@param [Hash] options the options used to create the path
@option options [String] :initial_value an initial value for the znode
@option options [Boolean] :ephemeral true if node is ephemeral, false otherwise
|
[
"Creates",
"a",
"znode",
"path",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L388-L397
|
20,375
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.write_state
|
def write_state(path, value, options = {})
create_path(path, options.merge(:initial_value => value))
@zk.set(path, value)
end
|
ruby
|
def write_state(path, value, options = {})
create_path(path, options.merge(:initial_value => value))
@zk.set(path, value)
end
|
[
"def",
"write_state",
"(",
"path",
",",
"value",
",",
"options",
"=",
"{",
"}",
")",
"create_path",
"(",
"path",
",",
"options",
".",
"merge",
"(",
":initial_value",
"=>",
"value",
")",
")",
"@zk",
".",
"set",
"(",
"path",
",",
"value",
")",
"end"
] |
Writes state to a particular znode path.
@param [String] path the znode path that should be written to
@param [String] value the value to write to the znode
@param [Hash] options the default options to be used when creating the node
@note the path will be created if it doesn't exist
|
[
"Writes",
"state",
"to",
"a",
"particular",
"znode",
"path",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L405-L408
|
20,376
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.handle_manual_failover_update
|
def handle_manual_failover_update(event)
if event.node_created? || event.node_changed?
perform_manual_failover
end
rescue => ex
logger.error("Error scheduling a manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end
|
ruby
|
def handle_manual_failover_update(event)
if event.node_created? || event.node_changed?
perform_manual_failover
end
rescue => ex
logger.error("Error scheduling a manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end
|
[
"def",
"handle_manual_failover_update",
"(",
"event",
")",
"if",
"event",
".",
"node_created?",
"||",
"event",
".",
"node_changed?",
"perform_manual_failover",
"end",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error scheduling a manual failover: #{ex.inspect}\"",
")",
"logger",
".",
"error",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"end"
] |
Handles a manual failover znode update.
@param [ZK::Event] event the ZK event to handle
|
[
"Handles",
"a",
"manual",
"failover",
"znode",
"update",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L413-L422
|
20,377
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.update_master_state
|
def update_master_state(node, snapshots)
state = @node_strategy.determine_state(node, snapshots)
case state
when :unavailable
handle_unavailable(node, snapshots)
when :available
if node.syncing_with_master?
handle_syncing(node, snapshots)
else
handle_available(node, snapshots)
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue *ZK_ERRORS
# fail hard if this is a ZK connection-related error
raise
rescue => ex
logger.error("Error handling state report for #{[node, state].inspect}: #{ex.inspect}")
end
|
ruby
|
def update_master_state(node, snapshots)
state = @node_strategy.determine_state(node, snapshots)
case state
when :unavailable
handle_unavailable(node, snapshots)
when :available
if node.syncing_with_master?
handle_syncing(node, snapshots)
else
handle_available(node, snapshots)
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue *ZK_ERRORS
# fail hard if this is a ZK connection-related error
raise
rescue => ex
logger.error("Error handling state report for #{[node, state].inspect}: #{ex.inspect}")
end
|
[
"def",
"update_master_state",
"(",
"node",
",",
"snapshots",
")",
"state",
"=",
"@node_strategy",
".",
"determine_state",
"(",
"node",
",",
"snapshots",
")",
"case",
"state",
"when",
":unavailable",
"handle_unavailable",
"(",
"node",
",",
"snapshots",
")",
"when",
":available",
"if",
"node",
".",
"syncing_with_master?",
"handle_syncing",
"(",
"node",
",",
"snapshots",
")",
"else",
"handle_available",
"(",
"node",
",",
"snapshots",
")",
"end",
"else",
"raise",
"InvalidNodeStateError",
".",
"new",
"(",
"node",
",",
"state",
")",
"end",
"rescue",
"ZK_ERRORS",
"# fail hard if this is a ZK connection-related error",
"raise",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error handling state report for #{[node, state].inspect}: #{ex.inspect}\"",
")",
"end"
] |
Used to update the master node manager state. These states are only handled if
this node manager instance is serving as the master manager.
@param [Node] node the node to handle
@param [Hash<Node, NodeSnapshot>] snapshots the current set of snapshots
|
[
"Used",
"to",
"update",
"the",
"master",
"node",
"manager",
"state",
".",
"These",
"states",
"are",
"only",
"handled",
"if",
"this",
"node",
"manager",
"instance",
"is",
"serving",
"as",
"the",
"master",
"manager",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L482-L501
|
20,378
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.update_current_state
|
def update_current_state(node, state, latency = nil)
old_unavailable = @monitored_unavailable.dup
old_available = @monitored_available.dup
case state
when :unavailable
unless @monitored_unavailable.include?(node)
@monitored_unavailable << node
@monitored_available.delete(node)
write_current_monitored_state
end
when :available
last_latency = @monitored_available[node]
if last_latency.nil? || (latency - last_latency) > LATENCY_THRESHOLD
@monitored_available[node] = latency
@monitored_unavailable.delete(node)
write_current_monitored_state
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue => ex
# if an error occurs, make sure that we rollback to the old state
@monitored_unavailable = old_unavailable
@monitored_available = old_available
raise
end
|
ruby
|
def update_current_state(node, state, latency = nil)
old_unavailable = @monitored_unavailable.dup
old_available = @monitored_available.dup
case state
when :unavailable
unless @monitored_unavailable.include?(node)
@monitored_unavailable << node
@monitored_available.delete(node)
write_current_monitored_state
end
when :available
last_latency = @monitored_available[node]
if last_latency.nil? || (latency - last_latency) > LATENCY_THRESHOLD
@monitored_available[node] = latency
@monitored_unavailable.delete(node)
write_current_monitored_state
end
else
raise InvalidNodeStateError.new(node, state)
end
rescue => ex
# if an error occurs, make sure that we rollback to the old state
@monitored_unavailable = old_unavailable
@monitored_available = old_available
raise
end
|
[
"def",
"update_current_state",
"(",
"node",
",",
"state",
",",
"latency",
"=",
"nil",
")",
"old_unavailable",
"=",
"@monitored_unavailable",
".",
"dup",
"old_available",
"=",
"@monitored_available",
".",
"dup",
"case",
"state",
"when",
":unavailable",
"unless",
"@monitored_unavailable",
".",
"include?",
"(",
"node",
")",
"@monitored_unavailable",
"<<",
"node",
"@monitored_available",
".",
"delete",
"(",
"node",
")",
"write_current_monitored_state",
"end",
"when",
":available",
"last_latency",
"=",
"@monitored_available",
"[",
"node",
"]",
"if",
"last_latency",
".",
"nil?",
"||",
"(",
"latency",
"-",
"last_latency",
")",
">",
"LATENCY_THRESHOLD",
"@monitored_available",
"[",
"node",
"]",
"=",
"latency",
"@monitored_unavailable",
".",
"delete",
"(",
"node",
")",
"write_current_monitored_state",
"end",
"else",
"raise",
"InvalidNodeStateError",
".",
"new",
"(",
"node",
",",
"state",
")",
"end",
"rescue",
"=>",
"ex",
"# if an error occurs, make sure that we rollback to the old state",
"@monitored_unavailable",
"=",
"old_unavailable",
"@monitored_available",
"=",
"old_available",
"raise",
"end"
] |
Updates the current view of the world for this particular node
manager instance. All node managers write this state regardless
of whether they are the master manager or not.
@param [Node] node the node to handle
@param [Symbol] state the node state
@param [Integer] latency an optional latency
|
[
"Updates",
"the",
"current",
"view",
"of",
"the",
"world",
"for",
"this",
"particular",
"node",
"manager",
"instance",
".",
"All",
"node",
"managers",
"write",
"this",
"state",
"regardless",
"of",
"whether",
"they",
"are",
"the",
"master",
"manager",
"or",
"not",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L510-L536
|
20,379
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.current_node_snapshots
|
def current_node_snapshots
nodes = {}
snapshots = Hash.new { |h, k| h[k] = NodeSnapshot.new(k) }
fetch_node_manager_states.each do |node_manager, states|
available, unavailable = states.values_at(:available, :unavailable)
available.each do |node_string, latency|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].viewable_by(node_manager, latency)
end
unavailable.each do |node_string|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].unviewable_by(node_manager)
end
end
snapshots
end
|
ruby
|
def current_node_snapshots
nodes = {}
snapshots = Hash.new { |h, k| h[k] = NodeSnapshot.new(k) }
fetch_node_manager_states.each do |node_manager, states|
available, unavailable = states.values_at(:available, :unavailable)
available.each do |node_string, latency|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].viewable_by(node_manager, latency)
end
unavailable.each do |node_string|
node = nodes[node_string] ||= node_from(node_string)
snapshots[node].unviewable_by(node_manager)
end
end
snapshots
end
|
[
"def",
"current_node_snapshots",
"nodes",
"=",
"{",
"}",
"snapshots",
"=",
"Hash",
".",
"new",
"{",
"|",
"h",
",",
"k",
"|",
"h",
"[",
"k",
"]",
"=",
"NodeSnapshot",
".",
"new",
"(",
"k",
")",
"}",
"fetch_node_manager_states",
".",
"each",
"do",
"|",
"node_manager",
",",
"states",
"|",
"available",
",",
"unavailable",
"=",
"states",
".",
"values_at",
"(",
":available",
",",
":unavailable",
")",
"available",
".",
"each",
"do",
"|",
"node_string",
",",
"latency",
"|",
"node",
"=",
"nodes",
"[",
"node_string",
"]",
"||=",
"node_from",
"(",
"node_string",
")",
"snapshots",
"[",
"node",
"]",
".",
"viewable_by",
"(",
"node_manager",
",",
"latency",
")",
"end",
"unavailable",
".",
"each",
"do",
"|",
"node_string",
"|",
"node",
"=",
"nodes",
"[",
"node_string",
"]",
"||=",
"node_from",
"(",
"node_string",
")",
"snapshots",
"[",
"node",
"]",
".",
"unviewable_by",
"(",
"node_manager",
")",
"end",
"end",
"snapshots",
"end"
] |
Builds current snapshots of nodes across all running node managers.
@return [Hash<Node, NodeSnapshot>] the snapshots for all nodes
|
[
"Builds",
"current",
"snapshots",
"of",
"nodes",
"across",
"all",
"running",
"node",
"managers",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L561-L577
|
20,380
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.wait_until_master
|
def wait_until_master
logger.info('Waiting to become master Node Manager ...')
with_lock do
@master_manager = true
logger.info('Acquired master Node Manager lock.')
logger.info("Configured node strategy #{@node_strategy.class}")
logger.info("Configured failover strategy #{@failover_strategy.class}")
logger.info("Required Node Managers to make a decision: #{@required_node_managers}")
manage_nodes
end
end
|
ruby
|
def wait_until_master
logger.info('Waiting to become master Node Manager ...')
with_lock do
@master_manager = true
logger.info('Acquired master Node Manager lock.')
logger.info("Configured node strategy #{@node_strategy.class}")
logger.info("Configured failover strategy #{@failover_strategy.class}")
logger.info("Required Node Managers to make a decision: #{@required_node_managers}")
manage_nodes
end
end
|
[
"def",
"wait_until_master",
"logger",
".",
"info",
"(",
"'Waiting to become master Node Manager ...'",
")",
"with_lock",
"do",
"@master_manager",
"=",
"true",
"logger",
".",
"info",
"(",
"'Acquired master Node Manager lock.'",
")",
"logger",
".",
"info",
"(",
"\"Configured node strategy #{@node_strategy.class}\"",
")",
"logger",
".",
"info",
"(",
"\"Configured failover strategy #{@failover_strategy.class}\"",
")",
"logger",
".",
"info",
"(",
"\"Required Node Managers to make a decision: #{@required_node_managers}\"",
")",
"manage_nodes",
"end",
"end"
] |
Waits until this node manager becomes the master.
|
[
"Waits",
"until",
"this",
"node",
"manager",
"becomes",
"the",
"master",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L580-L591
|
20,381
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.manage_nodes
|
def manage_nodes
# Re-discover nodes, since the state of the world may have been changed
# by the time we've become the primary node manager.
discover_nodes
# ensure that slaves are correctly pointing to this master
redirect_slaves_to(@master)
# Periodically update master config state.
while running? && master_manager?
@zk_lock.assert!
sleep(CHECK_INTERVAL)
@lock.synchronize do
snapshots = current_node_snapshots
if ensure_sufficient_node_managers(snapshots)
snapshots.each_key do |node|
update_master_state(node, snapshots)
end
# flush current master state
write_current_redis_nodes
# check if we've exhausted our attempts to promote a master
unless @master
@master_promotion_attempts += 1
raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
end
end
end
end
end
|
ruby
|
def manage_nodes
# Re-discover nodes, since the state of the world may have been changed
# by the time we've become the primary node manager.
discover_nodes
# ensure that slaves are correctly pointing to this master
redirect_slaves_to(@master)
# Periodically update master config state.
while running? && master_manager?
@zk_lock.assert!
sleep(CHECK_INTERVAL)
@lock.synchronize do
snapshots = current_node_snapshots
if ensure_sufficient_node_managers(snapshots)
snapshots.each_key do |node|
update_master_state(node, snapshots)
end
# flush current master state
write_current_redis_nodes
# check if we've exhausted our attempts to promote a master
unless @master
@master_promotion_attempts += 1
raise NoMasterError if @master_promotion_attempts > MAX_PROMOTION_ATTEMPTS
end
end
end
end
end
|
[
"def",
"manage_nodes",
"# Re-discover nodes, since the state of the world may have been changed",
"# by the time we've become the primary node manager.",
"discover_nodes",
"# ensure that slaves are correctly pointing to this master",
"redirect_slaves_to",
"(",
"@master",
")",
"# Periodically update master config state.",
"while",
"running?",
"&&",
"master_manager?",
"@zk_lock",
".",
"assert!",
"sleep",
"(",
"CHECK_INTERVAL",
")",
"@lock",
".",
"synchronize",
"do",
"snapshots",
"=",
"current_node_snapshots",
"if",
"ensure_sufficient_node_managers",
"(",
"snapshots",
")",
"snapshots",
".",
"each_key",
"do",
"|",
"node",
"|",
"update_master_state",
"(",
"node",
",",
"snapshots",
")",
"end",
"# flush current master state",
"write_current_redis_nodes",
"# check if we've exhausted our attempts to promote a master",
"unless",
"@master",
"@master_promotion_attempts",
"+=",
"1",
"raise",
"NoMasterError",
"if",
"@master_promotion_attempts",
">",
"MAX_PROMOTION_ATTEMPTS",
"end",
"end",
"end",
"end",
"end"
] |
Manages the redis nodes by periodically processing snapshots.
|
[
"Manages",
"the",
"redis",
"nodes",
"by",
"periodically",
"processing",
"snapshots",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L594-L625
|
20,382
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.with_lock
|
def with_lock
@zk_lock ||= @zk.locker(current_lock_path)
begin
@zk_lock.lock!(true)
rescue Exception
# handle shutdown case
running? ? raise : return
end
if running?
@zk_lock.assert!
yield
end
ensure
if @zk_lock
begin
@zk_lock.unlock!
rescue => ex
logger.warn("Failed to release lock: #{ex.inspect}")
end
end
end
|
ruby
|
def with_lock
@zk_lock ||= @zk.locker(current_lock_path)
begin
@zk_lock.lock!(true)
rescue Exception
# handle shutdown case
running? ? raise : return
end
if running?
@zk_lock.assert!
yield
end
ensure
if @zk_lock
begin
@zk_lock.unlock!
rescue => ex
logger.warn("Failed to release lock: #{ex.inspect}")
end
end
end
|
[
"def",
"with_lock",
"@zk_lock",
"||=",
"@zk",
".",
"locker",
"(",
"current_lock_path",
")",
"begin",
"@zk_lock",
".",
"lock!",
"(",
"true",
")",
"rescue",
"Exception",
"# handle shutdown case",
"running?",
"?",
"raise",
":",
"return",
"end",
"if",
"running?",
"@zk_lock",
".",
"assert!",
"yield",
"end",
"ensure",
"if",
"@zk_lock",
"begin",
"@zk_lock",
".",
"unlock!",
"rescue",
"=>",
"ex",
"logger",
".",
"warn",
"(",
"\"Failed to release lock: #{ex.inspect}\"",
")",
"end",
"end",
"end"
] |
Executes a block wrapped in a ZK exclusive lock.
|
[
"Executes",
"a",
"block",
"wrapped",
"in",
"a",
"ZK",
"exclusive",
"lock",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L638-L660
|
20,383
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.perform_manual_failover
|
def perform_manual_failover
@lock.synchronize do
return unless running? && @master_manager && @zk_lock
@zk_lock.assert!
new_master = @zk.get(manual_failover_path, :watch => true).first
return unless new_master && new_master.size > 0
logger.info("Received manual failover request for: #{new_master}")
logger.info("Current nodes: #{current_nodes.inspect}")
snapshots = current_node_snapshots
node = if new_master == ManualFailover::ANY_SLAVE
failover_strategy_candidate(snapshots)
else
node_from(new_master)
end
if node
handle_manual_failover(node, snapshots)
else
logger.error('Failed to perform manual failover, no candidate found.')
end
end
rescue => ex
logger.error("Error handling manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end
|
ruby
|
def perform_manual_failover
@lock.synchronize do
return unless running? && @master_manager && @zk_lock
@zk_lock.assert!
new_master = @zk.get(manual_failover_path, :watch => true).first
return unless new_master && new_master.size > 0
logger.info("Received manual failover request for: #{new_master}")
logger.info("Current nodes: #{current_nodes.inspect}")
snapshots = current_node_snapshots
node = if new_master == ManualFailover::ANY_SLAVE
failover_strategy_candidate(snapshots)
else
node_from(new_master)
end
if node
handle_manual_failover(node, snapshots)
else
logger.error('Failed to perform manual failover, no candidate found.')
end
end
rescue => ex
logger.error("Error handling manual failover: #{ex.inspect}")
logger.error(ex.backtrace.join("\n"))
ensure
@zk.stat(manual_failover_path, :watch => true)
end
|
[
"def",
"perform_manual_failover",
"@lock",
".",
"synchronize",
"do",
"return",
"unless",
"running?",
"&&",
"@master_manager",
"&&",
"@zk_lock",
"@zk_lock",
".",
"assert!",
"new_master",
"=",
"@zk",
".",
"get",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
".",
"first",
"return",
"unless",
"new_master",
"&&",
"new_master",
".",
"size",
">",
"0",
"logger",
".",
"info",
"(",
"\"Received manual failover request for: #{new_master}\"",
")",
"logger",
".",
"info",
"(",
"\"Current nodes: #{current_nodes.inspect}\"",
")",
"snapshots",
"=",
"current_node_snapshots",
"node",
"=",
"if",
"new_master",
"==",
"ManualFailover",
"::",
"ANY_SLAVE",
"failover_strategy_candidate",
"(",
"snapshots",
")",
"else",
"node_from",
"(",
"new_master",
")",
"end",
"if",
"node",
"handle_manual_failover",
"(",
"node",
",",
"snapshots",
")",
"else",
"logger",
".",
"error",
"(",
"'Failed to perform manual failover, no candidate found.'",
")",
"end",
"end",
"rescue",
"=>",
"ex",
"logger",
".",
"error",
"(",
"\"Error handling manual failover: #{ex.inspect}\"",
")",
"logger",
".",
"error",
"(",
"ex",
".",
"backtrace",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"ensure",
"@zk",
".",
"stat",
"(",
"manual_failover_path",
",",
":watch",
"=>",
"true",
")",
"end"
] |
Perform a manual failover to a redis node.
|
[
"Perform",
"a",
"manual",
"failover",
"to",
"a",
"redis",
"node",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L663-L690
|
20,384
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.ensure_sufficient_node_managers
|
def ensure_sufficient_node_managers(snapshots)
currently_sufficient = true
snapshots.each do |node, snapshot|
node_managers = snapshot.node_managers
if node_managers.size < @required_node_managers
logger.error("Not enough Node Managers in snapshot for node #{node}. " +
"Required: #{@required_node_managers}, " +
"Available: #{node_managers.size} #{node_managers}")
currently_sufficient = false
end
end
if currently_sufficient && !@sufficient_node_managers
logger.info("Required Node Managers are visible: #{@required_node_managers}")
end
@sufficient_node_managers = currently_sufficient
@sufficient_node_managers
end
|
ruby
|
def ensure_sufficient_node_managers(snapshots)
currently_sufficient = true
snapshots.each do |node, snapshot|
node_managers = snapshot.node_managers
if node_managers.size < @required_node_managers
logger.error("Not enough Node Managers in snapshot for node #{node}. " +
"Required: #{@required_node_managers}, " +
"Available: #{node_managers.size} #{node_managers}")
currently_sufficient = false
end
end
if currently_sufficient && !@sufficient_node_managers
logger.info("Required Node Managers are visible: #{@required_node_managers}")
end
@sufficient_node_managers = currently_sufficient
@sufficient_node_managers
end
|
[
"def",
"ensure_sufficient_node_managers",
"(",
"snapshots",
")",
"currently_sufficient",
"=",
"true",
"snapshots",
".",
"each",
"do",
"|",
"node",
",",
"snapshot",
"|",
"node_managers",
"=",
"snapshot",
".",
"node_managers",
"if",
"node_managers",
".",
"size",
"<",
"@required_node_managers",
"logger",
".",
"error",
"(",
"\"Not enough Node Managers in snapshot for node #{node}. \"",
"+",
"\"Required: #{@required_node_managers}, \"",
"+",
"\"Available: #{node_managers.size} #{node_managers}\"",
")",
"currently_sufficient",
"=",
"false",
"end",
"end",
"if",
"currently_sufficient",
"&&",
"!",
"@sufficient_node_managers",
"logger",
".",
"info",
"(",
"\"Required Node Managers are visible: #{@required_node_managers}\"",
")",
"end",
"@sufficient_node_managers",
"=",
"currently_sufficient",
"@sufficient_node_managers",
"end"
] |
Determines if each snapshot has a sufficient number of node managers.
@param [Hash<Node, Snapshot>] snapshots the current snapshots
@return [Boolean] true if sufficient, false otherwise
|
[
"Determines",
"if",
"each",
"snapshot",
"has",
"a",
"sufficient",
"number",
"of",
"node",
"managers",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L706-L724
|
20,385
|
ryanlecompte/redis_failover
|
lib/redis_failover/node_manager.rb
|
RedisFailover.NodeManager.failover_strategy_candidate
|
def failover_strategy_candidate(snapshots)
# only include nodes that this master Node Manager can see
filtered_snapshots = snapshots.select do |node, snapshot|
snapshot.viewable_by?(manager_id)
end
logger.info('Attempting to find candidate from snapshots:')
logger.info("\n" + filtered_snapshots.values.join("\n"))
@failover_strategy.find_candidate(filtered_snapshots)
end
|
ruby
|
def failover_strategy_candidate(snapshots)
# only include nodes that this master Node Manager can see
filtered_snapshots = snapshots.select do |node, snapshot|
snapshot.viewable_by?(manager_id)
end
logger.info('Attempting to find candidate from snapshots:')
logger.info("\n" + filtered_snapshots.values.join("\n"))
@failover_strategy.find_candidate(filtered_snapshots)
end
|
[
"def",
"failover_strategy_candidate",
"(",
"snapshots",
")",
"# only include nodes that this master Node Manager can see",
"filtered_snapshots",
"=",
"snapshots",
".",
"select",
"do",
"|",
"node",
",",
"snapshot",
"|",
"snapshot",
".",
"viewable_by?",
"(",
"manager_id",
")",
"end",
"logger",
".",
"info",
"(",
"'Attempting to find candidate from snapshots:'",
")",
"logger",
".",
"info",
"(",
"\"\\n\"",
"+",
"filtered_snapshots",
".",
"values",
".",
"join",
"(",
"\"\\n\"",
")",
")",
"@failover_strategy",
".",
"find_candidate",
"(",
"filtered_snapshots",
")",
"end"
] |
Invokes the configured failover strategy.
@param [Hash<Node, NodeSnapshot>] snapshots the node snapshots
@return [Node] a failover candidate
|
[
"Invokes",
"the",
"configured",
"failover",
"strategy",
"."
] |
be1208240b9b817fb0288edc7535e3f445f767cd
|
https://github.com/ryanlecompte/redis_failover/blob/be1208240b9b817fb0288edc7535e3f445f767cd/lib/redis_failover/node_manager.rb#L730-L739
|
20,386
|
larskanis/pkcs11
|
lib/pkcs11/library.rb
|
PKCS11.Library.C_Initialize
|
def C_Initialize(args=nil)
case args
when Hash
pargs = CK_C_INITIALIZE_ARGS.new
args.each{|k,v| pargs.send("#{k}=", v) }
else
pargs = args
end
unwrapped_C_Initialize(pargs)
end
|
ruby
|
def C_Initialize(args=nil)
case args
when Hash
pargs = CK_C_INITIALIZE_ARGS.new
args.each{|k,v| pargs.send("#{k}=", v) }
else
pargs = args
end
unwrapped_C_Initialize(pargs)
end
|
[
"def",
"C_Initialize",
"(",
"args",
"=",
"nil",
")",
"case",
"args",
"when",
"Hash",
"pargs",
"=",
"CK_C_INITIALIZE_ARGS",
".",
"new",
"args",
".",
"each",
"{",
"|",
"k",
",",
"v",
"|",
"pargs",
".",
"send",
"(",
"\"#{k}=\"",
",",
"v",
")",
"}",
"else",
"pargs",
"=",
"args",
"end",
"unwrapped_C_Initialize",
"(",
"pargs",
")",
"end"
] |
Initialize a pkcs11 dynamic library.
@param [Hash, CK_C_INITIALIZE_ARGS] args A Hash or CK_C_INITIALIZE_ARGS instance with load params.
|
[
"Initialize",
"a",
"pkcs11",
"dynamic",
"library",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/library.rb#L49-L58
|
20,387
|
larskanis/pkcs11
|
lib/pkcs11/library.rb
|
PKCS11.Library.C_GetSlotList
|
def C_GetSlotList(tokenPresent=false)
slots = unwrapped_C_GetSlotList(tokenPresent)
slots.map{|slot|
Slot.new self, slot
}
end
|
ruby
|
def C_GetSlotList(tokenPresent=false)
slots = unwrapped_C_GetSlotList(tokenPresent)
slots.map{|slot|
Slot.new self, slot
}
end
|
[
"def",
"C_GetSlotList",
"(",
"tokenPresent",
"=",
"false",
")",
"slots",
"=",
"unwrapped_C_GetSlotList",
"(",
"tokenPresent",
")",
"slots",
".",
"map",
"{",
"|",
"slot",
"|",
"Slot",
".",
"new",
"self",
",",
"slot",
"}",
"end"
] |
Obtain an array of Slot objects in the system.
@param [true, false] tokenPresent indicates whether the list
obtained includes only those slots with a token present (true), or
all slots (false);
@return [Array<Slot>]
|
[
"Obtain",
"an",
"array",
"of",
"Slot",
"objects",
"in",
"the",
"system",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/library.rb#L76-L81
|
20,388
|
larskanis/pkcs11
|
lib/pkcs11/session.rb
|
PKCS11.Session.C_FindObjects
|
def C_FindObjects(max_count)
objs = @pk.C_FindObjects(@sess, max_count)
objs.map{|obj| Object.new @pk, @sess, obj }
end
|
ruby
|
def C_FindObjects(max_count)
objs = @pk.C_FindObjects(@sess, max_count)
objs.map{|obj| Object.new @pk, @sess, obj }
end
|
[
"def",
"C_FindObjects",
"(",
"max_count",
")",
"objs",
"=",
"@pk",
".",
"C_FindObjects",
"(",
"@sess",
",",
"max_count",
")",
"objs",
".",
"map",
"{",
"|",
"obj",
"|",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"}",
"end"
] |
Continues a search for token and session objects that match a template,
obtaining additional object handles.
See {Session#find_objects} for convenience
@return [Array<PKCS11::Object>] Returns an array of Object instances.
|
[
"Continues",
"a",
"search",
"for",
"token",
"and",
"session",
"objects",
"that",
"match",
"a",
"template",
"obtaining",
"additional",
"object",
"handles",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L91-L94
|
20,389
|
larskanis/pkcs11
|
lib/pkcs11/session.rb
|
PKCS11.Session.C_GenerateKey
|
def C_GenerateKey(mechanism, template={})
obj = @pk.C_GenerateKey(@sess, to_mechanism(mechanism), to_attributes(template))
Object.new @pk, @sess, obj
end
|
ruby
|
def C_GenerateKey(mechanism, template={})
obj = @pk.C_GenerateKey(@sess, to_mechanism(mechanism), to_attributes(template))
Object.new @pk, @sess, obj
end
|
[
"def",
"C_GenerateKey",
"(",
"mechanism",
",",
"template",
"=",
"{",
"}",
")",
"obj",
"=",
"@pk",
".",
"C_GenerateKey",
"(",
"@sess",
",",
"to_mechanism",
"(",
"mechanism",
")",
",",
"to_attributes",
"(",
"template",
")",
")",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"end"
] |
Generates a secret key Object or set of domain parameters, creating a new
Object.
@param [Hash, Symbol, Integer, PKCS11::CK_MECHANISM] mechanism used mechanism
@param [Hash] template Attributes of the key to create.
@return [PKCS11::Object] key Object of the new created key.
@example generate 112 bit DES key
key = session.generate_key(:DES2_KEY_GEN,
{:ENCRYPT=>true, :WRAP=>true, :DECRYPT=>true, :UNWRAP=>true})
|
[
"Generates",
"a",
"secret",
"key",
"Object",
"or",
"set",
"of",
"domain",
"parameters",
"creating",
"a",
"new",
"Object",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L653-L656
|
20,390
|
larskanis/pkcs11
|
lib/pkcs11/session.rb
|
PKCS11.Session.C_DeriveKey
|
def C_DeriveKey(mechanism, base_key, template={})
obj = @pk.C_DeriveKey(@sess, to_mechanism(mechanism), base_key, to_attributes(template))
Object.new @pk, @sess, obj
end
|
ruby
|
def C_DeriveKey(mechanism, base_key, template={})
obj = @pk.C_DeriveKey(@sess, to_mechanism(mechanism), base_key, to_attributes(template))
Object.new @pk, @sess, obj
end
|
[
"def",
"C_DeriveKey",
"(",
"mechanism",
",",
"base_key",
",",
"template",
"=",
"{",
"}",
")",
"obj",
"=",
"@pk",
".",
"C_DeriveKey",
"(",
"@sess",
",",
"to_mechanism",
"(",
"mechanism",
")",
",",
"base_key",
",",
"to_attributes",
"(",
"template",
")",
")",
"Object",
".",
"new",
"@pk",
",",
"@sess",
",",
"obj",
"end"
] |
Derives a key from a base key, creating a new key object.
@param [Hash, Symbol, Integer, PKCS11::CK_MECHANISM] mechanism used mechanism
@param [PKCS11::Object] base_key key to derive
@param [Hash] template Attributes of the object to create.
@return [PKCS11::Object] key object of the new created key.
@example Derive a AES key by XORing with some derivation data
deriv_data = "\0"*16
new_key = session.derive_key( {CKM_XOR_BASE_AND_DATA => {:pData => deriv_data}}, secret_key,
:CLASS=>CKO_SECRET_KEY, :KEY_TYPE=>CKK_AES, :VALUE_LEN=>16, :ENCRYPT=>true )
|
[
"Derives",
"a",
"key",
"from",
"a",
"base",
"key",
"creating",
"a",
"new",
"key",
"object",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/session.rb#L718-L721
|
20,391
|
larskanis/pkcs11
|
lib/pkcs11/slot.rb
|
PKCS11.Slot.C_OpenSession
|
def C_OpenSession(flags=CKF_SERIAL_SESSION)
nr = @pk.C_OpenSession(@slot, flags)
sess = Session.new @pk, nr
if block_given?
begin
yield sess
ensure
sess.close
end
else
sess
end
end
|
ruby
|
def C_OpenSession(flags=CKF_SERIAL_SESSION)
nr = @pk.C_OpenSession(@slot, flags)
sess = Session.new @pk, nr
if block_given?
begin
yield sess
ensure
sess.close
end
else
sess
end
end
|
[
"def",
"C_OpenSession",
"(",
"flags",
"=",
"CKF_SERIAL_SESSION",
")",
"nr",
"=",
"@pk",
".",
"C_OpenSession",
"(",
"@slot",
",",
"flags",
")",
"sess",
"=",
"Session",
".",
"new",
"@pk",
",",
"nr",
"if",
"block_given?",
"begin",
"yield",
"sess",
"ensure",
"sess",
".",
"close",
"end",
"else",
"sess",
"end",
"end"
] |
Opens a Session between an application and a token in a particular slot.
@param [Integer] flags indicates the type of session. Default is read-only,
use <tt>CKF_SERIAL_SESSION | CKF_RW_SESSION</tt> for read-write session.
* If called with block, yields the block with the session and closes the session
when the is finished.
* If called without block, returns the session object.
@return [PKCS11::Session]
|
[
"Opens",
"a",
"Session",
"between",
"an",
"application",
"and",
"a",
"token",
"in",
"a",
"particular",
"slot",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/slot.rb#L79-L91
|
20,392
|
larskanis/pkcs11
|
lib/pkcs11/object.rb
|
PKCS11.Object.[]
|
def [](*attributes)
attrs = C_GetAttributeValue( attributes.flatten )
if attrs.length>1 || attributes.first.kind_of?(Array)
attrs.map(&:value)
else
attrs.first.value unless attrs.empty?
end
end
|
ruby
|
def [](*attributes)
attrs = C_GetAttributeValue( attributes.flatten )
if attrs.length>1 || attributes.first.kind_of?(Array)
attrs.map(&:value)
else
attrs.first.value unless attrs.empty?
end
end
|
[
"def",
"[]",
"(",
"*",
"attributes",
")",
"attrs",
"=",
"C_GetAttributeValue",
"(",
"attributes",
".",
"flatten",
")",
"if",
"attrs",
".",
"length",
">",
"1",
"||",
"attributes",
".",
"first",
".",
"kind_of?",
"(",
"Array",
")",
"attrs",
".",
"map",
"(",
":value",
")",
"else",
"attrs",
".",
"first",
".",
"value",
"unless",
"attrs",
".",
"empty?",
"end",
"end"
] |
Get the value of one or several attributes of the object.
@param [String, Symbol, Integer, Array] attribute can be String or Symbol
of the attribute(s) constant or the attribute(s) number as Integer.
@return [String, Integer, Boolean, Array, nil] the attribute value as String,
Integer or true/false depending on the attribute type.
If called with more than one parameter or with an Array, a Array
of attribute values is returned.
Unknown attributes (out of PKCS#11 v2.2) are not converted to adequate
ruby objects but returned as String.
That is true/false will be returned as "\\001" respectively "\\000".
@example
object[:VALUE] # => "\000\000\000\000\000\000\000\000"
object[:MODULUS_BITS] # => 768
object[:MODULUS_BITS, :LABEL] # => [1024, "MyKey"]
See PKCS#11 for attribute definitions.
|
[
"Get",
"the",
"value",
"of",
"one",
"or",
"several",
"attributes",
"of",
"the",
"object",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L48-L55
|
20,393
|
larskanis/pkcs11
|
lib/pkcs11/object.rb
|
PKCS11.Object.[]=
|
def []=(*attributes)
values = attributes.pop
values = [values] unless values.kind_of?(Array)
raise ArgumentError, "different number of attributes to set (#{attributes.length}) and given values (#{values.length})" unless attributes.length == values.length
map = values.each.with_index.inject({}){|s, v| s[attributes[v[1]]] = v[0]; s }
C_SetAttributeValue( map )
end
|
ruby
|
def []=(*attributes)
values = attributes.pop
values = [values] unless values.kind_of?(Array)
raise ArgumentError, "different number of attributes to set (#{attributes.length}) and given values (#{values.length})" unless attributes.length == values.length
map = values.each.with_index.inject({}){|s, v| s[attributes[v[1]]] = v[0]; s }
C_SetAttributeValue( map )
end
|
[
"def",
"[]=",
"(",
"*",
"attributes",
")",
"values",
"=",
"attributes",
".",
"pop",
"values",
"=",
"[",
"values",
"]",
"unless",
"values",
".",
"kind_of?",
"(",
"Array",
")",
"raise",
"ArgumentError",
",",
"\"different number of attributes to set (#{attributes.length}) and given values (#{values.length})\"",
"unless",
"attributes",
".",
"length",
"==",
"values",
".",
"length",
"map",
"=",
"values",
".",
"each",
".",
"with_index",
".",
"inject",
"(",
"{",
"}",
")",
"{",
"|",
"s",
",",
"v",
"|",
"s",
"[",
"attributes",
"[",
"v",
"[",
"1",
"]",
"]",
"]",
"=",
"v",
"[",
"0",
"]",
";",
"s",
"}",
"C_SetAttributeValue",
"(",
"map",
")",
"end"
] |
Modifies the value of one or several attributes of the object.
@param [String, Symbol, Integer] attribute can be String or Symbol of the attribute constant
or the attribute value as Integer.
@param [String, Integer, Boolean, Array, nil] value value(s) the attribute(s) will be set to.
Following value conversations are done from Ruby to C:
true -> 0x01
false -> 0x00
nil -> NULL pointer
Integer-> binary encoded unsigned long
@example
object[:VALUE] = "\000\000\000\000\000\000\000\000"
object[:MODULUS_BITS] = 768
object[:MODULUS_BITS, :LABEL] = 1024, 'MyKey'
See PKCS#11 for attribute definitions.
@return value
|
[
"Modifies",
"the",
"value",
"of",
"one",
"or",
"several",
"attributes",
"of",
"the",
"object",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L76-L82
|
20,394
|
larskanis/pkcs11
|
lib/pkcs11/object.rb
|
PKCS11.Object.C_GetAttributeValue
|
def C_GetAttributeValue(*template)
case template.length
when 0
return @pk.vendor_all_attribute_names.map{|attr|
begin
attributes(@pk.vendor_const_get(attr))
rescue PKCS11::Error
end
}.flatten.compact
when 1
template = template[0]
end
template = to_attributes template
@pk.C_GetAttributeValue(@sess, @obj, template)
end
|
ruby
|
def C_GetAttributeValue(*template)
case template.length
when 0
return @pk.vendor_all_attribute_names.map{|attr|
begin
attributes(@pk.vendor_const_get(attr))
rescue PKCS11::Error
end
}.flatten.compact
when 1
template = template[0]
end
template = to_attributes template
@pk.C_GetAttributeValue(@sess, @obj, template)
end
|
[
"def",
"C_GetAttributeValue",
"(",
"*",
"template",
")",
"case",
"template",
".",
"length",
"when",
"0",
"return",
"@pk",
".",
"vendor_all_attribute_names",
".",
"map",
"{",
"|",
"attr",
"|",
"begin",
"attributes",
"(",
"@pk",
".",
"vendor_const_get",
"(",
"attr",
")",
")",
"rescue",
"PKCS11",
"::",
"Error",
"end",
"}",
".",
"flatten",
".",
"compact",
"when",
"1",
"template",
"=",
"template",
"[",
"0",
"]",
"end",
"template",
"=",
"to_attributes",
"template",
"@pk",
".",
"C_GetAttributeValue",
"(",
"@sess",
",",
"@obj",
",",
"template",
")",
"end"
] |
Obtains the value of one or more attributes of the object in a single call.
@param [Array<String, Symbol, Integer>, Hash, String, Integer] attribute attribute names
whose values should be returned
Without params all known attributes are tried to read from the Object.
This is significant slower then naming the needed attributes and should
be used for debug purposes only.
@return [Array<PKCS11::CK_ATTRIBUTE>] Requested attributes with values.
@example
certificate.attributes :VALUE, :CLASS
=> [#<PKCS11::CK_ATTRIBUTE CKA_VALUE (17) value="0\x82...">, #<PKCS11::CK_ATTRIBUTE CKA_CLASS (0) value=1>]
|
[
"Obtains",
"the",
"value",
"of",
"one",
"or",
"more",
"attributes",
"of",
"the",
"object",
"in",
"a",
"single",
"call",
"."
] |
4f39c54a932face8b3d87c157d8d56469c43c6bc
|
https://github.com/larskanis/pkcs11/blob/4f39c54a932face8b3d87c157d8d56469c43c6bc/lib/pkcs11/object.rb#L109-L123
|
20,395
|
mailin-api/sendinblue-ruby-gem
|
lib/sendinblue.rb
|
Sendinblue.Mailin.get_campaigns_v2
|
def get_campaigns_v2(data)
if data['type'] == "" and data['status'] == "" and data['page'] == "" and data['page_limit'] == ""
return self.get("campaign/detailsv2/","")
else
return self.get("campaign/detailsv2/type/" + data['type'] + "/status/" + data['status'] + "/page/" + data['page'].to_s + "/page_limit/" + data['page_limit'].to_s + "/","")
end
end
|
ruby
|
def get_campaigns_v2(data)
if data['type'] == "" and data['status'] == "" and data['page'] == "" and data['page_limit'] == ""
return self.get("campaign/detailsv2/","")
else
return self.get("campaign/detailsv2/type/" + data['type'] + "/status/" + data['status'] + "/page/" + data['page'].to_s + "/page_limit/" + data['page_limit'].to_s + "/","")
end
end
|
[
"def",
"get_campaigns_v2",
"(",
"data",
")",
"if",
"data",
"[",
"'type'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'status'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'page'",
"]",
"==",
"\"\"",
"and",
"data",
"[",
"'page_limit'",
"]",
"==",
"\"\"",
"return",
"self",
".",
"get",
"(",
"\"campaign/detailsv2/\"",
",",
"\"\"",
")",
"else",
"return",
"self",
".",
"get",
"(",
"\"campaign/detailsv2/type/\"",
"+",
"data",
"[",
"'type'",
"]",
"+",
"\"/status/\"",
"+",
"data",
"[",
"'status'",
"]",
"+",
"\"/page/\"",
"+",
"data",
"[",
"'page'",
"]",
".",
"to_s",
"+",
"\"/page_limit/\"",
"+",
"data",
"[",
"'page_limit'",
"]",
".",
"to_s",
"+",
"\"/\"",
",",
"\"\"",
")",
"end",
"end"
] |
Get all campaigns detail.
@param {Array} data contains php array with key value pair.
@options data {String} type: Type of campaign. Possible values – classic, trigger, sms, template ( case sensitive ) [Optional]
@options data {String} status: Status of campaign. Possible values – draft, sent, archive, queued, suspended, in_process, temp_active, temp_inactive ( case sensitive ) [Optional]
@options data {Integer} page: Maximum number of records per request is 500, if there are more than 500 campaigns then you can use this parameter to get next 500 results [Optional]
@options data {Integer} page_limit: This should be a valid number between 1-500 [Optional]
|
[
"Get",
"all",
"campaigns",
"detail",
"."
] |
670d38921c9893e653fab07dc5b9ecfb86628460
|
https://github.com/mailin-api/sendinblue-ruby-gem/blob/670d38921c9893e653fab07dc5b9ecfb86628460/lib/sendinblue.rb#L169-L175
|
20,396
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_auth_code
|
def authenticate_with_auth_code(authorization_code, redirect_uri)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => authorization_code, :redirect_uri => redirect_uri}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_auth_code(authorization_code, redirect_uri)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'authorization_code', :client_id => api_key, :client_secret => api_secret, :code => authorization_code, :redirect_uri => redirect_uri}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_auth_code",
"(",
"authorization_code",
",",
"redirect_uri",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'authorization_code'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":code",
"=>",
"authorization_code",
",",
":redirect_uri",
"=>",
"redirect_uri",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
sign in as a user using the server side flow
|
[
"sign",
"in",
"as",
"a",
"user",
"using",
"the",
"server",
"side",
"flow"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L43-L53
|
20,397
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_credentials
|
def authenticate_with_credentials(username, password, offering_id=nil)
body = {:grant_type => 'password', :client_id => api_key, :client_secret => api_secret, :username => username, :password => password}
body[:offering_id] = offering_id if offering_id.present?
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = body
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_credentials(username, password, offering_id=nil)
body = {:grant_type => 'password', :client_id => api_key, :client_secret => api_secret, :username => username, :password => password}
body[:offering_id] = offering_id if offering_id.present?
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = body
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_credentials",
"(",
"username",
",",
"password",
",",
"offering_id",
"=",
"nil",
")",
"body",
"=",
"{",
":grant_type",
"=>",
"'password'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":username",
"=>",
"username",
",",
":password",
"=>",
"password",
"}",
"body",
"[",
":offering_id",
"]",
"=",
"offering_id",
"if",
"offering_id",
".",
"present?",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"body",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
Sign in as a user using credentials
|
[
"Sign",
"in",
"as",
"a",
"user",
"using",
"credentials"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L56-L69
|
20,398
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_app
|
def authenticate_with_app(app_id, app_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'app', :client_id => api_key, :client_secret => api_secret, :app_id => app_id, :app_token => app_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_app(app_id, app_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'app', :client_id => api_key, :client_secret => api_secret, :app_id => app_id, :app_token => app_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_app",
"(",
"app_id",
",",
"app_token",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'app'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":app_id",
"=>",
"app_id",
",",
":app_token",
"=>",
"app_token",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
Sign in as an app
|
[
"Sign",
"in",
"as",
"an",
"app"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L72-L82
|
20,399
|
podio/podio-rb
|
lib/podio/client.rb
|
Podio.Client.authenticate_with_transfer_token
|
def authenticate_with_transfer_token(transfer_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'transfer_token', :client_id => api_key, :client_secret => api_secret, :transfer_token => transfer_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
ruby
|
def authenticate_with_transfer_token(transfer_token)
response = @oauth_connection.post do |req|
req.url '/oauth/token'
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
req.body = {:grant_type => 'transfer_token', :client_id => api_key, :client_secret => api_secret, :transfer_token => transfer_token}
end
@oauth_token = OAuthToken.new(response.body)
configure_oauth
@oauth_token
end
|
[
"def",
"authenticate_with_transfer_token",
"(",
"transfer_token",
")",
"response",
"=",
"@oauth_connection",
".",
"post",
"do",
"|",
"req",
"|",
"req",
".",
"url",
"'/oauth/token'",
"req",
".",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/x-www-form-urlencoded'",
"req",
".",
"body",
"=",
"{",
":grant_type",
"=>",
"'transfer_token'",
",",
":client_id",
"=>",
"api_key",
",",
":client_secret",
"=>",
"api_secret",
",",
":transfer_token",
"=>",
"transfer_token",
"}",
"end",
"@oauth_token",
"=",
"OAuthToken",
".",
"new",
"(",
"response",
".",
"body",
")",
"configure_oauth",
"@oauth_token",
"end"
] |
Sign in with an transfer token, only available for Podio
|
[
"Sign",
"in",
"with",
"an",
"transfer",
"token",
"only",
"available",
"for",
"Podio"
] |
66137e685a494bc188ced542ae8e872d14b90a74
|
https://github.com/podio/podio-rb/blob/66137e685a494bc188ced542ae8e872d14b90a74/lib/podio/client.rb#L85-L95
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.