Class: Puppet::Provider::Comware::Vxlan

Inherits:
Puppet::Provider::Comware
  • Object
show all
Defined in:
lib/puppet/provider/comware/comware_vxlan.rb

Instance Method Summary collapse

Instance Method Details

#get_tunnels_list(tunnels) ⇒ Object

because the @property_hash or @property_hash maybe like that: ‘1,2,3-8,4’,so we use it to convert it to [1,2,3,4,5,6,7,8]



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 58

def get_tunnels_list(tunnels)
  return nil unless tunnels

  lists = tunnels.to_s.split(',')
  newlist = []
  lists.each do |x|
    if x.include?('-') then
      ary = x.split('-')
      xx = []
      for i in ary[0]..ary[1]
        xx << i.to_i
      end
      newlist << xx unless xx.empty?
    else
      newlist << x.to_i
    end
  end
  newlist.flatten.uniq
end

#init_resourceObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 14

def init_resource
  @ndev_res ||= NetdevComware::Resource.new( self, "VXLAN/VXLANs/Vxlan" )

  ndev_config = @ndev_res.getconfig

  @ndev_res.change_edit_path("VXLAN")
  return false unless (ifd = ndev_config.xpath('////Vxlan')[0])

  resource[:name] = resource[:vxlan_id]
  @ndev_res.set_active_state( ifd )

  return ifd
end

#netdev_res_exists?Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 5

def netdev_res_exists?

  return false unless (ifd = init_resource)

  @ndev_res[:vsiname] = ifd.xpath('VsiName').text.chomp

  return true
end

#netdev_resxml_create_top(xml) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 43

def netdev_resxml_create_top( xml )
  xml.VXLANs{
    xml.Vxlan{
      xml.VxlanID resource[:vxlan_id]
      return xml
    }
  }
end

#netdev_resxml_delete(xml) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 28

def netdev_resxml_delete( xml )
  xml.VXLANs('xc:operation' => 'delete'){
    xml.Vxlan{
      xml.VxlanID resource[:vxlan_id]
      return xml
    }
  }
end

#netdev_resxml_edit(xml) ⇒ Object

because the exsiting framework cannot meet our requires so I rewrite the netdev_resxml_edit method to construct xml for our netconf request caution:this method assume that the param xml is like below: <top><VXLAN/></top>



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
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 82

def netdev_resxml_edit( xml )
  if resource[:vsiname] then
    xml.VXLANs {
      xml.Vxlan {
        xml.VxlanID resource[:vxlan_id]
        xml.VsiName resource[:vsiname]
      }
    }
  end

  lists = []
  if lists = get_tunnels_list(resource[:add_tunnels]) then
    xml.Tunnels {
     lists.each do |e|
       xml.Tunnel {
         xml.VxlanID  resource[:vxlan_id]
         xml.TunnelID e
       }
     end
    }
  end

  if lists = get_tunnels_list(resource[:delete_tunnels]) then
    xml.Tunnels('xc:operation' => 'delete') {
      lists.each do |e|
        xml.Tunnel {
          xml.VxlanID  resource[:vxlan_id]
          xml.TunnelID e
        }
      end
    }
  end

  return xml
end

#netdev_resxml_merge_top(xml) ⇒ Object



52
53
54
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 52

def netdev_resxml_merge_top(xml)
  return xml
end

#netdev_resxml_top(xml) ⇒ Object

override the method



38
39
40
41
# File 'lib/puppet/provider/comware/comware_vxlan.rb', line 38

def netdev_resxml_top( xml )
  xml.VxlanID resource[:vxlan_id]
  return xml
end