Class: Junos::Ez::Vlans::Provider::VLAN_L2NG

Inherits:
Junos::Ez::Vlans::Provider show all
Defined in:
lib/junos-ez/vlans/vlan_l2ng.rb,
lib/junos-ez/vlans/vlan_l2ng.rb,
lib/junos-ez/vlans/vlan_l2ng.rb

Overview


Provider operational 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_config_read!, #xml_element_newname, #xml_on_create, #xml_on_delete

Constructor Details

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

Instance Method Details

#build_catalogObject



77
78
79
80
81
82
83
84
85
86
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 77

def build_catalog
  @catalog = {}    
  xml_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'vlans' }    
  xml_cfgs.xpath('vlans/vlan').collect do |vlan|
    name = vlan.xpath('name').text
    @catalog[name] = {}
    xml_read_parser( vlan, @catalog[name] )
  end          
  return @catalog
end

#build_listObject



70
71
72
73
74
75
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 70

def build_list    
  xml_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'vlans' }
  xml_cfgs.xpath('vlans/vlan').collect do |vlan|
    vlan.xpath('name').text
  end    
end

#interfaces(opts = {}) ⇒ Object


interfaces - returns a Hash of each interface in the VLAN

each interface (key) will identify:
:mode = [ :access | :trunk ]
:native = true if (:mode == :trunk) and this VLAN is the 
   native vlan-id (untagged packets)

Raises:

  • (ArgumentError)


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 104

def interfaces( opts = {} )
  raise ArgumentError, "not a resource" if is_provider?
  
  args = {}
  args[:vlan_name] = @name 
  args[:extensive] = true    
  got = @ndev.rpc.get_vlan_information( args )
  
  member_pfx = 'l2ng-l2rtb-vlan-member'
  members = got.xpath("//#{member_pfx}-interface")
  ifs_h = {}
  members.each do |port|
    port_name = port.text.split('.')[0]
    port_h = {}
    port_h[:mode] = port.xpath("following-sibling::#{member_pfx}-interface-mode[1]").text.to_sym
    tgd = port.xpath("following-sibling::#{member_pfx}-tagness[1]").text
    native = (tgd == 'untagged')
    port_h[:native] = true if( native and port_h[:mode] == :trunk)
    ifs_h[port_name] = port_h
  end
  ifs_h    
end

#xml_at_topObject


XML top placement




7
8
9
10
11
12
13
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 7

def xml_at_top
  Nokogiri::XML::Builder.new{|x| x.configuration{ 
    x.vlans { x.vlan { x.name @name
      return x
    }}
  }}
end

#xml_change_description(xml) ⇒ Object



57
58
59
60
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 57

def xml_change_description( xml )
  value = @should[:description]
  xml.description value ? value : Netconf::JunosConfig::DELETE
end

#xml_change_no_mac_learning(xml) ⇒ Object


XML writers




45
46
47
48
49
50
51
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 45

def xml_change_no_mac_learning( xml )
  no_ml = @should[:no_mac_learning]     
  return unless exists? and no_ml    
  xml.send(:'switch-options') {
    xml.send(:'no-mac-learning', no_ml == :enable ? nil : Netconf::JunosConfig::DELETE )
  }
end

#xml_change_vlan_id(xml) ⇒ Object



53
54
55
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 53

def xml_change_vlan_id( xml )
  xml.send(:'vlan-id', @should[:vlan_id] )
end

#xml_get_has_xml(xml) ⇒ Object


XML readers




19
20
21
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 19

def xml_get_has_xml( xml )
  xml.xpath('//vlan')[0]    
end

#xml_read_parser(as_xml, as_hash) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/junos-ez/vlans/vlan_l2ng.rb', line 23

def xml_read_parser( as_xml, as_hash )
  set_has_status( as_xml, as_hash )    
  
  as_hash[:vlan_id] = as_xml.xpath('vlan-id').text.to_i
  xml_when_item(as_xml.xpath('description')){ |i| as_hash[:description] = i.text }
      
  xml_when_item(as_xml.xpath('switch-options/no-mac-learning')) {
    as_hash[:no_mac_learning] = :enable
  }
  
  # get a brief list of the interfaces on this vlan
  got = @ndev.rpc.get_vlan_information( :vlan_name => @name || as_xml.xpath('name').text )
  as_hash[:interfaces] = got.xpath('//l2ng-l2rtb-vlan-member-interface').collect{|ifs| ifs.text.strip }
  as_hash[:interfaces] = nil if as_hash[:interfaces][0] == "None"
  
  return true
end