Class: Junos::Ez::LAGports::Provider

Inherits:
Provider::Parent show all
Defined in:
lib/junos-ez/lag_ports.rb,
lib/junos-ez/lag_ports.rb,
lib/junos-ez/lag_ports.rb,
lib/junos-ez/lag_ports.rb

Overview


_PRIVATE methods


Instance Attribute Summary

Attributes inherited from Provider::Parent

#catalog, #has, #list, #name, #ndev, #parent, #properties, #providers, #should

Instance Method Summary collapse

Methods inherited from Provider::Parent

#[], #[]=, #activate!, #active?, #catalog!, #create, #create!, #create_from_hash!, #create_from_yaml!, #deactivate!, #delete!, #each, #exists?, #init_has, #initialize, #is_new?, #is_provider?, #list!, #name_decorated, #need_write?, #read!, #rename!, #reorder!, #select, #to_h, #to_h_expanded, #to_yaml, #with, #write!, #xml_at_edit, #xml_build_change, #xml_change__active, #xml_change__exist, #xml_change_admin, #xml_change_description, #xml_element_newname

Constructor Details

This class inherits a constructor from Junos::Ez::Provider::Parent

Instance Method Details

#_get_port_list(name) ⇒ Object



259
260
261
262
263
264
265
266
# File 'lib/junos-ez/lag_ports.rb', line 259

def _get_port_list( name )
  @ndev.rpc.get_interface_information(
    :detail => true,
    :interface_name => name + '.0'
  ).xpath('//lag-link/name').collect{ |name| 
    name.text.strip.split('.',2).first 
  }
end

#build_catalogObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/junos-ez/lag_ports.rb', line 233

def build_catalog
  return @catalog if list!.empty?
  
  list.each do |ae_name|
    @ndev.rpc.get_configuration{ |xml|
      xml.interfaces {
        xml.interface {
          xml.name ae_name
        }
      }
    }.xpath('interfaces/interface').each do |as_xml|
      @catalog[ae_name] = {}
      xml_read_parser( as_xml, @catalog[ae_name] )
    end
  end    
  
  @catalog
end

#build_listObject



226
227
228
229
230
231
# File 'lib/junos-ez/lag_ports.rb', line 226

def build_list    
  @ndev.rpc.get_interface_information(
    :terse => true,
    :interface_name => 'ae*' 
  ).xpath('physical-interface/name').collect{ |name| name.text.strip }
end


utilities




46
47
48
# File 'lib/junos-ez/lag_ports.rb', line 46

def get_cookie_links( cfg )
  cfg.xpath( "apply-macro[name = 'netdev_lag[:links]']/data/name" ).collect { |n| n.text }
end


50
51
52
53
54
55
56
57
# File 'lib/junos-ez/lag_ports.rb', line 50

def set_cookie_links( cfg )
  cfg.send(:'apply-macro', Netconf::JunosConfig::REPLACE ) {
    cfg.name 'netdev_lag[:links]'
    should[:links].each{ |ifd|
      cfg.data { cfg.name ifd }
    }
  }
end

#update_ifd_hasObject



108
109
110
111
112
113
114
115
116
# File 'lib/junos-ez/lag_ports.rb', line 108

def update_ifd_has()
  @has[:links] = @has[:links].to_a
  if @has[:links].empty?
   raise Junos::Ez::NoProviderError, "\n Either lag interface is not created or links associated with given lag interface is not supported \n"
  else
   ether_option = @has[:links][0].to_s
   @ifd_ether_options = (ether_option.start_with? 'fe-') ? 'fastether-options' : 'gigether-options'
  end  
end

#update_ifd_shouldObject


XML property writers




99
100
101
102
103
104
105
106
# File 'lib/junos-ez/lag_ports.rb', line 99

def update_ifd_should()
  if @should[:links].empty?
    raise Junos::Ez::NoProviderError, "\n *links* are compulsory for creating lag interface!!! \n"
  else
    ether_option = @should[:links][0].to_s
    @ifd_ether_options = (ether_option.start_with? 'fe-') ? 'fastether-options' : 'gigether-options'
  end
end

#xml_at_topObject

LAG ports sit at the toplevel interface



32
33
34
35
36
37
38
39
# File 'lib/junos-ez/lag_ports.rb', line 32

def xml_at_top
  Nokogiri::XML::Builder.new {|xml| xml.configuration {
    xml.interfaces { xml.interface {
      xml.name @name
      return xml
    }}
  }}
end

#xml_change_lacp(xml) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/junos-ez/lag_ports.rb', line 150

