Class: Puppet::NetDev::CE::CarApi
- Defined in:
- lib/puppet/provider/ce/api/car/car_api.rb
Instance Method Summary collapse
- #create_car(resource) ⇒ Object
- #delete_car(resource) ⇒ Object
- #get_car ⇒ Object
-
#initialize ⇒ CarApi
constructor
A new instance of CarApi.
- #set_car(resource) ⇒ Object
Constructor Details
permalink #initialize ⇒ CarApi
Returns a new instance of CarApi.
22 23 24 |
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 22 def initialize super() end |
Instance Method Details
permalink #create_car(resource) ⇒ Object
[View source]
99 100 101 102 103 |
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 99 def create_car(resource) session = Puppet::NetDev::CE::Device.session create_car_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl operation="create"><carTmplName>' + (resource[:name]).to_s + '</carTmplName><cir>' + (resource[:speed]).to_s + '</cir><pir></pir><cbs></cbs><pbs></pbs></qosIfCarTmpl></qosIfCarTmpls></qos></config></edit-config></rpc>' session.rpc.do_config(create_car_xml) end |
permalink #delete_car(resource) ⇒ Object
[View source]
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 105 def delete_car(resource) session = Puppet::NetDev::CE::Device.session car_interface = nil get_car_apply_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar><ifName></ifName><direction>inbound</direction><carTmplName></carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></filter></get></rpc>' car_apply_all = session.rpc.do_config(get_car_apply_xml) if car_apply_all.element_children.count != 0 car_apply_elements = car_apply_all.first_element_child.first_element_child.first_element_child car_apply_elements.element_children.each do |car_apply_elem| car_doc = Nokogiri::XML(car_apply_elem.to_s) car_name_get = car_doc.xpath('/qosIfCar/carTmplName').text if car_name_get == resource[:name] car_interface = car_doc.xpath('/qosIfCar/ifName').text end end end unless car_interface.nil? delete_car_apply_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar operation="delete"><ifName>' + car_interface.to_s + '</ifName><direction>inbound</direction></qosIfCar></qosIfCars></qosIfQoss></qos></config></edit-config></rpc>' session.rpc.do_config(delete_car_apply_xml) end delete_car_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl operation="delete"><carTmplName>' + (resource[:name]).to_s + '</carTmplName></qosIfCarTmpl></qosIfCarTmpls></qos></config></edit-config></rpc>' session.rpc.do_config(delete_car_xml) end |
permalink #get_car ⇒ Object
[View source]
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 26 def get_car car_array = [] session = Puppet::NetDev::CE::Device.session get_car_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl><carTmplName></carTmplName><cir></cir><pir></pir><cbs></cbs><pbs></pbs></qosIfCarTmpl></qosIfCarTmpls></qos></filter></get></rpc>' car_all = session.rpc.do_config(get_car_xml) if car_all.element_children.count != 0 car_element = car_all.first_element_child.first_element_child car_element.element_children.each do |car_elem| car_doc_speed = Nokogiri::XML(car_elem.to_s) car_name = car_doc_speed.xpath('/qosIfCarTmpl/carTmplName').text car_speed = car_doc_speed.xpath('/qosIfCarTmpl/cir').text property_hash = { ensure: :present } property_hash[:name] = car_name property_hash[:speed] = car_speed get_car_apply_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar><ifName></ifName><direction>inbound</direction><carTmplName></carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></filter></get></rpc>' car_apply_all = session.rpc.do_config(get_car_apply_xml) if car_apply_all.element_children.count != 0 car_apply_elements = car_apply_all.first_element_child.first_element_child.first_element_child car_apply_elements.element_children.each do |car_apply_elem| car_doc = Nokogiri::XML(car_apply_elem.to_s) car_name_get = car_doc.xpath('/qosIfCar/carTmplName').text next unless car_name_get == car_name car_interface = car_doc.xpath('/qosIfCar/ifName').text property_hash[:interface_name] = car_interface end end car_array << property_hash end end car_array end |
permalink #set_car(resource) ⇒ Object
[View source]
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 93 94 95 96 97 |
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 67 def set_car(resource) session = Puppet::NetDev::CE::Device.session create_car_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl operation="create"><carTmplName>' + (resource[:name]).to_s + '</carTmplName><cir>' + (resource[:speed]).to_s + '</cir><pir></pir><cbs></cbs><pbs></pbs></qosIfCarTmpl></qosIfCarTmpls></qos></config></edit-config></rpc>' session.rpc.do_config(create_car_xml) if !resource[:interface_name].nil? && !resource[:interface_name].empty? set_car_apply_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar operation="create"><ifName>' + (resource[:interface_name]).to_s + '</ifName><direction>inbound</direction><carTmplName>' + (resource[:name]).to_s + '</carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></config></edit-config></rpc>' session.rpc.do_config(set_car_apply_xml) end if !resource[:interface_name].nil? && resource[:interface_name].empty? car_interface = nil get_car_apply_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar><ifName></ifName><direction>inbound</direction><carTmplName></carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></filter></get></rpc>' car_apply_all = session.rpc.do_config(get_car_apply_xml) if car_apply_all.element_children.count != 0 car_apply_elements = car_apply_all.first_element_child.first_element_child.first_element_child car_apply_elements.element_children.each do |car_apply_elem| car_doc = Nokogiri::XML(car_apply_elem.to_s) car_name_get = car_doc.xpath('/qosIfCar/carTmplName').text if car_name_get == resource[:name] car_interface = car_doc.xpath('/qosIfCar/ifName').text end end end unless car_interface.nil? delete_car_apply_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar operation="delete"><ifName>' + car_interface.to_s + '</ifName><direction>inbound</direction></qosIfCar></qosIfCars></qosIfQoss></qos></config></edit-config></rpc>' session.rpc.do_config(delete_car_apply_xml) end end end |