Class: Cisco::Node
- Inherits:
-
Object
- Object
- Cisco::Node
- Defined in:
- lib/util/node.rb
Overview
class Cisco::Node Pseudo-singleton representing the network node (switch/router) that is running this code. The singleton is lazily instantiated, meaning that it doesn’t exist until some client requests it (with Node.instance(…))
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Here and below are implementation details and private APIs that most providers shouldn’t need to know about or use.
Class Method Summary collapse
-
.instance(client_class = nil) ⇒ Object
Return a node instance that wraps a client of the specified class.
- .instance_exists(client_class) ⇒ Object
Instance Method Summary collapse
-
#boot ⇒ String
Such as “bootflash:///n3000-uk9-kickstart.6.0.2.U5.0.941.bin”.
-
#delete_yang(yang) ⇒ Object
Delete the specified JSON YANG config from the device.
-
#domain_name ⇒ String
Such as “example.com”.
-
#get(**kwargs) ⇒ Object
Send a show command to the device.
-
#get_netconf(xpath) ⇒ Object
Retrieve config from the device for the specified path using netconf.
-
#get_yang(yang_path) ⇒ Object
Retrieve JSON YANG config from the device for the specified path.
-
#get_yang_oper(yang_path) ⇒ Object
Retrieve JSON YANG operational data for the specified path.
-
#host_name ⇒ String
Such as “bxb-oa-n3k-7”.
-
#initialize(client_class) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
-
#last_reset_reason ⇒ String
Such as “Reset Requested by CLI command reload”.
-
#last_reset_time ⇒ String
Timestamp of last reset time.
-
#merge_netconf(config) ⇒ Object
Merge the specified config with the running config on the device.
-
#merge_yang(yang) ⇒ Object
Merge the specified JSON YANG config with the running config on the device.
-
#os ⇒ String
Such as “Cisco Nexus Operating System (NX-OS) Software”.
-
#os_version ⇒ String
Such as “6.0(2)U5(1) [build 6.0(2)U5(0.941)]”.
-
#product_description ⇒ String
Such as “Nexus 3048 Chassis”.
-
#product_id ⇒ String
Such as “N3K-C3048TP-1GE”.
-
#product_serial_number ⇒ String
Such as “FOC1722R0ET”.
-
#product_version_id ⇒ String
Such as “V01”.
-
#replace_netconf(config) ⇒ Object
Replace the running config on the device with the specified config using netconf client.
-
#replace_yang(yang) ⇒ Object
Replace the running config on the device with the specified JSON YANG config.
-
#set(**kwargs) ⇒ Object
Send a config command to the device.
-
#system ⇒ String
Such as “bootflash:///n3000-uk9.6.0.2.U5.0.941.bin”.
-
#system_cpu_utilization ⇒ Float
Combined user/kernel CPU utilization.
-
#system_uptime ⇒ Integer
System uptime, in seconds.
- #to_s ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Here and below are implementation details and private APIs that most providers shouldn’t need to know about or use.
36 37 38 |
# File 'lib/util/node.rb', line 36 def client @client end |
Class Method Details
.instance(client_class = nil) ⇒ Object
Return a node instance that wraps a client of the specified class.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/util/node.rb', line 39 def self.instance(client_class=nil) return @instance_hash[client_class] ||= new(client_class) unless client_class.nil? # just return one of the cached instances return @instance_hash[hash.keys[0]] unless @instance_hash.empty? # no nodes currently cached, so create one debug 'Attempting to create a client (type not specified)...' env_names = Cisco::Util::Environment.environment_names Cisco::Client.clients.each do |c| client_env_name = Cisco::Client.environment_name(c) if env_names.include?(client_env_name) debug "Environment configuration found for client #{c}" return instance(c) end end error 'No clients configured' end |
.instance_exists(client_class) ⇒ Object
60 61 62 |
# File 'lib/util/node.rb', line 60 def self.instance_exists(client_class) !@instance_hash[client_class].nil? end |
Instance Method Details
#boot ⇒ String
Returns such as “bootflash:///n3000-uk9-kickstart.6.0.2.U5.0.941.bin”.
195 196 197 |
# File 'lib/util/node.rb', line 195 def boot @client.get_boot end |
#delete_yang(yang) ⇒ Object
Delete the specified JSON YANG config from the device.
119 120 121 |
# File 'lib/util/node.rb', line 119 def delete_yang(yang) @client.set(values: yang, mode: :delete_config) end |
#domain_name ⇒ String
Returns such as “example.com”.
169 170 171 |
# File 'lib/util/node.rb', line 169 def domain_name @client.domain_name end |
#get(**kwargs) ⇒ Object
Send a show command to the device.
84 85 86 |
# File 'lib/util/node.rb', line 84 def get(**kwargs) @client.get(**kwargs) end |
#get_netconf(xpath) ⇒ Object
Retrieve config from the device for the specified path using netconf.
101 102 103 |
# File 'lib/util/node.rb', line 101 def get_netconf(xpath) @client.get(command: xpath) end |
#get_yang(yang_path) ⇒ Object
Retrieve JSON YANG config from the device for the specified path.
124 125 126 |
# File 'lib/util/node.rb', line 124 def get_yang(yang_path) @client.get(command: yang_path) end |
#get_yang_oper(yang_path) ⇒ Object
Retrieve JSON YANG operational data for the specified path.
129 130 131 |
# File 'lib/util/node.rb', line 129 def get_yang_oper(yang_path) @client.get(command: yang_path, mode: :get_oper) end |
#host_name ⇒ String
Returns such as “bxb-oa-n3k-7”.
164 165 166 |
# File 'lib/util/node.rb', line 164 def host_name @client.host_name end |
#inspect ⇒ Object
72 73 74 |
# File 'lib/util/node.rb', line 72 def inspect "Node: client:'#{client.inspect}'" end |
#last_reset_reason ⇒ String
Returns such as “Reset Requested by CLI command reload”.
184 185 186 |
# File 'lib/util/node.rb', line 184 def last_reset_reason @client.get_last_reset_reason end |
#last_reset_time ⇒ String
Returns timestamp of last reset time.
179 180 181 |
# File 'lib/util/node.rb', line 179 def last_reset_time @client.get_last_reset_time end |
#merge_netconf(config) ⇒ Object
Merge the specified config with the running config on the device. using netconf
90 91 92 |
# File 'lib/util/node.rb', line 90 def merge_netconf(config) @client.set(values: config, mode: :merge) end |
#merge_yang(yang) ⇒ Object
Merge the specified JSON YANG config with the running config on the device.
107 108 109 |
# File 'lib/util/node.rb', line 107 def merge_yang(yang) @client.set(values: yang, mode: :merge_config) end |
#os ⇒ String
Returns such as “Cisco Nexus Operating System (NX-OS) Software”.
134 135 136 |
# File 'lib/util/node.rb', line 134 def os @client.os end |
#os_version ⇒ String
Returns such as “6.0(2)U5(1) [build 6.0(2)U5(0.941)]”.
139 140 141 |
# File 'lib/util/node.rb', line 139 def os_version @client.os_version end |
#product_description ⇒ String
Returns such as “Nexus 3048 Chassis”.
144 145 146 |
# File 'lib/util/node.rb', line 144 def product_description @client.product_description end |
#product_id ⇒ String
Returns such as “N3K-C3048TP-1GE”.
149 150 151 |
# File 'lib/util/node.rb', line 149 def product_id @client.product_id end |
#product_serial_number ⇒ String
Returns such as “FOC1722R0ET”.
159 160 161 |
# File 'lib/util/node.rb', line 159 def product_serial_number @client.product_serial_number end |
#product_version_id ⇒ String
Returns such as “V01”.
154 155 156 |
# File 'lib/util/node.rb', line 154 def product_version_id @client.product_version_id end |
#replace_netconf(config) ⇒ Object
Replace the running config on the device with the specified config using netconf client.
96 97 98 |
# File 'lib/util/node.rb', line 96 def replace_netconf(config) @client.set(values: config, mode: :replace) end |
#replace_yang(yang) ⇒ Object
Replace the running config on the device with the specified JSON YANG config.
113 114 115 116 |
# File 'lib/util/node.rb', line 113 def replace_yang(yang) @client.set(values: yang, mode: :replace_config) end |
#set(**kwargs) ⇒ Object
Send a config command to the device.
78 79 80 |
# File 'lib/util/node.rb', line 78 def set(**kwargs) @client.set(**kwargs) end |
#system ⇒ String
Returns such as “bootflash:///n3000-uk9.6.0.2.U5.0.941.bin”.
201 202 203 |
# File 'lib/util/node.rb', line 201 def system @client.system end |
#system_cpu_utilization ⇒ Float
Returns combined user/kernel CPU utilization.
189 190 191 |
# File 'lib/util/node.rb', line 189 def system_cpu_utilization @client.system_cpu_utilization end |
#system_uptime ⇒ Integer
Returns System uptime, in seconds.
174 175 176 |
# File 'lib/util/node.rb', line 174 def system_uptime @client.system_uptime end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/util/node.rb', line 68 def to_s client.to_s end |