Class: Puppet::Provider::Comware::Interface
- Inherits:
-
Puppet::Provider::Comware
- Object
- Puppet::Provider::Comware
- Puppet::Provider::Comware::Interface
- Defined in:
- lib/puppet/provider/comware/comware_interface.rb
Constant Summary collapse
- INTERFACE_SPEED_TO_COMWARE =
{ :'auto' => 1, :'10m' => 2, :'100m' => 4, :'155m' => 8, :'622m' => 16, :'1g' => 32, :'2g' => 64, :'2.5g' => 128, :'4g' => 256, :'8g' => 512, :'10g' => 1024, :'16g' => 2048, :'20g' => 4096, :'40g' => 8192, :'100g' => 16384 }
Instance Method Summary collapse
- #default_description ⇒ Object
- #init_resource ⇒ Object
- #linktype_from_comware(type) ⇒ Object
- #netdev_res_exists? ⇒ Boolean
- #netdev_resxml_delete(xml) ⇒ Object
-
#netdev_resxml_top(xml) ⇒ Object
override the method:add IfIndex as the get Index.
- #portlayer_from_comware(layer) ⇒ Object
- #speed_from_comware(jval) ⇒ Object
- #speed_to_comware(pval) ⇒ Object
- #xml_change_admin(xml) ⇒ Object
- #xml_change_description(xml) ⇒ Object
- #xml_change_duplex(xml) ⇒ Object
- #xml_change_linktype(xml) ⇒ Object
-
#xml_change_mtu(xml) ⇒ Object
————————————————————- XML builder methods ————————————————————-.
- #xml_change_portlayer(xml) ⇒ Object
- #xml_change_speed(xml) ⇒ Object
Instance Method Details
permalink #default_description ⇒ Object
[View source]
111 112 113 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 111 def default_description "Puppet created interface: #{resource[:name]}" end |
permalink #init_resource ⇒ Object
[View source]
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 86 def init_resource @ndev_res ||= NetdevComware::Resource.new(self, "Ifmgr/Interfaces/Interface") ndev_config = @ndev_res.getconfig return false unless (ifd = ndev_config.xpath('////Interface')[0]) @ndev_res.set_active_state(ifd) return ifd end |
permalink #linktype_from_comware(type) ⇒ Object
[View source]
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 52 def linktype_from_comware(type) case type when 3 then :hybrid when 2 then :trunk when 1 then :access end end |
permalink #netdev_res_exists? ⇒ Boolean
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 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 23 def netdev_res_exists? return false unless (ifd = init_resource) @ndev_res[:description] = ifd.xpath('Description').text.chomp @ndev_res[:admin] = ((admin_status = ifd.xpath('AdminStatus').text.to_i) == 1) ? :up : :down @ndev_res[:mtu] = (mtu = ifd.xpath('ConfigMTU')[0]).nil? ? 1500 : mtu.text.to_i @ndev_res[:duplex] = case = ifd.xpath('ConfigDuplex').text.chomp.to_i when 1 then :full when 2 then :half when 3 then :auto end if speed = ifd.xpath('ConfigSpeed')[0] @ndev_res[:speed] = speed_from_comware(speed.text.to_i) else @ndev_res[:speed] = :auto end @ndev_res[:portlayer] = portlayer_from_comware((portLayer = ifd.xpath('PortLayer').text.to_i)) @ndev_res[:linktype] = linktype_from_comware((linkType = ifd.xpath('LinkType').text.to_i)) return true end |
permalink #netdev_resxml_delete(xml) ⇒ Object
[View source]
103 104 105 106 107 108 109 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 103 def netdev_resxml_delete(xml) if mod = xml.doc.at('Interfaces') mod['xc:operation'] = 'delete' end xml.IfIndex resource[:ifindex] end |
permalink #netdev_resxml_top(xml) ⇒ Object
override the method:add IfIndex as the get Index
98 99 100 101 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 98 def netdev_resxml_top(xml) xml.IfIndex resource[:ifindex] return xml end |
permalink #portlayer_from_comware(layer) ⇒ Object
[View source]
63 64 65 66 67 68 69 70 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 63 def portlayer_from_comware(layer) case layer when 1 then :bridge else :route end end |
permalink #speed_from_comware(jval) ⇒ Object
[View source]
76 77 78 79 80 81 82 83 84 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 76 def speed_from_comware(jval) INTERFACE_SPEED_TO_COMWARE.each do |k, v| if v == jval return k end end :auto end |
permalink #speed_to_comware(pval) ⇒ Object
[View source]
72 73 74 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 72 def speed_to_comware(pval) (jval = INTERFACE_SPEED_TO_COMWARE[pval]).nil? ? 1 : jval end |
permalink #xml_change_admin(xml) ⇒ Object
[View source]
123 124 125 126 127 128 129 130 131 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 123 def xml_change_admin(xml) xml.send(:'AdminStatus', ( case resource[:admin] when :up then 1 when :down then 2 end)) end |
permalink #xml_change_description(xml) ⇒ Object
[View source]
133 134 135 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 133 def xml_change_description(xml) xml.send(:'Description', resource[:description]) end |
permalink #xml_change_duplex(xml) ⇒ Object
[View source]
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 141 def xml_change_duplex(xml) xml.send(:'ConfigDuplex', case resource[:duplex] when :full then 1 when :half then 2 when :auto then 3 end) end |
permalink #xml_change_linktype(xml) ⇒ Object
[View source]
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 164 def xml_change_linktype(xml) xml.send(:'LinkType', case resource[:linktype] when :access then 1 when :trunk then 2 when :hybrid then 3 end) end |
permalink #xml_change_mtu(xml) ⇒ Object
XML builder methods
119 120 121 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 119 def xml_change_mtu(xml) xml.send(:'ConfigMTU', resource[:mtu]) end |
permalink #xml_change_portlayer(xml) ⇒ Object
[View source]
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 152 def xml_change_portlayer(xml) xml.send(:'PortLayer', case resource[:portlayer] when :bridge then 1 when :route then 2 end) ## when switching portlayer,the description will be lost if the description is the same of before xml.send(:'Description', resource[:description]) if resource[:description] == @ndev_res[:description] end |
permalink #xml_change_speed(xml) ⇒ Object
[View source]
137 138 139 |
# File 'lib/puppet/provider/comware/comware_interface.rb', line 137 def xml_change_speed(xml) xml.send(:'ConfigSpeed', speed_to_comware(resource[:speed])) end |