rbeapi 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/.gitignore +35 -0
  2. data/Gemfile +25 -0
  3. data/Guardfile +15 -0
  4. data/LICENSE +28 -0
  5. data/README.md +218 -0
  6. data/Rakefile +12 -0
  7. data/lib/rbeapi.rb +32 -0
  8. data/lib/rbeapi/api.rb +135 -0
  9. data/lib/rbeapi/api/aaa.rb +410 -0
  10. data/lib/rbeapi/api/dns.rb +198 -0
  11. data/lib/rbeapi/api/interfaces.rb +1193 -0
  12. data/lib/rbeapi/api/ipinterfaces.rb +328 -0
  13. data/lib/rbeapi/api/logging.rb +157 -0
  14. data/lib/rbeapi/api/mlag.rb +519 -0
  15. data/lib/rbeapi/api/ntp.rb +201 -0
  16. data/lib/rbeapi/api/ospf.rb +214 -0
  17. data/lib/rbeapi/api/prefixlists.rb +98 -0
  18. data/lib/rbeapi/api/radius.rb +317 -0
  19. data/lib/rbeapi/api/radius.rb.old +399 -0
  20. data/lib/rbeapi/api/routemaps.rb +100 -0
  21. data/lib/rbeapi/api/snmp.rb +427 -0
  22. data/lib/rbeapi/api/staticroutes.rb +88 -0
  23. data/lib/rbeapi/api/stp.rb +381 -0
  24. data/lib/rbeapi/api/switchports.rb +272 -0
  25. data/lib/rbeapi/api/system.rb +87 -0
  26. data/lib/rbeapi/api/tacacs.rb +236 -0
  27. data/lib/rbeapi/api/varp.rb +181 -0
  28. data/lib/rbeapi/api/vlans.rb +338 -0
  29. data/lib/rbeapi/client.rb +454 -0
  30. data/lib/rbeapi/eapilib.rb +334 -0
  31. data/lib/rbeapi/netdev/snmp.rb +370 -0
  32. data/lib/rbeapi/utils.rb +70 -0
  33. data/lib/rbeapi/version.rb +37 -0
  34. data/rbeapi.gemspec +32 -0
  35. data/spec/fixtures/dut.conf +5 -0
  36. data/spec/spec_helper.rb +22 -0
  37. data/spec/support/fixtures.rb +114 -0
  38. data/spec/support/shared_examples_for_api_modules.rb +124 -0
  39. data/spec/system/api_ospf_interfaces_spec.rb +58 -0
  40. data/spec/system/api_ospf_spec.rb +111 -0
  41. data/spec/system/api_varp_interfaces_spec.rb +60 -0
  42. data/spec/system/api_varp_spec.rb +44 -0
  43. data/spec/system/rbeapi/api/dns_spec.rb +77 -0
  44. data/spec/system/rbeapi/api/interfaces_base_spec.rb +94 -0
  45. data/spec/system/rbeapi/api/interfaces_ethernet_spec.rb +135 -0
  46. data/spec/system/rbeapi/api/interfaces_portchannel_spec.rb +188 -0
  47. data/spec/system/rbeapi/api/interfaces_vxlan_spec.rb +115 -0
  48. data/spec/system/rbeapi/api/ipinterfaces_spec.rb +97 -0
  49. data/spec/system/rbeapi/api/logging_spec.rb +65 -0
  50. data/spec/system/rbeapi/api/mlag_interfaces_spec.rb +80 -0
  51. data/spec/system/rbeapi/api/mlag_spec.rb +94 -0
  52. data/spec/system/rbeapi/api/ntp_spec.rb +76 -0
  53. data/spec/system/rbeapi/api/snmp_spec.rb +68 -0
  54. data/spec/system/rbeapi/api/stp_instances_spec.rb +61 -0
  55. data/spec/system/rbeapi/api/stp_interfaces_spec.rb +71 -0
  56. data/spec/system/rbeapi/api/stp_spec.rb +57 -0
  57. data/spec/system/rbeapi/api/switchports_spec.rb +135 -0
  58. data/spec/system/rbeapi/api/system_spec.rb +38 -0
  59. data/spec/system/rbeapi/api/vlans_spec.rb +121 -0
  60. metadata +274 -0
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+ /backup/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalisation:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,25 @@
1
+ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
2
+
3
+ gem 'net_http_unix'
4
+ gem 'inifile'
5
+
6
+ group :development do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-rubocop'
10
+ gem 'guard-shell'
11
+ end
12
+
13
+ group :development, :test do
14
+ gem 'rake', '~> 10.1.0'
15
+ gem 'rspec', '~> 3.0.0'
16
+ gem 'rspec-mocks', '~> 3.0.0'
17
+ gem 'simplecov'
18
+ gem 'yard'
19
+ gem 'redcarpet', '~> 3.1.2'
20
+ gem 'pry', require: false
21
+ gem 'pry-doc', require: false
22
+ gem 'pry-stack_explorer', require: false
23
+ end
24
+
25
+ # vim:ft=ruby
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ # A sample Guardfile
4
+ # More info at https://github.com/guard/guard#readme
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ watch(/^spec\/.+_spec\.rb$/)
8
+ watch(/^lib\/(.+)\.rb$/) { |m| "spec/unit/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { 'spec' }
10
+ end
11
+
12
+ guard :rubocop do
13
+ watch(/.+\.rb$/)
14
+ watch(/(?:.+\/)?\.rubocop\.yml$/) { |m| File.dirname(m[0]) }
15
+ end
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2015, Arista Networks EOS+
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of rbeapi nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
data/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # Arista eAPI Ruby Library
2
+
3
+ #### Table of Contents
4
+
5
+ 1. [Overview] (#overview)
6
+ * [Requirements] (#requirements)
7
+ 2. [Getting Started] (#getting-started)
8
+ 3. [Installation] (#installation)
9
+ 5. [Contributing] (#contributing)
10
+ 6. [License] (#license)
11
+
12
+
13
+ The Ruby Cliet for eAPI provides a native Ruby implementation for programming Arista EOS network devices using Ruby. The Ruby client provides the ability to build native applications in Ruby that can communicate with EOS either locally via Unix domain sockets (on-box) or remotely over a HTTP/S transport (off-box). It uses a standard INI-style configuration file to specifiy one or more connection profiles.
14
+
15
+ The rbeapi implemenation also provides an API layer for building native Ruby objects that allow for configuration and state extraction of EOS nodes. The API layer provides a consistent implementation for working with EOS configuration resources. The implementation of the API layer is highly extensible and can be used as a foundation for building custom data models.
16
+
17
+ The libray is freely provided to the open source community for building robust applications using Arista EOS eAPI. Support is provided as best effort through Github iusses.
18
+
19
+ ## Requirements
20
+
21
+ * Arista EOS 4.12 or later
22
+ * Arista eAPI enabled for at least one transport (see official EOS Config Guide at arista.com for details)
23
+ * Ruby 1.9.3 or later
24
+
25
+ # Getting Started
26
+ In order to use rbeapi, the EOS command API must be enabled using ``management
27
+ api http-commands`` configuration mode. This library supports eAPI calls over
28
+ both HTTP and UNIX Domain Sockets. Once the command API is enabled on the
29
+ destination node, create a configuration file with the node properities.
30
+
31
+ **Note:** The default search path for the conf file is ``~/.eapi.conf``
32
+ followed by ``/mnt/flash/eapi.conf``. This can be overridden by setting
33
+ ``EAPI_CONF=<path file conf file>`` in your environment.
34
+
35
+ ## Example eapi.conf File
36
+ Below is an example of an eAPI conf file. The conf file can contain more than
37
+ one node. Each node section must be prefaced by **connection:\<name\>** where
38
+ \<name\> is the name of the connection.
39
+
40
+ The following configuration options are available for defining node entries:
41
+
42
+ * **host** - The IP address or FQDN of the remote device. If the host
43
+ parameter is omitted then the connection name is used
44
+ * **username** - The eAPI username to use for authentication (only required for
45
+ http or https connections)
46
+ * **password** - The eAPI password to use for authentication (only required for
47
+ http or https connections)
48
+ * **enablepwd** - The enable mode password if required by the destination node
49
+ * **transport** - Configures the type of transport connection to use. The
50
+ default value is _https_. Valid values are:
51
+ * socket (available in EOS 4.14.5 or later)
52
+ * http_local (available in EOS 4.14.5 or later)
53
+ * http
54
+ * https
55
+ * **port** - Configures the port to use for the eAPI connection. A default
56
+ port is used if this parameter is absent, based on the transport setting
57
+ using the following values:
58
+ * transport: http, default port: 80
59
+ * transport: https, deafult port: 443
60
+ * transport: https_local, default port: 8080
61
+ * transport: socket, default port: n/a
62
+
63
+
64
+ _Note:_ See the EOS User Manual found at arista.com for more details on
65
+ configuring eAPI values.
66
+
67
+ All configuration values are optional.
68
+
69
+ ```
70
+ [connection:veos01]
71
+ username: eapi
72
+ password: password
73
+ transport: http
74
+
75
+ [connection:veos02]
76
+ transport: http
77
+
78
+ [connection:veos03]
79
+ transport: socket
80
+
81
+ [connection:veos04]
82
+ host: 172.16.10.1
83
+ username: eapi
84
+ password: password
85
+ enablepwd: itsasecret
86
+ port: 1234
87
+ transport: https
88
+
89
+ [connection:localhost]
90
+ transport: http_local
91
+ ```
92
+
93
+ The above example shows different ways to define EOS node connections. All
94
+ configuration options will attempt to use default values if not explicitly
95
+ defined. If the host parameter is not set for a given entry, then the
96
+ connection name will be used as the host address.
97
+
98
+ ### Configuring \[connection:localhost]
99
+
100
+ The rbeapi library automatically installs a single default configuration entry
101
+ for connecting to localhost host using a transport of sockets. If using the
102
+ rbeapi library locally on an EOS node, simply enable the command API to use
103
+ sockets and no further configuration is needed for rbeapi to function. If you
104
+ specify an entry in a conf file with the name ``[connection:localhost]``, the
105
+ values in the conf file will overwrite the default.
106
+
107
+ ## Using rbeapi
108
+ The Ruby Client for eAPI was designed to be easy to use and implement for
109
+ writing tools and applications that interface with the Arista EOS management
110
+ plane.
111
+
112
+ ### Creating a connection and sending commands
113
+ Once EOS is configured properly and the config file created, getting started
114
+ with a connection to EOS is simple. Below demonstrates a basic connection
115
+ using rbeapi. For more examples, please see the examples folder.
116
+
117
+ ```
118
+ # start by importing the library
119
+ require 'rbeapi/client'
120
+
121
+ # create a node object by specifying the node to work with
122
+ node = Rbeap::Client.connect_to('veos01')
123
+
124
+ # send one or more commands to the node
125
+ node.eanble('show hostname')
126
+ node.enable('show hostname')
127
+ => [{:command=>"show hostname", :result=>{"fqdn"=>"veos01.arista.com", "hostname"=>"veos01"}, :encoding=>"json"}]
128
+
129
+ # use the config method to send configuration commands
130
+ node.config('hostname veos01')
131
+ => [{}]
132
+
133
+ # multiple commands can be sent by using a list (works for both enable or
134
+ config)
135
+ node.config(['interface Ethernet1', 'description foo'])
136
+ => [{}, {}]
137
+
138
+ # return the running or startup configuration from the node (output omitted for
139
+ brevity)
140
+ node.running_config
141
+
142
+ node.startup_config
143
+ ```
144
+
145
+ ### Using the API
146
+
147
+ The rbeapi library provides both a client for send and receiving commands over
148
+ eAPI as well as an API for working directly with EOS resources. The API is
149
+ designed to be easy and straightforward to use yet also extensible. Below is
150
+ an example of working with the ``vlans`` API
151
+
152
+ ```
153
+ # create a connection to the node
154
+ require 'rbeapi/client'
155
+ node = Rbeapi::Client.connect_to('veos01')
156
+
157
+ # get the instance of the API (in this case vlans)
158
+ vlans = node.api('vlans')
159
+
160
+ # return all vlans from the node
161
+ vlans.getall
162
+ => {"1"=>{:name=>"tester", :state=>"active", :trunk_groups=>[]},
163
+ "4"=>{:name=>"VLAN0004", :state=>"active", :trunk_groups=>[]},
164
+ "100"=>{:name=>"TEST_VLAN_100", :state=>"active", :trunk_groups=>[]},
165
+ "300"=>{:name=>"VLAN0300", :state=>"active", :trunk_groups=>[]}}
166
+
167
+ # return a specific vlan from the node
168
+ vlans.get(1)
169
+ => {:name=>"tester", :state=>"active", :trunk_groups=>[]}
170
+
171
+ # add a new vlan to the node
172
+ vlans.create(400)
173
+ => true
174
+
175
+ # set the new vlan name
176
+ vlans.set_name(100, value: 'foo')
177
+ => true
178
+ ```
179
+
180
+ All API implementations developed by Arista EOS+ CS are found in the rbeapi/api
181
+ folder. See the examples folder for additional examples.
182
+
183
+ # Installation
184
+
185
+ The source code for rbeapi is provided on Github at
186
+ http://github.com/arista-eosplus/rbeapi. All current development is done in
187
+ the develop branch. Stable released versions are tagged in the master branch
188
+ and uploaded to RubyGems.
189
+
190
+ * To install the latest stable version of rbeapi, simply run ``gem install
191
+ rbeapi``
192
+ * To install the latest development version from Github, simply clone the
193
+ develop branch and run ``rake build``
194
+
195
+
196
+ # Contributing
197
+
198
+ Contributing pull requests are gladly welcomed for this repository. Please
199
+ note that all contributions that modify the library behavior require
200
+ corresponding test cases otherwise the pull request will be rejected.
201
+
202
+ # License
203
+
204
+ Copyright (c) 2015, Arista Networks, Inc. All rights reserved.
205
+
206
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
207
+
208
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
209
+
210
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
211
+
212
+ Neither the name of Arista Networks nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
213
+
214
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
215
+
216
+
217
+
218
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
4
+ require 'rbeapi/version'
5
+
6
+ task :build do
7
+ system "gem build rbeapi.gemspec"
8
+ end
9
+
10
+ task :release => :build do
11
+ system "gem push rbeapi-#{Rbeapi::VERSION}"
12
+ end
data/lib/rbeapi.rb ADDED
@@ -0,0 +1,32 @@
1
+ #
2
+ # Copyright (c) 2014, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'rbeapi/client'
data/lib/rbeapi/api.rb ADDED
@@ -0,0 +1,135 @@
1
+ #
2
+ # Copyright (c) 2014, Arista Networks, Inc.
3
+ # All rights reserved.
4
+ #
5
+ # Redistribution and use in source and binary forms, with or without
6
+ # modification, are permitted provided that the following conditions are
7
+ # met:
8
+ #
9
+ # Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ #
12
+ # Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ #
16
+ # Neither the name of Arista Networks nor the names of its
17
+ # contributors may be used to endorse or promote products derived from
18
+ # this software without specific prior written permission.
19
+ #
20
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
24
+ # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27
+ # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28
+ # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29
+ # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
30
+ # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ #
32
+ require 'rbeapi/eapilib'
33
+
34
+ module Rbeapi
35
+
36
+ module Api
37
+
38
+ class Entity
39
+
40
+ attr_reader :error
41
+ attr_reader :config
42
+ attr_reader :node
43
+
44
+ ##
45
+ # The instance class method is used to create a new instance of the
46
+ # object. It works in conjunction with the Node.api loader method
47
+ # to make it easy to load classes derived from Entity
48
+ #
49
+ # @param [Node] :node An instance of Rbeapi::Client::Node used to
50
+ # send and receive eAPI messages
51
+ def self.instance(node)
52
+ new(node)
53
+ end
54
+
55
+ ##
56
+ # The Entity class provides a base class implementation for building
57
+ # API modules. The Entity class is typcially not instantiated directly
58
+ # but serves as a super class with convenience methods used to
59
+ # work with the node.
60
+ #
61
+ # @param [Node] :node This should be an instance of Rbeapi::Client::Node
62
+ # that is used to send and receive eAPI messages
63
+ #
64
+ def initialize(node, opts = {})
65
+ @node = node
66
+ end
67
+
68
+ ##
69
+ # Returns the running configuration from the node instance. This is
70
+ # a convenience method to easily access the current running config
71
+ # from an API module
72
+ #
73
+ # @return [String] The current running-config from the node
74
+ def config
75
+ return @node.running_config
76
+ end
77
+
78
+ ##
79
+ # Provides a convenience method for access the connection error (if
80
+ # one exists) of the node's connection instance
81
+ #
82
+ # @return [Rbeapi::Eapilib::CommandError] An instance of CommandError
83
+ # that can be used to futher evaluate the root cause of an error
84
+ def error
85
+ return @node.connection.error
86
+ end
87
+
88
+ ##
89
+ # Returns a block of configuration from the current running config
90
+ # as a string. The argument is used to search the config and return
91
+ # the text along with any child configuration statements.
92
+ #
93
+ # @param [String] :text The text to be used to find the parent line
94
+ # in the nodes configuration.
95
+ #
96
+ # @returns [nil, String] Returns the block of configuration based on
97
+ # the supplied argument. If the argument is not found in the
98
+ # configuration, nil is returned
99
+ def get_block(text)
100
+ mdata = /^#{text}$/.match(config)
101
+ return nil unless mdata
102
+ block_start, line_end = mdata.offset(0)
103
+
104
+ mdata = /^[^\s]/.match(config, line_end)
105
+ return nil unless mdata
106
+
107
+ _, block_end = mdata.offset(0)
108
+ block_end = block_end - block_start
109
+
110
+ config[block_start, block_end]
111
+ end
112
+
113
+ ##
114
+ # Method called to send configuration commands to the node. This method
115
+ # will send the commands to the node and rescue from CommandError or
116
+ # ConnectionError.
117
+ #
118
+ # @param [String, Array] :commands The commands to send to the node over
119
+ # the API connection to configure the system
120
+ #
121
+ # @return [Boolean] Returns True if the commands were successful or
122
+ # returns False if there was an error issuing the commands on the
123
+ # node. Use error to further investigate the cause of any errors
124
+ def configure(commands)
125
+ begin
126
+ @node.config(commands)
127
+ return true
128
+ rescue Rbeapi::Eapilib::CommandError, Rbeapi::Eapilib::ConnectionError
129
+ return false
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
135
+