Class: Puppet::Provider::Junos::BridgeDomain
- Inherits:
-
Puppet::Provider::Junos
- Object
- Puppet::Provider::Junos
- Puppet::Provider::Junos::BridgeDomain
- Defined in:
- lib/puppet/provider/junos/junos_vlan_bd.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
———————————————————— Helper, Utilities .…
- #on_new_bridge_domain(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
73 74 75 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 73 def default_description "Puppet created VLAN: #{resource[:name]}: #{resource[:vlan_id]}" end |
#init_resource ⇒ Object
#netdev_retrieve helpers
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 59 def init_resource resource[:description] ||= default_description @ndev_res ||= NetdevJunos::Resource.new( self, "bridge-domains", "domain" ) return nil unless (ndev_config = @ndev_res.getconfig) return nil unless vlan_config = ndev_config.xpath('//domain')[0] @ndev_res.set_active_state( vlan_config ) return vlan_config end |
#netdev_res_exists? ⇒ Boolean
triggered by provider #exists?
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 43 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('bridge-options/no-mac-learning').empty? ? :false : :true return true end |
#on_change_vlan_id(xml) ⇒ Object
Helper, Utilities .…
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 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_vlan_bd.rb', line 111 def on_change_vlan_id( xml ) # because the MX 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 begin bd_info = rpc.get_bridge_instance_information( :bridge_domain_name => vlan_name ) rescue Netconf::RpcError => e # if rpc is not supported on device return errmsg = e.to_s NetdevJunos::Log.notice errmsg return end intfs = bd_info.xpath('//l2rtb-interface-name') intfs.each do |x_int| ifd_name = x_int.text[/(.*)\./,1] next unless ifd_name 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.notice "Unmanaged bridge interface: #{x_int.text} for vlan #{vlan_name}" end end end |
#on_new_bridge_domain(xml) ⇒ Object
77 78 79 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 77 def on_new_bridge_domain( xml ) xml.send(:'domain-type', 'bridge') end |
#xml_change_description(xml) ⇒ Object
93 94 95 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 93 def xml_change_description( xml ) xml.description resource[:description] end |
#xml_change_no_mac_learning(xml) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 97 def xml_change_no_mac_learning( xml ) no_ml = resource[:no_mac_learning] == :false return if @ndev_res.is_new? and no_ml xml.send(:'bridge-options') { xml.send(:'no-mac-learning', no_ml ? Netconf::JunosConfig::DELETE : nil ) } end |
#xml_change_vlan_id(xml) ⇒ Object
XML builder routines, one for each property
85 86 87 88 89 90 91 |
# File 'lib/puppet/provider/junos/junos_vlan_bd.rb', line 85 def xml_change_vlan_id( xml ) if @ndev_res.is_new? on_new_bridge_domain( xml ) end xml.send :"vlan-id", resource[:vlan_id] on_change_vlan_id( xml ) end |