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 —————————————————————.
-
#install_software!(opts = {}) ⇒ Object
————————————————————— install_software! - request system software add …
-
#memory ⇒ Object
————————————————————— memory - show system memory —————————————————————.
- #ping(opts = {}) ⇒ Object
-
#reboot!(opts = {}) ⇒ Object
————————————————————— reboot! - request system reboot (no confirm!!) —————————————————————.
-
#rollback_software! ⇒ Object
————————————————————— rollback_software! - request system software rollback —————————————————————.
-
#shutdown!(opts = {}) ⇒ Object
————————————————————— shutdown! - request system power-off (no confirm!!) —————————————————————.
-
#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 —————————————————————.
-
#validate_software?(package) ⇒ Boolean
————————————————————— validate_software? - request system software validate …
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, #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
127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/junos-ez/utils/re.rb', line 127 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 |
#install_software!(opts = {}) ⇒ Object
install_software! - request system software add …
198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/junos-ez/utils/re.rb', line 198 def install_software!( 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] 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 |
#memory ⇒ Object
memory - show system memory
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/junos-ez/utils/re.rb', line 143 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(opts = {}) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'lib/junos-ez/utils/re.rb', line 247 def ping( opts = {} ) = [ :host, :do_not_fragment, :inet, :inet6, :strict, :count, :interface, :interval, :mac_address, :routing_instance, :size, :source, :tos, :ttl, :wait ] args = {} 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!!)
226 227 228 229 |
# File 'lib/junos-ez/utils/re.rb', line 226 def reboot!( opts = {} ) got = @ndev.rpc.request_reboot got.xpath('request-reboot-status').text.strip end |
#rollback_software! ⇒ Object
rollback_software! - request system software rollback
217 218 219 220 |
# File 'lib/junos-ez/utils/re.rb', line 217 def rollback_software! got = @ndev.rpc.request_package_rollback got.text.strip end |
#shutdown!(opts = {}) ⇒ Object
shutdown! - request system power-off (no confirm!!)
235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/junos-ez/utils/re.rb', line 235 def shutdown!( opts = {} ) ## 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 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 |
#status(opts = {}) ⇒ Object
status - show chassis routing-engine information
44 45 46 47 48 49 50 51 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 |
# File 'lib/junos-ez/utils/re.rb', line 44 def status( opts = {} ) got = @ndev.rpc.get_route_engine_information status_h = {} got.xpath('//route-engine').each do |re| re_h = {} slot_id = re.xpath('slot').text.to_i 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
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/junos-ez/utils/re.rb', line 111 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
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/junos-ez/utils/re.rb', line 90 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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/junos-ez/utils/re.rb', line 164 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[:command] = user.xpath('command').text.strip end users_a end |
#validate_software?(package) ⇒ Boolean
validate_software? - request system software validate …
185 186 187 188 189 190 191 192 |
# File 'lib/junos-ez/utils/re.rb', line 185 def validate_software?( 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 |