Class: Junos::Ez::IPports::Provider::CLASSIC

Inherits:
Junos::Ez::IPports::Provider show all
Defined in:
lib/junos-ez/ip_ports/classic.rb,
lib/junos-ez/ip_ports/classic.rb

Overview


Provider collection 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, #write!, #xml_at_edit, #xml_build_change, #xml_change__active, #xml_change__exist, #xml_change_admin, #xml_change_description, #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



99
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
# File 'lib/junos-ez/ip_ports/classic.rb', line 99

def build_catalog
  @catalog = {}

  ## do the equivalent of "show interfaces ..." to retrieve the list
  ## of known interfaces that have an IFA == 'inet'.  Note that this
  ## list will *not* include anything that has been deactivated.
  
  ifa_list = from_junos_get_ifa_xml
  
  ## from this list of IFA, retrieve the configurations
  
  got_xml_cfg = @ndev.rpc.get_configuration do |cfg|
    cfg.interfaces {
      ifa_list.each do |ifa|
        ifa_name = ifa.xpath('name').text.strip
        ifa_ifd, ifa_ifl = ifa_name.split '.'
        cfg.interface { 
          cfg.name ifa_ifd 
          cfg.unit { cfg.name ifa_ifl }
        }
      end
    }
  end    
  
  ## now create the object property hashes for each of the instances
  
  got_xml_cfg.xpath('interfaces/interface/unit').each do |ifl|      
    ifd = ifl.xpath('preceding-sibling::name').text.strip
    unit = ifl.xpath('name').text.strip
    obj_name = ifd + '.' + unit
    
    @catalog[obj_name] = {}
    xml_read_parser( ifl, @catalog[obj_name] )
  end
  
  return @catalog
end

#build_listObject



93
94
95
96
97
# File 'lib/junos-ez/ip_ports/classic.rb', line 93

def build_list            
  from_junos_get_ifa_xml.collect do |ifa|
    ifa.xpath('name').text.strip
  end                
end

#xml_at_topObject


XML top placement




7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/junos-ez/ip_ports/classic.rb', line 7

def xml_at_top    
  
  # if just the IFD is given as the name, default to unit "0"
  @ifd, @ifl = @name.split '.'
  @ifl ||= "0"
  
  Nokogiri::XML::Builder.new{ |x| x.configuration{ 
    x.interfaces { x.interface { x.name @ifd
      x.unit {
        x.name @ifl
        return x
      }
    }}
  }}
end

#xml_change_address(xml) ⇒ Object


XML writers




62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/junos-ez/ip_ports/classic.rb', line 62

def xml_change_address( xml )
  xml.family { xml.inet {
    if @has[:address]
      xml.address( Netconf::JunosConfig::DELETE ) {
        xml.name @has[:address]
      }
    end
    xml.address { 
      xml.name @should[:address] 
    }
  }}
end

#xml_change_mtu(xml) ⇒ Object



79
80
81
82
83
# File 'lib/junos-ez/ip_ports/classic.rb', line 79

def xml_change_mtu( xml )
  xml.family { xml.inet {
    xml_set_or_delete( xml, 'mtu', @should[:mtu] )
  }}
end

#xml_change_tag_id(xml) ⇒ Object



75
76
77
# File 'lib/junos-ez/ip_ports/classic.rb', line 75

def xml_change_tag_id( xml )
  xml_set_or_delete( xml, 'vlan-id', @should[:tag_id] )
end

#xml_element_rename(new_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/junos-ez/ip_ports/classic.rb', line 23

def xml_element_rename( new_name )
  
  # if just the IFD is given as the name, default to unit "0"
  n_ifd, n_ifl = new_name.split '.'
  n_ifl ||= "0"
  
  # do not allow rename to different IFD.
  return false unless @ifd == n_ifd
  
  # return the new element name
  return n_ifl
end

#xml_get_has_xml(xml) ⇒ Object


XML readers




40
41
42
# File 'lib/junos-ez/ip_ports/classic.rb', line 40

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

#xml_read_parser(as_xml, as_hash) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/junos-ez/ip_ports/classic.rb', line 44

def xml_read_parser( as_xml, as_hash )
  set_has_status( as_xml, as_hash )    
  
  ifa_inet = as_xml.xpath('family/inet')
  
  as_hash[:tag_id] = as_xml.xpath('vlan-id').text.to_i
  as_hash[:description] = as_xml.xpath('description').text
  as_hash[:mtu] = ifa_inet.xpath('mtu').text.to_i || nil
  as_hash[:address] = ifa_inet.xpath('address/name').text || nil
  as_hash[:admin] = as_xml.xpath('disable').empty? ? :up : :down
  
  return true
end