Class: Puppet::Provider::Junos::Vlan
- Inherits:
-
Puppet::Provider::Junos
- Object
- Puppet::Provider::Junos
- Puppet::Provider::Junos::Vlan
- Defined in:
- lib/puppet/provider/junos/junos_vlan.rb
Instance Method Summary collapse
- #default_description ⇒ Object
-
#init_resource ⇒ Object
——————————————————————– #netdev_retrieve helpers ——————————————————————–.
-
#netdev_res_exists? ⇒ Boolean
——————————————————————– triggered by provider #exists? ——————————————————————–.
- #on_change_vlan_id(xml) ⇒ Object
- #xml_change_description(xml) ⇒ Object
- #xml_change_no_mac_learning(xml) ⇒ Object
-
#xml_change_vlan_id(xml) ⇒ Object
———————————————————— XML builder routines, one for each property ————————————————————.
Instance Method Details
#default_description ⇒ Object
76 77 78 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 76 def default_description "Puppet created VLAN: #{resource[:name]}: #{resource[:vlan_id]}" end |
#init_resource ⇒ Object
#netdev_retrieve helpers
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 61 def init_resource resource[:description] ||= default_description @ndev_res ||= NetdevJunos::Resource.new( self, "vlans", "vlan" ) return nil unless (ndev_config = @ndev_res.getconfig) return nil unless vlan_config = ndev_config.xpath('//vlan')[0] @ndev_res.set_active_state( vlan_config ) return vlan_config end |
#netdev_res_exists? ⇒ Boolean
triggered by provider #exists?
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 46 def netdev_res_exists? return false unless (vlan_config = init_resource) @ndev_res[:vlan_id] = vlan_config.xpath('vlan-id').text.chomp @ndev_res[:description] = vlan_config.xpath('description').text.chomp @ndev_res[:no_mac_learning] = vlan_config.xpath('no-mac-learning').empty? ? :false : :true return true end |
#on_change_vlan_id(xml) ⇒ Object
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 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 100 def on_change_vlan_id( xml ) return unless Facter.value('junos_switch_style') == 'vlan_l2ng' # because the L2NG codes the vlan-id values into the interfaces, # we now need to update all instances of the use of the vlan. Yo! # so the trick here is to create a false-name by prepending a # tilde (~) before the vlan_name. Then tinker with the # associated netdev_l2_interface properties so that it # triggers the resource to 'do the right thing'. There is # a dependency in the netdev_l2_interface code on the use # of the '~' so be aware if you want to muck with it. Yo! vlan_name = resource[:name] vlan_name_new = '~' + vlan_name vlan_old = [[ vlan_name ]] vlan_new = [[ vlan_name_new ]] catalog = resource.catalog rpc = @ndev_res.rpc bd_info = rpc.get_vlan_information( :vlan_name => vlan_name ) intfs = bd_info.xpath('//l2ng-l2rtb-vlan-member-interface') intfs.each do |x_int| ifd_name = x_int.text[/(.*)\./,1] if l2_intf = catalog.resource( :netdev_l2_interface, ifd_name ) if l2_intf[:tagged_vlans].include? [vlan_name] l2_intf[:tagged_vlans] = l2_intf[:tagged_vlans] - vlan_old + vlan_new end l2_intf[:untagged_vlan] = vlan_name_new if l2_intf[:untagged_vlan] == vlan_name else NetdevJunos::Log.err "Unmanaged VLAN interface: #{ifd_name}" end end end |
#xml_change_description(xml) ⇒ Object
89 90 91 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 89 def xml_change_description( xml ) xml.description resource[:description] end |
#xml_change_no_mac_learning(xml) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 93 def xml_change_no_mac_learning( xml ) ml = resource[:no_mac_learning] == :false return if @ndev_res.is_new? and ml xml.send( :'no-mac-learning', ml ? Netconf::JunosConfig::DELETE : nil ) end |
#xml_change_vlan_id(xml) ⇒ Object
XML builder routines, one for each property
84 85 86 87 |
# File 'lib/puppet/provider/junos/junos_vlan.rb', line 84 def xml_change_vlan_id( xml ) xml.send :"vlan-id", resource[:vlan_id] on_change_vlan_id( xml ) end |