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.
326 327 328 329 330 331 |
# File 'lib/rbeapi/api/acl.rb', line 326 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.
Commands
ip access-list standard <name>
205 206 207 |
# File 'lib/rbeapi/api/acl.rb', line 205 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.
Commands
default no ip access-list standard <name>
240 241 242 |
# File 'lib/rbeapi/api/acl.rb', line 240 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.
Commands
no ip access-list standard <name>
222 223 224 |
# File 'lib/rbeapi/api/acl.rb', line 222 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.
82 83 84 85 86 87 |
# File 'lib/rbeapi/api/acl.rb', line 82 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.
137 138 139 140 141 142 143 |
# File 'lib/rbeapi/api/acl.rb', line 137 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.
152 153 154 155 |
# File 'lib/rbeapi/api/acl.rb', line 152 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.
345 346 347 348 |
# File 'lib/rbeapi/api/acl.rb', line 345 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.
297 298 299 300 301 302 303 |
# File 'lib/rbeapi/api/acl.rb', line 297 def update_entry(name, entry) cmds = ["ip access-list standard #{name}"] cmds << "no #{entry[:seqno]}" cmds << build_entry(entry) cmds << 'exit' configure(cmds) end |