Class: Rbeapi::Api::Acl
Overview
The Acl class manages the set of standard ACLs.
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_entry(name, entry) ⇒ Boolean
add_entry will add an entry to the specified ACL with the passed in parameters.
-
#create(name) ⇒ Boolean
create will create a new ACL resource in the nodes current configuration with the specified name.
-
#default(name) ⇒ Boolean
default will configure the ACL using the default keyword.
-
#delete(name) ⇒ Boolean
delete will delete an existing ACL resource from the nodes current running configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the specified ACL from the nodes current configuration.
-
#getall ⇒ nil, Hash<Symbol, Object>
getall returns the collection of ACLs from the nodes running configuration as a hash.
-
#initialize(node) ⇒ Acl
constructor
A new instance of Acl.
-
#mask_to_prefixlen(mask) ⇒ String
mask_to_prefixlen converts a subnet mask from dotted decimal to bit length.
-
#remove_entry(name, seqno) ⇒ Boolean
remove_entry will remove the entry specified by the seqno for the ACL specified by name.
-
#update_entry(name, entry) ⇒ Boolean
update_entry will update an entry, identified by the seqno in the ACL specified by name, with the passed in parameters.
Methods inherited from Entity
#command_builder, #configure, #configure_interface, #get_block, instance
Constructor Details
#initialize(node) ⇒ Acl
Returns a new instance of Acl.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rbeapi/api/acl.rb', line 44 def initialize(node) super(node) @entry_re = Regexp.new(%r{(\d+) (?:\ ([p|d]\w+)) (?:\ (any))? (?:\ (host))? (?:\ ([0-9]+(?:\.[0-9]+){3}))? (?:/([0-9]{1,2}))? (?:\ ([0-9]+(?:\.[0-9]+){3}))? (?:\ (log))?}x) end |
Instance Method Details
#add_entry(name, entry) ⇒ Boolean
add_entry will add an entry to the specified ACL with the passed in parameters.
252 253 254 255 256 257 |
# File 'lib/rbeapi/api/acl.rb', line 252 def add_entry(name, entry) cmds = ["ip access-list standard #{name}"] cmds << build_entry(entry) cmds << 'exit' configure(cmds) end |
#create(name) ⇒ Boolean
create will create a new ACL resource in the nodes current configuration with the specified name. If the create method is called and the ACL already exists, this method will still return true. The ACL will not have any entries. Use add_entry to add entries to the ACL.
147 148 149 |
# File 'lib/rbeapi/api/acl.rb', line 147 def create(name) configure("ip access-list standard #{name}") end |
#default(name) ⇒ Boolean
default will configure the ACL using the default keyword. This command has the same effect as deleting the ACL from the nodes running configuration.
182 183 184 |
# File 'lib/rbeapi/api/acl.rb', line 182 def default(name) configure("default ip access-list standard #{name}") end |
#delete(name) ⇒ Boolean
delete will delete an existing ACL resource from the nodes current running configuration. If the delete method is called and the ACL does not exist, this method will succeed.
164 165 166 |
# File 'lib/rbeapi/api/acl.rb', line 164 def delete(name) configure("no ip access-list standard #{name}") end |
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the specified ACL from the nodes current configuration.
63 64 65 66 67 68 |
# File 'lib/rbeapi/api/acl.rb', line 63 def get(name) config = get_block("ip access-list standard #{name}") return nil unless config parse_entries(config) end |
#getall ⇒ nil, Hash<Symbol, Object>
getall returns the collection of ACLs from the nodes running configuration as a hash. The ACL resource collection hash is keyed by the ACL name.
79 80 81 82 83 84 85 |
# File 'lib/rbeapi/api/acl.rb', line 79 def getall acls = config.scan(/ip access-list standard ([^\s]+)/) acls.each_with_object({}) do |name, hsh| resource = get(name[0]) hsh[name[0]] = resource if resource end end |
#mask_to_prefixlen(mask) ⇒ String
mask_to_prefixlen converts a subnet mask from dotted decimal to bit length
94 95 96 97 |
# File 'lib/rbeapi/api/acl.rb', line 94 def mask_to_prefixlen(mask) mask = '255.255.255.255' unless mask NetAddr::CIDR.create('0.0.0.0/' + mask).netmask_ext end |
#remove_entry(name, seqno) ⇒ Boolean
remove_entry will remove the entry specified by the seqno for the ACL specified by name.
270 271 272 273 |
# File 'lib/rbeapi/api/acl.rb', line 270 def remove_entry(name, seqno) cmds = ["ip access-list standard #{name}", "no #{seqno}", 'exit'] configure(cmds) end |
#update_entry(name, entry) ⇒ Boolean
update_entry will update an entry, identified by the seqno in the ACL specified by name, with the passed in parameters.
228 229 230 231 232 233 234 |
# File 'lib/rbeapi/api/acl.rb', line 228 def update_entry(name, entry) cmds = ["ip access-list standard #{name}"] cmds << "no #{entry[:seqno]}" cmds << build_entry(entry) cmds << 'exit' configure(cmds) end |