Class: Junos::Ez::Vlans::Provider::VLAN

Inherits:
Junos::Ez::Vlans::Provider show all
Defined in:
lib/junos-ez/vlans/vlan.rb,
lib/junos-ez/vlans/vlan.rb,
lib/junos-ez/vlans/vlan.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



72
73
74
75
76
77
78
79
80
81
# File 'lib/junos-ez/vlans/vlan.rb', line 72

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



65
66
67
68
69
70
# File 'lib/junos-ez/vlans/vlan.rb', line 65

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)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/junos-ez/vlans/vlan.rb', line 99

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 )
  
  members = got.xpath('vlan/vlan-detail/vlan-member-list/vlan-member')
  ifs_h = {}
  members.each do |port|
    port_name = port.xpath('vlan-member-interface').text.split('.')[0]
    port_h = {}
    port_h[:mode] = port.xpath('vlan-member-port-mode').text.to_sym
    native = (port.xpath('vlan-member-tagness').text == '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.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



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

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




42
43
44
45
46
# File 'lib/junos-ez/vlans/vlan.rb', line 42

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

#xml_change_vlan_id(xml) ⇒ Object



48
49
50
# File 'lib/junos-ez/vlans/vlan.rb', line 48

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.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
# File 'lib/junos-ez/vlans/vlan.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('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('//vlan-member-interface').collect{|ifs| ifs.text.strip }
  as_hash[:interfaces] = nil if as_hash[:interfaces][0] == "None"
  
  return true
end