Class: Junos::Ez::SRX::Apps::Provider
- Inherits:
-
Provider::Parent
- Object
- Provider::Parent
- Junos::Ez::SRX::Apps::Provider
- Defined in:
- lib/junos-ez/srx/apps.rb,
lib/junos-ez/srx/apps.rb
Overview
Provider collection methods
Instance Method Summary collapse
- #_xml_read_parse_destination_port_(text) ⇒ Object
- #build_catalog ⇒ Object
- #build_list ⇒ Object
- #catalog_junos_defaults ⇒ Object
- #list_junos_defaults ⇒ Object
-
#xml_at_top ⇒ Object
————————————————————— XML top placement —————————————————————.
- #xml_change_dst_ports(xml) ⇒ Object
- #xml_change_icmp_code(xml) ⇒ Object
- #xml_change_icmp_type(xml) ⇒ Object
-
#xml_change_proto(xml) ⇒ Object
————————————————————— XML property writers —————————————————————.
- #xml_change_timeout(xml) ⇒ Object
-
#xml_get_has_xml(xml) ⇒ Object
————————————————————— XML readers —————————————————————.
- #xml_read_parser(as_xml, as_hash) ⇒ Object
Instance Method Details
#_xml_read_parse_destination_port_(text) ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/junos-ez/srx/apps.rb', line 76 def _xml_read_parse_destination_port_( text ) if (Float(text) != nil rescue false) text.to_i elsif text =~ /(\d+)-(\d+)/ [ $1.to_i, $2.to_i ] else text end end |
#build_catalog ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/junos-ez/srx/apps.rb', line 128 def build_catalog @catalog = {} @ndev.rpc.get_configuration{|x| x.applications { x.application }}.xpath('applications/application').each do |app| name = app.xpath('name').text @catalog[name] = {} xml_read_parser( app, @catalog[name] ) end @catalog end |
#build_list ⇒ Object
122 123 124 125 126 |
# File 'lib/junos-ez/srx/apps.rb', line 122 def build_list @ndev.rpc.get_configuration{|x| x.applications { x.application(:recurse => 'false') }}.xpath('applications/application/name').collect{ |n| n.text } end |
#catalog_junos_defaults ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/junos-ez/srx/apps.rb', line 146 def catalog_junos_defaults j_catalog = {} @ndev.rpc.get_configuration{|x| x.groups { x.name 'junos-defaults' x.applications { x.application }}}.xpath('//applications/application').each do |app| name = app.xpath('name').text j_catalog[name] = {} xml_read_parser( app, j_catalog[name] ) end j_catalog end |
#list_junos_defaults ⇒ Object
140 141 142 143 144 |
# File 'lib/junos-ez/srx/apps.rb', line 140 def list_junos_defaults @ndev.rpc.get_configuration{|x| x.groups { x.name 'junos-defaults' x.applications { x.application(:recurse => 'false') }}}.xpath('//application/name').collect{ |n| n.text } end |
#xml_at_top ⇒ Object
XML top placement
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/junos-ez/srx/apps.rb', line 7 def xml_at_top Nokogiri::XML::Builder.new{|x| x.configuration{ x.applications { x.application { x.name @name return x } } }} end |
#xml_change_dst_ports(xml) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/junos-ez/srx/apps.rb', line 94 def xml_change_dst_ports( xml ) e_value = ( @should[:dst_ports].kind_of? Array ) ? "#{@should[:dst_ports][0]}-#{@should[:dst_ports][1]}" : @should[:dst_ports] xml_set_or_delete( xml, 'destination-port', e_value ) end |
#xml_change_icmp_code(xml) ⇒ Object
110 111 112 |
# File 'lib/junos-ez/srx/apps.rb', line 110 def xml_change_icmp_code( xml ) xml_set_or_delete( xml, 'icmp-code', @should[:icmp_code] ) end |
#xml_change_icmp_type(xml) ⇒ Object
106 107 108 |
# File 'lib/junos-ez/srx/apps.rb', line 106 def xml_change_icmp_type( xml ) xml_set_or_delete( xml, 'icmp-type', @should[:icmp_type] ) end |
#xml_change_proto(xml) ⇒ Object
XML property writers
90 91 92 |
# File 'lib/junos-ez/srx/apps.rb', line 90 def xml_change_proto( xml ) xml_set_or_delete( xml, 'protocol', @should[:proto] ) end |
#xml_change_timeout(xml) ⇒ Object
102 103 104 |
# File 'lib/junos-ez/srx/apps.rb', line 102 def xml_change_timeout( xml ) xml_set_or_delete( xml, 'inactivity-timeout', @should[:timeout] ) end |
#xml_get_has_xml(xml) ⇒ Object
XML readers
22 23 24 |
# File 'lib/junos-ez/srx/apps.rb', line 22 def xml_get_has_xml( xml ) xml.xpath('//application')[0] end |
#xml_read_parser(as_xml, as_hash) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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 69 70 71 72 73 74 |
# File 'lib/junos-ez/srx/apps.rb', line 26 def xml_read_parser( as_xml, as_hash ) set_has_status( as_xml, as_hash ) xml_when_item(as_xml.xpath('description')){|i| as_hash[:description] = i.text } xml_when_item(as_xml.xpath('protocol')){|i| as_hash[:proto] = i.text } as_hash[:proto] ||= nil xml_when_item(as_xml.xpath('inactivity-timeout')){|i| as_hash[:timeout] = i.text.to_i } if as_hash[:proto] == 'icmp' xml_when_item(as_xml.xpath('icmp-type')){|i| as_hash[:icmp_type] = i.text } xml_when_item(as_xml.xpath('icmp-code')){|i| as_hash[:icmp_code] = i.text } return true end ## check to see if we have a proto. if not, this is a composite application ## definition witha collection of terms. return when done. if as_hash[:proto] == nil terms = [] as_xml.xpath('term').each do |term| term_h = {} term_h[:name] = term.xpath('name').text term_h[:proto] = term.xpath('protocol').text xml_when_item(term.xpath('destination-port')) do |i| term_h[:dst_ports] = _xml_read_parse_destination_port_( i.text ) end terms << term_h end as_hash[:terms] = terms return #!!! end of excution end ### rest of this is for non ICMP xml_when_item(as_xml.xpath('destination-port')) do |i| text = i.text if (Float(text) != nil rescue false) as_hash[:dst_ports] = text.to_i elsif text =~ /(\d+)-(\d+)/ as_hash[:dst_ports] = [ $1.to_i, $2.to_i ] else as_hash[:dst_ports] = text end end return true end |