Class: Puppet::Provider::Comware::Lagg

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

Instance Method Summary collapse

Instance Method Details

#get_ports_list(ports) ⇒ 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]



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 131

def get_ports_list(ports)
  return nil unless ports

  lists = ports.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



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 32

def init_resource
  @ndev_res ||= NetdevComware::Resource.new( self, "LAGG/LAGGGroups/LAGGGroup" )

  ndev_config = @ndev_res.getconfig
  #ugly because of the limited my ability
  @ndev_res.change_edit_path("LAGG")
  return false unless (ifd = ndev_config.xpath('////LAGGGroup')[0])

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

  return ifd
end

#linkmode_from_comware(mode) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 14

def linkmode_from_comware(mode)
  case mode
    when 1
      :static
    else
      :dynamic
  end
end

#linkmode_to_comware(mode) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 23

def linkmode_to_comware(mode)
  case mode
    when :static
      1
    else
      2
  end
end

#netdev_res_exists?Boolean

Returns:

  • (Boolean)


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

def netdev_res_exists?

  return false unless (ifd = init_resource)

  @ndev_res[:linkmode] = linkmode_from_comware(ifd.xpath('LinkMode').text.to_i)

  return true
end

#netdev_resxml_create_top(xml) ⇒ Object



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

def netdev_resxml_create_top( xml )
  xml.LAGGGroups {
    xml.LAGGGroup {
      xml.GroupId resource[:group_id]
      xml.LinkMode linkmode_to_comware(resource[:linkmode]) if resource[:linkmode]
    }
  }

  lists = []
  if lists = get_ports_list(resource[:addports]) then
    xml.LAGGMembers {
      lists.each do |e|
        xml.LAGGMember {
          xml.IfIndex e
          xml.GroupId resource[:group_id]
        }
      end
    }
  end

  if lists = get_ports_list(resource[:deleteports]) then
    xml.LAGGMembers('xc:operation' => 'delete') {
      lists.each do |e|
        xml.LAGGMember {
          xml.IfIndex e
          xml.GroupId
        }
      end
    }
  end
end

#netdev_resxml_delete(xml) ⇒ Object

when delete use it



85
86
87
88
89
90
91
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 85

def netdev_resxml_delete( xml )
  xml.LAGGGroups {
    xml.LAGGGroup('xc:operation'=>'delete'){
      xml.GroupId resource[:group_id]
    }
  }
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><LAGG/></top>



155
156
157
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 155

def netdev_resxml_edit( xml )
  return xml
end

#netdev_resxml_merge_top(xml) ⇒ Object

when merge use it



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

def netdev_resxml_merge_top( xml )
  if @property_hash[:linkmode] then
    xml.LAGGGroups {
      xml.LAGGGroup {
        xml.GroupId resource[:group_id]
        xml.LinkMode linkmode_to_comware(resource[:linkmode])
      }
    }
  end

  lists = []
  if lists = get_ports_list(@property_hash[:addports]) then
    xml.LAGGMembers {
      lists.each do |e|
        xml.LAGGMember {
          xml.IfIndex e
          xml.GroupId resource[:group_id]
        }
      end
    }
  end

  if lists = get_ports_list(@property_hash[:deleteports]) then
    xml.LAGGMembers('xc:operation' => 'delete') {
      lists.each do |e|
        xml.LAGGMember {
          xml.IfIndex e
          xml.GroupId
        }
      end
    }
  end
  return xml
end

#netdev_resxml_top(xml) ⇒ Object

when get,create use it



47
48
49
50
# File 'lib/puppet/provider/comware/comware_lagg.rb', line 47

def netdev_resxml_top( xml )
  xml.GroupId resource[:group_id]
  return xml
end