Method: Cisco::Node#config_get

Defined in:
lib/cisco_node_utils/node.rb

#config_get(feature, name, *args) ⇒ String, ...

Convenience wrapper for show(command, :structured). Uses CommandReference to look up the given show command and key of interest, executes that command, and returns the value corresponding to that key.

Examples:

config_get(“show_version”, “system_image”)

config_get(“ospf”, “router_id”,

{name: "green", vrf: "one"})

Parameters:

  • feature (String)
  • name (String)

Returns:

  • (String, Hash, Array)

Raises:

  • (IndexError)

    if the given (feature, name) pair is not in the CommandReference data or if the data doesn’t have values defined for the ‘config_get’ and (optional) ‘config_get_token’ fields.

  • (Cisco::CliError)

    if the given command is rejected by the device.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cisco_node_utils/node.rb', line 69

def config_get(feature, name, *args)
  fail 'lazy_connect specified but did not request connect' unless @cmd_ref
  ref = @cmd_ref.lookup(feature, name)

  return ref.default_value if ref.default_only?

  begin
    token = ref.config_get_token(*args)
  rescue IndexError
    # IndexError: no entry for config_get_token
    token = nil
  end
  if token.nil?
    # Just get the whole output
    return massage(show(ref.config_get, :structured), ref)
  elsif token[0].kind_of?(Regexp)
    return massage(Cisco.find_ascii(show(ref.config_get, :ascii),
                                    token[-1],
                                    *token[0..-2]), ref)
  else
    return massage(
      config_get_handle_structured(token,
                                   show(ref.config_get, :structured)),
      ref)
  end
end