Class: Junos::Ez::SRX::AddressBookEntries::Provider
- Inherits:
-
Provider::Parent
- Object
- Provider::Parent
- Junos::Ez::SRX::AddressBookEntries::Provider
- Defined in:
- lib/junos-ez/srx/abooke.rb,
lib/junos-ez/srx/abooke.rb,
lib/junos-ez/srx/abooke.rb,
lib/junos-ez/srx/abooke.rb
Overview
Provider operational methods
Instance Method Summary collapse
- #build_catalog ⇒ Object
- #build_list ⇒ Object
- #find(addr) ⇒ Object
- #lpm_find(addr) ⇒ Object
-
#to_h_expanded(opts = {}) ⇒ Object
—————————————————– create a Hash from the existing provider information —————————————————–.
-
#xml_at_top ⇒ Object
————————————————————— XML top placement —————————————————————.
-
#xml_change_ip_prefix(xml) ⇒ Object
————————————————————— XML writers —————————————————————.
- #xml_element_top(xml, name) ⇒ Object
-
#xml_from_h_expanded(from_hash, opts = {}) ⇒ Object
—————————————————————- create the XML for a complete policy rules set given a Hash structure the mimics the provider and properties for the Policy and associated PolicyRules —————————————————————-.
-
#xml_get_has_xml(xml) ⇒ Object
————————————————————— XML readers —————————————————————.
- #xml_read_parser(as_xml, as_hash) ⇒ Object
Instance Method Details
#build_catalog ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/junos-ez/srx/abooke.rb', line 78 def build_catalog @catalog = {} @ndev.rpc.get_configuration{ |x| x.security { x.zones { x.send(:'security-zone') { x.name @parent.name x.send(:'address-book') { x.address } } }} }.xpath('//address').each{ |adr| name = adr.xpath('name').text @catalog[name] = {} xml_read_parser( adr, @catalog[name] ) } @catalog end |
#build_list ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/junos-ez/srx/abooke.rb', line 64 def build_list @ndev.rpc.get_configuration{ |x| x.security { x.zones { x.send(:'security-zone') { x.name @parent.name x.send(:'address-book') { x.address({:recurse => 'false' }) } } }} }.xpath('//address/name').collect{ |adr_name| adr_name.text } end |
#find(addr) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/junos-ez/srx/abooke.rb', line 156 def find( addr ) lpm_cache_create! # turn the given string into a searchable IPAddress object find_addr = IPAddress( addr ) # search the cache for a matching item found = @zab_lpm_cache.select{ |name, ab_addr, ipadr| ipadr.include? find_addr } return nil if found.empty? # return a sorted result with highest prefix first found.sort_by{ |n,a,ip| ip.prefix }.reverse! end |
#lpm_find(addr) ⇒ Object
173 174 175 176 |
# File 'lib/junos-ez/srx/abooke.rb', line 173 def lpm_find( addr ) return nil unless found = find( addr ) found[0] end |
#to_h_expanded(opts = {}) ⇒ Object
create a Hash from the existing provider information
109 110 111 112 113 |
# File 'lib/junos-ez/srx/abooke.rb', line 109 def ( opts = {} ) { :name => @parent.name, # zone name :addrs => catalog } end |
#xml_at_top ⇒ Object
XML top placement
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/junos-ez/srx/abooke.rb', line 13 def xml_at_top Nokogiri::XML::Builder.new{ |x| x.configuration{ x.security { x.zones { x.send(:'security-zone') { x.name @parent.name x.send(:'address-book') { x.address { x.name @name return x } } } }} }} end |
#xml_change_ip_prefix(xml) ⇒ Object
XML writers
52 53 54 |
# File 'lib/junos-ez/srx/abooke.rb', line 52 def xml_change_ip_prefix( xml ) xml_set_or_delete( xml, 'ip-prefix', @should[:ip_prefix] ) end |
#xml_element_top(xml, name) ⇒ Object
27 28 29 30 31 |
# File 'lib/junos-ez/srx/abooke.rb', line 27 def xml_element_top( xml, name ) xml.address { xml.name @name return xml } end |
#xml_from_h_expanded(from_hash, opts = {}) ⇒ Object
create the XML for a complete policy rules set given a Hash structure the mimics the provider and properties for the Policy and associated PolicyRules
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/junos-ez/srx/abooke.rb', line 121 def ( from_hash, opts = {} ) zone_name = from_hash[:name] raise ArgumentError, "zone-name as :name not provided in hash" unless zone_name ## handle the case where 'self' is either a provider or a specific instance. zone_pvd = self.is_provider? ? Junos::Ez::SRX::Zones::Provider.new( @ndev, zone_name ) : @parent xml_top = zone_pvd.xml_at_top xml_top.send(:'address-book') xml_add_here = xml_top.parent.at('address-book') ## now create objects and process the hash data accordingly from_hash[:addrs].each do |name, hash| Nokogiri::XML::Builder.with( xml_add_here ) do |xml| # create the new object so we can generate XML on it adr = self.class.new( @ndev, name, :parent => zone_pvd ) # generate the object specific XML inside adr.should = hash adr_xml = adr.xml_element_top( xml, name ) adr.xml_build_change( adr_xml ) end end xml_top.doc.root end |
#xml_get_has_xml(xml) ⇒ Object
XML readers
37 38 39 |
# File 'lib/junos-ez/srx/abooke.rb', line 37 def xml_get_has_xml( xml ) xml.xpath('//address')[0] end |
#xml_read_parser(as_xml, as_hash) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/junos-ez/srx/abooke.rb', line 41 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 } as_hash[:ip_prefix] = as_xml.xpath('ip-prefix').text true end |