Class: Rbeapi::Api::Entity
- Inherits:
-
Object
- Object
- Rbeapi::Api::Entity
- Defined in:
- lib/rbeapi/api.rb
Overview
The Entity class provides a base class implementation for building API modules. The Entity class is typically not instantiated directly but serves as a super class with convenience methods used to work with the node.
Direct Known Subclasses
Aaa, AaaGroups, Acl, Alias, BaseInterface, Bgp, BgpNeighbors, Dns, Interfaces, Iphosts, Ipinterfaces, Logging, Managementdefaults, Mlag, Ntp, Ospf, OspfInterfaces, Prefixlists, Radius, Routemaps, Snmp, Staticroutes, Stp, StpInstances, StpInterfaces, Switchports, System, Tacacs, Users, Varp, VarpInterfaces, Vlans, Vrrp, Netdev::Snmp
Instance Attribute Summary collapse
-
#config ⇒ String
readonly
Returns the running configuration from the node instance.
-
#error ⇒ Rbeapi::Eapilib::CommandError
readonly
Provides a convenience method for access the connection error (if one exists) of the node’s connection instance.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Class Method Summary collapse
-
.instance(node) ⇒ Object
Construct the node.
Instance Method Summary collapse
-
#command_builder(cmd, opts = {}) ⇒ String
Method called to build the correct version of a command based on the modifier options.
-
#configure(commands) ⇒ Boolean
Method called to send configuration commands to the node.
-
#configure_interface(name, commands) ⇒ Boolean
configure_interface sends the commands over eAPI to the destination node to configure a specific interface.
-
#get_block(text) ⇒ nil, String
Returns a block of configuration from the current running config as a string.
-
#initialize(node) ⇒ Entity
constructor
The Entity class provides a base class implementation for building API modules.
Constructor Details
#initialize(node) ⇒ Entity
The Entity class provides a base class implementation for building API modules. The Entity class is typically not instantiated directly but serves as a super class with convenience methods used to work with the node.
68 69 70 |
# File 'lib/rbeapi/api.rb', line 68 def initialize(node) @node = node end |
Instance Attribute Details
#config ⇒ String (readonly)
Returns the running configuration from the node instance. This is a convenience method to easily access the current running config from an API module.
78 79 80 |
# File 'lib/rbeapi/api.rb', line 78 def config @config end |
#error ⇒ Rbeapi::Eapilib::CommandError (readonly)
Provides a convenience method for access the connection error (if one exists) of the node’s connection instance.
88 89 90 |
# File 'lib/rbeapi/api.rb', line 88 def error @error end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
48 49 50 |
# File 'lib/rbeapi/api.rb', line 48 def node @node end |
Class Method Details
.instance(node) ⇒ Object
Construct the node.
55 56 57 |
# File 'lib/rbeapi/api.rb', line 55 def self.instance(node) new(node) end |
Instance Method Details
#command_builder(cmd, opts = {}) ⇒ String
Method called to build the correct version of a command based on the modifier options. If value option is set then it is appended to the command. If the enable option is false then the ‘no’ keyword is prefixed to the command. If the default value is provided and set to true, then the default keyword is used. If both options are provided, then default option takes precedence.
158 159 160 161 162 163 164 165 |
# File 'lib/rbeapi/api.rb', line 158 def command_builder(cmd, opts = {}) enable = opts.fetch(:enable, true) default = opts.fetch(:default, false) cmd << " #{opts[:value]}" if opts[:value] return "default #{cmd}" if default return "no #{cmd}" unless enable cmd end |
#configure(commands) ⇒ Boolean
Method called to send configuration commands to the node. This method will send the commands to the node and rescue from CommandError or ConnectionError.
128 129 130 131 132 133 |
# File 'lib/rbeapi/api.rb', line 128 def configure(commands) @node.config(commands) return true rescue Rbeapi::Eapilib::CommandError, Rbeapi::Eapilib::ConnectionError return false end |
#configure_interface(name, commands) ⇒ Boolean
configure_interface sends the commands over eAPI to the destination node to configure a specific interface.
178 179 180 181 182 |
# File 'lib/rbeapi/api.rb', line 178 def configure_interface(name, commands) commands = [*commands] commands.insert(0, "interface #{name}") configure commands end |
#get_block(text) ⇒ nil, String
Returns a block of configuration from the current running config as a string. The argument is used to search the config and return the text along with any child configuration statements.
103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rbeapi/api.rb', line 103 def get_block(text) mdata = /^#{text}$/.match(config) return nil unless mdata block_start, line_end = mdata.offset(0) mdata = /^[^\s]/.match(config, line_end) return nil unless mdata _, block_end = mdata.offset(0) block_end -= block_start config[block_start, block_end] end |