Class: Puppet::NetDev::CE::VlanBatchApi
- Defined in:
- lib/puppet/provider/ce/api/vlan_batch/vlan_batch_api.rb
Instance Method Summary collapse
-
#initialize ⇒ VlanBatchApi
constructor
A new instance of VlanBatchApi.
- #vlan_batch(resource) ⇒ Object
Constructor Details
#initialize ⇒ VlanBatchApi
Returns a new instance of VlanBatchApi.
22 23 24 |
# File 'lib/puppet/provider/ce/api/vlan_batch/vlan_batch_api.rb', line 22 def initialize super() end |
Instance Method Details
#vlan_batch(resource) ⇒ 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 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 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/vlan_batch/vlan_batch_api.rb', line 26 def vlan_batch(resource) session = Puppet::NetDev::CE::Device.session # transform tagged_vlans into trunkVlans bitmap vlan_bit = Array.new(1024, 0) all_bits = Array.new(1024, 0) for i in resource[:vlan_start]..resource[:vlan_end] do tagged_vlans = i j = tagged_vlans / 4 all_bits[j] = all_bits[j] + 1 if tagged_vlans % 4 == 0 all_bits[j] = all_bits[j] + 2 if tagged_vlans % 4 == 1 all_bits[j] = all_bits[j] + 4 if tagged_vlans % 4 == 2 all_bits[j] = all_bits[j] + 8 if tagged_vlans % 4 == 3 case all_bits[j] when 0 vlan_bit[j] = '0' when 1 vlan_bit[j] = '8' when 2 vlan_bit[j] = '4' when 3 vlan_bit[j] = 'C' when 4 vlan_bit[j] = '2' when 5 vlan_bit[j] = 'A' when 6 vlan_bit[j] = '6' when 7 vlan_bit[j] = 'E' when 8 vlan_bit[j] = '1' when 9 vlan_bit[j] = '9' when 10 vlan_bit[j] = '5' when 11 vlan_bit[j] = 'D' when 12 vlan_bit[j] = '3' when 13 vlan_bit[j] = 'B' when 14 vlan_bit[j] = '7' when 15 vlan_bit[j] = 'F' end end aa = vlan_bit.join if resource[:ensure] == :present create_vlan_batch_xml = '<rpc><execute-action xmlns="http://www.huawei.com/netconf/capability/base/1.0"><action><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><shVlanBatchCrt><vlans>' + aa.to_s + ':' + aa.to_s + '</vlans></shVlanBatchCrt></vlan></action></execute-action></rpc>' session.rpc.do_config(create_vlan_batch_xml) end if resource[:ensure] == :absent delete_vlan_batch_xml = '<rpc><execute-action xmlns="http://www.huawei.com/netconf/capability/base/1.0"><action><vlan xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><shVlanBatchDel><vlans>' + aa.to_s + ':' + aa.to_s + '</vlans></shVlanBatchDel></vlan></action></execute-action></rpc>' session.rpc.do_config(delete_vlan_batch_xml) end end |