Class: Junos::Ez::RE::Provider
- Inherits:
-
Provider::Parent
- Object
- Provider::Parent
- Junos::Ez::RE::Provider
- Defined in:
- lib/junos-ez/utils/re.rb,
lib/junos-ez/utils/re.rb
Overview
PRIVATE METHODS
Instance Attribute Summary
Attributes inherited from Provider::Parent
#catalog, #has, #list, #name, #ndev, #parent, #properties, #providers, #should
Instance Method Summary collapse
-
#chassis_alarms ⇒ Object
————————————————————— chassis_alarms - show chassis alarms —————————————————————.
-
#license_install!(opts = {}) ⇒ Object
—————————————————————- add a license .
-
#license_rm!(license_id) ⇒ Object
—————————————————————- remove a license .
-
#license_save(opts = {}) ⇒ Object
—————————————————————- save licenses (plr!) to a file —————————————————————-.
-
#licenses(opts = {}) ⇒ Object
—————————————————————- - retrieve Hash of license information.
-
#memory ⇒ Object
————————————————————— memory - show system memory —————————————————————.
- #ping(host, opts = {}) ⇒ Object
-
#reboot!(opts = {}) ⇒ Object
————————————————————— reboot! - request system reboot (no confirm!!) —————————————————————.
-
#shutdown!(opts = {}) ⇒ Object
————————————————————— shutdown! - request system power-off (no confirm!!) —————————————————————.
- #software_images ⇒ Object
-
#software_install!(opts = {}) ⇒ Object
————————————————————— software_install! - request system software add …
-
#software_rollback! ⇒ Object
————————————————————— software_rollback! - request system software rollback —————————————————————.
-
#software_validate?(package) ⇒ Boolean
————————————————————— software_validate? - request system software validate …
-
#status(opts = {}) ⇒ Object
————————————————————— status - show chassis routing-engine information —————————————————————.
-
#system_alarms ⇒ Object
————————————————————— system_alarms - show system alarms —————————————————————.
-
#uptime ⇒ Object
————————————————————— uptime - show system uptime information —————————————————————.
-
#users ⇒ Object
————————————————————— users - show system users —————————————————————.
Methods inherited from Provider::Parent
#[], #[]=, #activate!, #active?, #catalog!, #create, #create!, #create_from_hash!, #create_from_yaml!, #deactivate!, #delete!, #each, #exists?, #init_has, #initialize, #is_new?, #is_provider?, #list!, #name_decorated, #need_write?, #read!, #rename!, #reorder!, #select, #to_h, #to_h_expanded, #to_yaml, #with, #write!, #xml_at_edit, #xml_at_top, #xml_build_change, #xml_change__active, #xml_change__exist, #xml_change_admin, #xml_change_description, #xml_config_read!, #xml_element_newname, #xml_get_has_xml, #xml_on_create, #xml_on_delete
Constructor Details
This class inherits a constructor from Junos::Ez::Provider::Parent
Instance Method Details
#chassis_alarms ⇒ Object
chassis_alarms - show chassis alarms
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/junos-ez/utils/re.rb', line 135 def chassis_alarms got = @ndev.rpc.get_alarm_information alarms_a = [] got.xpath('alarm-detail').each do |alarm| alarm_h = {} _alarm_info_to_h( alarm, alarm_h ) alarms_a << alarm_h end return nil if alarms_a.empty? alarms_a end |
#license_install!(opts = {}) ⇒ Object
add a license
— returns — true - key added OK String - error message otherwise
— options — :key => String
The key text
:filename => String
Path to licence-file on server
416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/junos-ez/utils/re.rb', line 416 def license_install!( opts = {} ) args = {} if opts[:key] args[:key_data] = opts[:key] elsif opts[:filename] args[:key_data] = File.read(opts[:filename]).strip end got = @ndev.rpc.request_license_add( args ) success = got.xpath('add-success')[0] return true if success got.xpath('//message').text.strip end |
#license_rm!(license_id) ⇒ Object
remove a license
license_id is the String license-id or the special name :all
435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/junos-ez/utils/re.rb', line 435 def license_rm!( license_id ) args = {} if license_id == :all args[:all] = true else args[:license_identifier] = license_id end got = @ndev.rpc.request_license_delete( args ) ### @@@ need to test return cases ... for now, just return ### the 'got' XML got end |
#license_save(opts = {}) ⇒ Object
save licenses (plr!) to a file
452 453 454 |
# File 'lib/junos-ez/utils/re.rb', line 452 def license_save( opts = {} ) raise StandardError, "not implemented yet" end |
#licenses(opts = {}) ⇒ Object
-
retrieve Hash of license information.
By default this will provide the license installed information.
— returns —
-
Hash of data if there are licenses
-
nil if no licenses
— options — :keys => true
Will include the key-text for the license
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/junos-ez/utils/re.rb', line 353 def licenses( opts = {} ) got = @ndev.rpc.get_license_summary_information licenses = got.xpath('license-information/license') return nil if licenses.empty? ret_h = {} licenses.each do |lic| lic_h = {} ret_h[lic.xpath('name').text.strip] = lic_h lic_h[:state] = lic.xpath('license-state').text.strip lic_h[:version] = lic.xpath('license-version').text.strip lic_h[:serialnumber] = lic.xpath('software-sn').text.strip lic_h[:customer] = lic.xpath('customer-reference').text.strip features = lic.xpath('feature-block/feature') unless features.empty? feats_h = {} lic_h[:features] = feats_h features.each do |feat| feat_h = {} feats_h[feat.xpath('name').text.strip] = feat_h feat_h[:description] = feat.xpath('description').text.strip v_info = feat.xpath('validity-information')[0] case v_info.xpath('validity-type').text.strip when 'date-based' feat_h[:date_start] = v_info.xpath('start-date').text.strip feat_h[:date_end] = v_info.xpath('end-date').text.strip end end # each features end # if features end # each license ## now check to see if the :keys have been requested. if so ## then get that data, and store back into the return Hash. if opts[:keys] got = @ndev.rpc.get_license_key_information got.xpath('license-key').each do |key| name = key.xpath('name').text.strip ret_h[name][:key] = key.xpath('key-data').text end end ret_h end |
#memory ⇒ Object
memory - show system memory
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/junos-ez/utils/re.rb', line 151 def memory got = @ndev.rpc.get_system_memory_information ret_h = {} unless (n_re = got.xpath('multi-routing-engine-item')).empty? n_re.each do |this_re| as_xml = this_re.xpath('system-memory-information')[0] re_name = this_re.xpath('re-name').text.strip ret_h[re_name] = {} _system_memory_to_h( as_xml, ret_h[re_name] ) end else ret_h['re0'] = {} _system_memory_to_h( got, ret_h['re0'] ) end ret_h end |
#ping(host, opts = {}) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/junos-ez/utils/re.rb', line 304 def ping( host, opts = {} ) = [ :do_not_fragment, :inet, :inet6, :strict, :count, :interface, :interval, :mac_address, :routing_instance, :size, :source, :tos, :ttl, :wait ] args = {:host => host} opts.each do |k,v| if .include? k args[k] = v else raise ArgumentError, "unrecognized option #{k}" end end args[:count] ||= 1 got = @ndev.rpc.ping( args ) return true if got.xpath('ping-success')[0] # if the caller privded a 'failure block' then call that now, # otherwise, just return false return (block_given?) ? yield(got) : false end |
#reboot!(opts = {}) ⇒ Object
reboot! - request system reboot (no confirm!!)
265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/junos-ez/utils/re.rb', line 265 def reboot!( opts = {} ) = [:in, :at] args = {} opts.each do |k,v| if .include? k args[k] = v else raise ArgumentError, "unrecognized option #{k}" end end got = @ndev.rpc.request_reboot( args ) got.xpath('request-reboot-status').text.strip end |
#shutdown!(opts = {}) ⇒ Object
shutdown! - request system power-off (no confirm!!)
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/junos-ez/utils/re.rb', line 283 def shutdown!( opts = {} ) = [:in, :at] args = {} opts.each do |k,v| if .include? k args[k] = v else raise ArgumentError, "unrecognized option #{k}" end end ## some Junos devices will throw an RPC error exception which is really ## a warning, and some do not. So we need to trap that here. begin got = @ndev.rpc.request_power_off( args ) rescue => e retmsg = e.rsp.xpath('//error-message').text.strip + "\n" return retmsg + e.rsp.xpath('//request-reboot-status').text.strip end got.xpath('//request-reboot-status').text.strip end |
#software_images ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/junos-ez/utils/re.rb', line 238 def software_images ls_pkgs = @ndev.rpc.file_list(:path=>'/packages') symlink = ls_pkgs.xpath('//file-symlink-target')[0] if symlink ls_pkgs = @ndev.rpc.file_list(:path => symlink.text.strip) end junos_symlink = ls_pkgs.xpath('//file-information[normalize-space(file-name) = "junos"]')[0] junos_old_symlink = ls_pkgs.xpath('//file-information[normalize-space(file-name) = "junos.old"]')[0] ret_h = {} ret_h[:rollback] = (junos_old_symlink) ? junos_old_symlink.xpath('file-symlink-target').text.strip : nil ret_h[:current] = (junos_symlink) ? junos_symlink.xpath('file-symlink-target').text.strip : ret_h[:rollback] ret_h end |
#software_install!(opts = {}) ⇒ Object
software_install! - request system software add …
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/junos-ez/utils/re.rb', line 213 def software_install!( opts = {} ) raise ArgumentError "missing :package" unless opts[:package] args = { :package_name => opts[:package] } args[:no_validate] = true if opts[:no_validate] args[:unlink] = true if opts[:unlink] args[:reboot] = true if opts[:reboot] got = @ndev.rpc.request_package_add( args ).parent errcode = got.xpath('package-result').text.to_i return true if errcode == 0 # otherwise return the output error message got.xpath('output').text.strip end |
#software_rollback! ⇒ Object
software_rollback! - request system software rollback
233 234 235 236 |
# File 'lib/junos-ez/utils/re.rb', line 233 def software_rollback! got = @ndev.rpc.request_package_rollback got.text.strip end |
#software_validate?(package) ⇒ Boolean
software_validate? - request system software validate …
200 201 202 203 204 205 206 207 |
# File 'lib/junos-ez/utils/re.rb', line 200 def software_validate?( package ) got = @ndev.rpc.request_package_validate(:package_name => package).parent errcode = got.xpath('package-result').text.to_i return true if errcode == 0 # otherwise return the output error message got.xpath('output').text.strip end |
#status(opts = {}) ⇒ Object
status - show chassis routing-engine information
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/junos-ez/utils/re.rb', line 52 def status( opts = {} ) got = @ndev.rpc.get_route_engine_information status_h = {} got.xpath('//route-engine').each do |re| re_h = {} slot_id = "re" + re.xpath('slot').text status_h[slot_id] = re_h re_h[:model] = re.xpath('model').text.strip re_h[:serialnumber] = re.xpath('serial-number').text.strip xml_when_item(re.xpath('mastership-state')){|i| re_h[:mastership] = i.text.strip} re_h[:temperature] = { :system => re.xpath('temperature').text.strip, :cpu => re.xpath('cpu-temperature').text.strip } re_h[:memory] = { :total_size => re.xpath('memory-dram-size').text.to_i, :buffer_util => re.xpath('memory-buffer-itilization').text.to_i } re_h[:cpu_util] = { :user => re.xpath('cpu-user').text.to_i, :background => re.xpath('cpu-background').text.to_i, :system => re.xpath('cpu-system').text.to_i, :interrupt => re.xpath('cpu-interrupt').text.to_i, :idle => re.xpath('cpu-idle').text.to_i, } re_h[:uptime] = { :at => re.xpath('start-time').text.strip, :ago => re.xpath('up-time').text.strip, :reboot_reason => re.xpath('last-reboot-reason').text.strip } re_h[:load_avg] = [ re.xpath('load-average-one').text.to_f, re.xpath('load-average-five').text.to_f, re.xpath('load-average-fifteen').text.to_f ] end status_h end |
#system_alarms ⇒ Object
system_alarms - show system alarms
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/junos-ez/utils/re.rb', line 119 def system_alarms got = @ndev.rpc.get_system_alarm_information alarms_a = [] got.xpath('alarm-detail').each do |alarm| alarm_h = {} _alarm_info_to_h( alarm, alarm_h ) alarms_a << alarm_h end return nil if alarms_a.empty? alarms_a end |
#uptime ⇒ Object
uptime - show system uptime information
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/junos-ez/utils/re.rb', line 98 def uptime up_h = {} got = @ndev.rpc.get_system_uptime_information unless (n_re = got.xpath('multi-routing-engine-item')).empty? n_re.each do |this_re| as_xml = this_re.xpath('system-uptime-information') re_name = this_re.xpath('re-name').text.strip up_h[re_name] = {} _uptime_to_h( as_xml, up_h[re_name] ) end else up_h['re0'] = {} _uptime_to_h( got, up_h['re0'] ) end up_h end |
#users ⇒ Object
users - show system users
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/junos-ez/utils/re.rb', line 172 def users got = @ndev.rpc.get_system_users_information users_a = [] got.xpath('uptime-information/user-table/user-entry').each do |user| user_h = {} users_a << user_h user_h[:name] = user.xpath('user').text.strip user_h[:tty] = user.xpath('tty').text.strip user_h[:from] = user.xpath('from').text.strip user_h[:login_time] = user.xpath('login-time').text.strip user_h[:idle_time] = user.xpath('idel-time').text.strip user_h[:idle_time] = nil if user_h[:idle_time].empty? user_h[:command] = user.xpath('command').text.strip end users_a end |