Class: Puppet::Provider::Junos::LAG
- Inherits:
-
Puppet::Provider::Junos
- Object
- Puppet::Provider::Junos
- Puppet::Provider::Junos::LAG
- Defined in:
- lib/puppet/provider/junos/junos_lag.rb
Instance Method Summary collapse
-
#destroy ⇒ Object
————————————————————— Overriding Parent methods —————————————————————.
-
#get_cookie_links(cfg) ⇒ Object
———————————————————— Utilities ————————————————————.
-
#init_resource ⇒ Object
————————————————————— called from #netdev_exists? —————————————————————.
-
#netdev_res_exists? ⇒ Boolean
————————————————————— triggered from Provider #exists? —————————————————————.
-
#on_destroy(has_links, xml) ⇒ Object
on_destroy is called by the ‘change links’ handler as a special case.
- #set_cookie_links(cfg) ⇒ Object
-
#xml_change_lacp(xml) ⇒ Object
——————————————- PROPERTY: lacp ——————————————-.
-
#xml_change_links(xml) ⇒ Object
——————————————- PROPERTY: links ——————————————-.
-
#xml_change_minimum_links(xml) ⇒ Object
——————————————- PROPERTY: minimum_links ——————————————-.
Instance Method Details
#destroy ⇒ Object
Overriding Parent methods
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 117 def destroy Puppet.debug( "#{self.resource.type}::LAG-DESTROY #{resource[:name]}" ) # we need to load the known IFD ports in the lag so we can unbind them # from the lag. We 'trick' the Puppet agent into processing the # "change links" method, and from there we can do the unlink and # removal of the IFD (special-case) ae_config = init_resource @ndev_res[:links] = ( ae_config ) || [] resource[:links] = [] @property_hash[:links] = true end |
#get_cookie_links(cfg) ⇒ Object
Utilities
161 162 163 164 165 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 161 def ( cfg ) cfg.xpath( "apply-macro[name = 'netdev_lag[:links]']/data/name" ).collect { |n| n.text } end |
#init_resource ⇒ Object
called from #netdev_exists?
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 102 def init_resource @ndev_res ||= NetdevJunos::Resource.new( self, 'interfaces', 'interface' ) ndev_config = @ndev_res.getconfig return nil unless lagcfg = ndev_config.xpath( '//interface')[0] @ndev_res.set_active_state( lagcfg ) return lagcfg end |
#netdev_res_exists? ⇒ Boolean
triggered from Provider #exists?
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 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 45 def netdev_res_exists? ### need to setup the @ifd_ether_options before we return anything ### since this will be used in the case of a yet-to-be-created LAG if Facter.value(:junos_ifd_style) == 'classic' # all ports in the LAG must be of the same type, so check the first one # and use it to determine the options stanza name. yo. l_0 = resource[:links][0].to_s @ifd_ether_options = (l_0.start_with? 'fe-') ? 'fastether-options' : 'gigether-options' else # switching platforms are standardized on the same stanza name. @ifd_ether_options = 'ether-options' end return false unless ae_config = init_resource nc = netdev_get.netconf.rpc # ------------------------------------------- # PROPERTY: links # ------------------------------------------- # retrieve details on the ae interface so we can pull the list of member links. In the general # case there could be a lot of sub-interfaces (units), so we need to handle that case here. We # only want the IFD names in the @ndev_res hash @ndev_res[:links] = ( ae_config ) || [] # ------------------------------------------- # PROPERTY: minimum_links # ------------------------------------------- if mlinks = ae_config.xpath('aggregated-ether-options/minimum-links')[0] @ndev_res[:minimum_links] = mlinks.text.chomp.to_i; else @ndev_res[:minimum_links] = 0 end # ------------------------------------------- # PROPERTY: lacp # ------------------------------------------- lacp = ae_config.xpath('aggregated-ether-options/lacp')[0] if lacp @ndev_res[:lacp] = :active if lacp.xpath('active')[0] @ndev_res[:lacp] = :passive if lacp.xpath('passive')[0] else @ndev_res[:lacp] = :disabled end return true end |
#on_destroy(has_links, xml) ⇒ Object
on_destroy is called by the ‘change links’ handler as a special case. that handler will immediately return once on_destroy is done
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 135 def on_destroy( has_links, xml ) par = xml.instance_variable_get(:@parent) dot_ifd = par.at_xpath('ancestor::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 Nokogiri::XML::Builder.with( dot_ifd ) do |dot| dot.interface( Netconf::JunosConfig::DELETE ) { dot.name resource[:name] } end end |
#set_cookie_links(cfg) ⇒ Object
167 168 169 170 171 172 173 174 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 167 def ( cfg ) cfg.send(:'apply-macro', Netconf::JunosConfig::REPLACE ) { cfg.name 'netdev_lag[:links]' resource[:links].each{ |ifd| cfg.data { cfg.name ifd } } } end |
#xml_change_lacp(xml) ⇒ Object
PROPERTY: lacp
200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 200 def xml_change_lacp( xml ) if resource[:lacp] == :disabled xml.send(:'aggregated-ether-options') { xml.lacp( Netconf::JunosConfig::DELETE ) } else xml.send(:'aggregated-ether-options') { xml.lacp { xml.send resource[:lacp] } } end end |
#xml_change_links(xml) ⇒ Object
PROPERTY: links
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 218 def xml_change_links( xml ) has = @ndev_res[:links] || [] should = resource[:links] || [] # -------------------------------------------------------------------- # this is a special case where we're removing the entire LAG # we use an empty links list to trigger this action, see #destroy # method in the above code. # -------------------------------------------------------------------- if should.empty? on_destroy( has, xml ) return end ( xml ) has = has.map(&:to_s) should = should.map(&:to_s) 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 resource[: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 |
#xml_change_minimum_links(xml) ⇒ Object
PROPERTY: minimum_links
184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/puppet/provider/junos/junos_lag.rb', line 184 def xml_change_minimum_links( xml ) if resource[:minimum_links] > 0 xml.send(:'aggregated-ether-options') { xml.send( :'minimum-links', resource[:minimum_links] ) } else xml.send(:'aggregated-ether-options') { xml.send(:'minimum-links', Netconf::JunosConfig::DELETE ) } end end |