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,
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, #with, #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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/junos-ez/ip_ports/classic.rb', line 138

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



132
133
134
135
136
# File 'lib/junos-ez/ip_ports/classic.rb', line 132

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

#statusObject



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/junos-ez/ip_ports/classic.rb', line 113

def status
  got = @ndev.rpc.get_interface_information( :interface_name => @ifd+'.'+@ifd_unit )
  ifs = got.xpath('logical-interface')[0]  
  ret_h = {}
  ret_h[:l1_oper_status] = (ifs.xpath('if-config-flags/iff-device-down')[0]) ? :down : :up
  ret_h[:oper_status] = (ifs.xpath('address-family//ifaf-down')[0]) ? :down : :up    
  ret_h[:snmp_index] = ifs.xpath('snmp-index').text.to_i
  ret_h[:packets_rx] = ifs.xpath('traffic-statistics/input-packets').text.to_i
  ret_h[:packets_tx] = ifs.xpath('traffic-statistics/output-packets').text.to_i
  ret_h
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, @ifd_unit = @name.split '.'
  @ifd_unit ||= "0"
  
  Nokogiri::XML::Builder.new{ |x| x.configuration{ 
    x.interfaces { x.interface { x.name @ifd
      x.unit {
        x.name @ifd_unit
        return x
      }
    }}
  }}
end

#xml_change_acl_in(xml) ⇒ Object



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

def xml_change_acl_in( xml )
  xml.family { xml.inet { xml.filter { xml.input {
    xml_set_or_delete( xml, 'filter-name', @should[:acl_in] )
  }}}}
end

#xml_change_acl_out(xml) ⇒ Object



100
101
102
103
104
# File 'lib/junos-ez/ip_ports/classic.rb', line 100

def xml_change_acl_out( xml )
  xml.family { xml.inet { xml.filter { xml.output {
    xml_set_or_delete( xml, 'filter-name', @should[:acl_out] )      
  }}}}    
end

#xml_change_address(xml) ⇒ Object


XML writers




74
75
76
77
78
79
80
81
82
# File 'lib/junos-ez/ip_ports/classic.rb', line 74

def xml_change_address( xml )
  xml.family { xml.inet {
    # delete the old address and replace it with the new one ...
    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



88
89
90
91
92
# File 'lib/junos-ez/ip_ports/classic.rb', line 88

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

#xml_change_tag_id(xml) ⇒ Object



84
85
86
# File 'lib/junos-ez/ip_ports/classic.rb', line 84

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
57
58
59
60
61
62
63
64
65
66
67
68
# 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 )    

  as_hash[:admin] = as_xml.xpath('disable').empty? ? :up : :down    
  ifa_inet = as_xml.xpath('family/inet')
  
  xml_when_item(as_xml.xpath('vlan-id')){ |i| as_hash[:tag_id] = i.text.to_i }
  xml_when_item(as_xml.xpath('description')){ |i| as_hash[:description] = i.text }
  xml_when_item(ifa_inet.xpath('mtu')){ |i| as_hash[:mtu] = i.text.to_i }   
  
  # The address could be a list.
  address = []
  ifa_inet.xpath('address').each do |addr|
    address << addr.xpath('name').text
  end
  as_hash[:address] = address || nil
  
  # check for firewall-filters (aka ACLs)
  if (fw_acl = ifa_inet.xpath('filter')[0])
    xml_when_item( fw_acl.xpath('input/filter-name')){ |i| as_hash[:acl_in] = i.text.strip }
    xml_when_item( fw_acl.xpath('output/filter-name')){ |i| as_hash[:acl_out] = i.text.strip }
  end
  
  return true
end