Class: NetdevComware::Device
- Inherits:
-
Object
- Object
- NetdevComware::Device
- Defined in:
- lib/puppet/provider/comware/comware_device.rb
Instance Attribute Summary collapse
-
#netconf ⇒ Object
Returns the value of attribute netconf.
-
#ready ⇒ Object
Returns the value of attribute ready.
Instance Method Summary collapse
- #edit_config(jcfg_obj) ⇒ Object
-
#initialize(args = {}) ⇒ Device
constructor
A new instance of Device.
Constructor Details
#initialize(args = {}) ⇒ Device
Returns a new instance of Device.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/puppet/provider/comware/comware_device.rb', line 7 def initialize(args={}) @ready = true @edits_count = 0 begin @netconf = Netconf::SSH.new(args) @netconf.open rescue @ready = false end end |
Instance Attribute Details
#netconf ⇒ Object
Returns the value of attribute netconf.
5 6 7 |
# File 'lib/puppet/provider/comware/comware_device.rb', line 5 def netconf @netconf end |
#ready ⇒ Object
Returns the value of attribute ready.
5 6 7 |
# File 'lib/puppet/provider/comware/comware_device.rb', line 5 def ready @ready end |
Instance Method Details
#edit_config(jcfg_obj) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/provider/comware/comware_device.rb', line 20 def edit_config( jcfg_obj ) edits = Netconf::ComwareConfig.new(:TOP) edits << jcfg_obj load_config = edits.doc.root NetdevComware::Log.debug load_config.to_xml, :tags => [:config, :changes] # if there is an RPC error (syntax error), it will generate an exception, and # we want that to "bubble-up" to the calling context so don't # rescue it here. begin @edits_count += 1 @netconf.rpc.edit_config( load_config, :target => 'running' ) rescue Netconf::RpcError => e # the load_configuration may yeield rpc-errors that are in fact not errors, # but merely warnings. Check for that here. if rpc_errs = e.rsp.xpath('//rpc-error') # ignore warnings ... all_count = rpc_errs.count warn_count = rpc_errs.xpath('error-severity').select{|err| err.text == 'warning'}.count if all_count - warn_count > 0 @edits_count -= 1 NetdevComware::Log.err "ERROR: load-configuration\n" + e.rsp.to_xml, :tags => [:config, :fail] end end end # rescue block end |