Class: Junos::Ez::IPports::Provider::CLASSIC
Overview
Provider collection methods
Instance Attribute Summary
#catalog, #has, #list, #name, #ndev, #parent, #properties, #providers, #should
Instance Method Summary
collapse
#[], #[]=, #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
Instance Method Details
#build_catalog ⇒ Object
134
135
136
137
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
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 134
def build_catalog
@catalog = {}
ifa_list = from_junos_get_ifa_xml
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
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_list ⇒ Object
128
129
130
131
132
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 128
def build_list
from_junos_get_ifa_xml.collect do |ifa|
ifa.xpath('name').text.strip
end
end
|
#status ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 109
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_top ⇒ Object
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
@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
90
91
92
93
94
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 90
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
96
97
98
99
100
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 96
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
70
71
72
73
74
75
76
77
78
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 70
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
84
85
86
87
88
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 84
def xml_change_mtu( xml )
xml.family { xml.inet {
xml_set_or_delete( xml, 'mtu', @should[:mtu] )
}}
end
|
#xml_change_tag_id(xml) ⇒ Object
80
81
82
|
# File 'lib/junos-ez/ip_ports/classic.rb', line 80
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 )
n_ifd, n_ifl = new_name.split '.'
n_ifl ||= "0"
return false unless @ifd == n_ifd
return n_ifl
end
|
#xml_get_has_xml(xml) ⇒ Object
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
|
# 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 }
as_hash[:address] = ifa_inet.xpath('address/name').text || nil
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
|