Class: Puppet::NetDev::CE::VlanApi
- Defined in:
- lib/puppet/provider/ce/api/vlan/vlan_api.rb
Instance Method Summary collapse
- #create_vlan(resource) ⇒ Object
- #delete_vlan(resource) ⇒ Object
- #get_vlan ⇒ Object
-
#initialize ⇒ VlanApi
constructor
A new instance of VlanApi.
- #set_vlan(resource) ⇒ Object
Constructor Details
#initialize ⇒ VlanApi
Returns a new instance of VlanApi.
22 23 24 |
# File 'lib/puppet/provider/ce/api/vlan/vlan_api.rb', line 22 def initialize super() end |
Instance Method Details
#create_vlan(resource) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/puppet/provider/ce/api/vlan/vlan_api.rb', line 70 def create_vlan(resource) session = Puppet::NetDev::CE::Device.session create_vlan_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><vlans><vlan operation="create"><vlanId>' + (resource[:id]).to_s + '</vlanId><vlanName/><vlanDesc/><vlanType>common</vlanType><vlanif><cfgBand/><dampTime/></vlanif></vlan></vlans></vlan></config></edit-config></rpc>' session.rpc.do_config(create_vlan_xml) end |
#delete_vlan(resource) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/puppet/provider/ce/api/vlan/vlan_api.rb', line 78 def delete_vlan(resource) session = Puppet::NetDev::CE::Device.session delete_vlan_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><vlans><vlan operation="delete"><vlanId>' + (resource[:id]).to_s + '</vlanId></vlan></vlans></vlan></config></edit-config></rpc>' session.rpc.do_config(delete_vlan_xml) end |
#get_vlan ⇒ Object
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 |
# File 'lib/puppet/provider/ce/api/vlan/vlan_api.rb', line 26 def get_vlan vlan_array = [] session = Puppet::NetDev::CE::Device.session get_vlan_xml = '<rpc><get><filter type="subtree"><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><vlans><vlan></vlan></vlans></vlan></filter></get></rpc>' vlan_all = session.rpc.do_config(get_vlan_xml) vlan_elements = vlan_all.first_element_child.first_element_child vlan_elements.element_children.each do |vlan_elem| vlan_doc = Nokogiri::XML(vlan_elem.to_s) vlan_id = vlan_doc.xpath('/vlan/vlanId').text vlan_name = vlan_doc.xpath('/vlan/vlanName').text vlan_des = vlan_doc.xpath('/vlan/vlanDesc').text property_hash = { ensure: :present } property_hash[:id] = vlan_id property_hash[:name] = property_hash[:id] property_hash[:vlan_name] = vlan_name property_hash[:description] = vlan_des vlan_array << property_hash end vlan_array end |
#set_vlan(resource) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/provider/ce/api/vlan/vlan_api.rb', line 52 def set_vlan(resource) session = Puppet::NetDev::CE::Device.session set_vlan_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><vlans><vlan operation="merge"><vlanId>' + (resource[:id]).to_s + '</vlanId>' if resource[:vlan_name] set_vlan_xml += '<vlanName>' + (resource[:vlan_name]).to_s + '</vlanName>' end if resource[:description] set_vlan_xml += '<vlanDesc>' + (resource[:description]).to_s + '</vlanDesc>' end set_vlan_xml += '</vlan></vlans></vlan></config></edit-config></rpc>' session.rpc.do_config(set_vlan_xml) end |