def xml_change_lacp( xml )
  if @should[:lacp] == :disabled or @should[:lacp].nil?
    xml.send(:'aggregated-ether-options') {
      xml.lacp( Netconf::JunosConfig::DELETE )
    }
  else
    xml.send(:'aggregated-ether-options') {
      xml.lacp { xml.send @should[:lacp] }      # @@@ should validate :lacp value before doing this...
    }
  end
end


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/junos-ez/lag_ports.rb', line 118

def xml_change_links( xml )
  update_ifd_should()  
  @should[:links] = @should[:links].to_set if @should[:links].kind_of? Array
  
  has = @has[:links] || Set.new
  should = @should[:links] || Set.new
          
  set_cookie_links( xml )

  del = has - should
  add = should - has
  
  par = xml.instance_variable_get(:@parent)
  dot_ifd = par.at_xpath('ancestor::interfaces')

  add.each{ |new_ifd| Nokogiri::XML::Builder.with( dot_ifd ) {|dot|
    dot.interface { dot.name new_ifd
      dot.send(@ifd_ether_options.to_sym) {
        dot.send(:'ieee-802.3ad') {
          dot.bundle @name
        }
      }
  }}}

  del.each{ |new_ifd| Nokogiri::XML::Builder.with( dot_ifd ) {|dot|
    dot.interface { dot.name new_ifd
      dot.send(@ifd_ether_options) {
        dot.send( :'ieee-802.3ad', Netconf::JunosConfig::DELETE )
      }
  }}} 
end


162
163
164
165
166
167
168
169
170
171
172
# File 'lib/junos-ez/lag_ports.rb', line 162

def xml_change_minimum_links( xml )
  if @should[:minimum_links] 
    xml.send(:'aggregated-ether-options') {
      xml.send( :'minimum-links', @should[:minimum_links] )
    }
  else
    xml.send(:'aggregated-ether-options') {
      xml.send(:'minimum-links', Netconf::JunosConfig::DELETE )
    }
  end
end

#xml_config_read!Object


XML property readers




63
64
65
66
# File 'lib/junos-ez/lag_ports.rb', line 63

def xml_config_read!
  database = {'database' => 'committed'}
  @ndev.rpc.get_configuration(xml_at_top, database)
end

#xml_get_has_xml(xml) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/junos-ez/lag_ports.rb', line 68

def xml_get_has_xml( xml )
  if ndev.facts[:ifd_style] == "CLASSIC"
    @ifd_ether_options = 'gigether-options'
  else
    @ifd_ether_options = 'ether-options' 
  end 
  xml.xpath('//interface')[0]    
end

#xml_on_create(xml) ⇒ Object


XML on-create




178
179
180
181
182
183
184
185
186
# File 'lib/junos-ez/lag_ports.rb', line 178

def xml_on_create( xml )
  # make sure there is a 'unit 0' on the AE port
  par = xml.instance_variable_get(:@parent)
  Nokogiri::XML::Builder.with(par) do |dot|
    dot.unit {
      dot.name '0'
    }
  end
end

#xml_on_delete(xml) ⇒ Object


XML on-delete




192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/junos-ez/lag_ports.rb', line 192

def xml_on_delete( xml )
  update_ifd_has()
  par = xml.instance_variable_get(:@parent)
  dot_ifd = par.at_xpath('ancestor::interfaces')
 
  # remove the bindings from each of the physical interfaces
  #    
  @has[:links].each do |new_ifd| Nokogiri::XML::Builder.with( dot_ifd ) do |dot|
    dot.interface { dot.name new_ifd
      dot.send(@ifd_ether_options) {
        dot.send( :'ieee-802.3ad', Netconf::JunosConfig::DELETE )
      }
    }
    end
  end
  
  # now remove the LAG interface
  #
  Nokogiri::XML::Builder.with( dot_ifd ) do |dot|
    dot.interface( Netconf::JunosConfig::DELETE ) {
      dot.name @name
    }
  end        
end

#xml_read_parser(as_xml, as_hash) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/junos-ez/lag_ports.rb', line 77

def xml_read_parser( as_xml, as_hash )    
  set_has_status( as_xml, as_hash )          
      
  # property :links
  ae_name = as_xml.xpath('name').text
  as_hash[:links] = Set.new(get_cookie_links(as_xml))
  
  # property :lacp
  ae_opts = as_xml.xpath('aggregated-ether-options')
  if (lacp = ae_opts.xpath('lacp')[0])
    as_hash[:lacp] = (lacp.xpath('active')[0]) ? :active : :passive
  else
    as_hash[:lacp] = :disabled
  end      
  
  # property :minimum_links
  as_hash[:minimum_links] = (min_links = ae_opts.xpath('minimum-links')[0]) ? min_links.text.to_i : 1
end