Class: Rbeapi::Api::Entity
- Inherits:
-
Object
- Object
- Rbeapi::Api::Entity
- Defined in:
- lib/rbeapi/api.rb
Direct Known Subclasses
Aaa, AaaGroups, BaseInterface, Dns, Interfaces, Ipinterfaces, Logging, Mlag, MlagInterfaces, Ntp, Ospf, OspfInterfaces, Prefixlists, Radius, Routemaps, Snmp, Staticroute, Stp, StpInstances, StpInterfaces, Switchports, System, Tacacs, Varp, VarpInterfaces, Vlans, 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
The instance class method is used to create a new instance of the object.
Instance Method Summary collapse
-
#configure(commands) ⇒ Boolean
Method called to send configuration commands to the node.
-
#get_block(text) ⇒ Object
Returns a block of configuration from the current running config as a string.
-
#initialize(node, opts = {}) ⇒ Entity
constructor
The Entity class provides a base class implementation for building API modules.
Constructor Details
#initialize(node, opts = {}) ⇒ Entity
The Entity class provides a base class implementation for building API modules. The Entity class is typcially not instantiated directly but serves as a super class with convenience methods used to work with the node.
64 65 66 |
# File 'lib/rbeapi/api.rb', line 64 def initialize(node, opts = {}) @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
74 75 76 |
# File 'lib/rbeapi/api.rb', line 74 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
84 85 86 |
# File 'lib/rbeapi/api.rb', line 84 def error @error end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
42 43 44 |
# File 'lib/rbeapi/api.rb', line 42 def node @node end |
Class Method Details
.instance(node) ⇒ Object
The instance class method is used to create a new instance of the object. It works in conjunction with the Node.api loader method to make it easy to load classes derived from Entity
51 52 53 |
# File 'lib/rbeapi/api.rb', line 51 def self.instance(node) new(node) end |
Instance Method Details
#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.
124 125 126 127 128 129 130 131 |
# File 'lib/rbeapi/api.rb', line 124 def configure(commands) begin @node.config(commands) return true rescue Rbeapi::Eapilib::CommandError, Rbeapi::Eapilib::ConnectionError return false end end |
#get_block(text) ⇒ Object
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.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbeapi/api.rb', line 99 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_end - block_start config[block_start, block_end] end |