Skip to content

Commit

Permalink
Merge branch 'release-1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jerearista committed Dec 6, 2016
2 parents 15e6443 + 3fbee2d commit 9607f21
Show file tree
Hide file tree
Showing 66 changed files with 2,222 additions and 533 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ Metrics/AbcSize:

Metrics/ClassLength:
Max: 130

Metrics/BlockLength:
Enabled: False
27 changes: 25 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
# Change Log

## [1.0](https://github.com/arista-eosplus/rbeapi/tree/1.0) (2016-09-22)
[Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.5.1...1.0)
## [1.1](https://github.com/arista-eosplus/rbeapi/tree/1.1) (2016-12-06)
[Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v1.0...1.1)

**Implemented enhancements:**

- add subinterface functionality [\#161](https://github.com/arista-eosplus/rbeapi/pull/161) ([mmailand](https://github.com/mmailand))
- add support to set aliases [\#160](https://github.com/arista-eosplus/rbeapi/pull/160) ([mmailand](https://github.com/mmailand))
- added support for setting the crypto in managementdefaults [\#159](https://github.com/arista-eosplus/rbeapi/pull/159) ([mmailand](https://github.com/mmailand))
- added support for autostate [\#158](https://github.com/arista-eosplus/rbeapi/pull/158) ([mmailand](https://github.com/mmailand))
- add support for multi/single-line prefix list output [\#155](https://github.com/arista-eosplus/rbeapi/pull/155) ([mrvinti](https://github.com/mrvinti))

**Fixed bugs:**

- Fix multiline alias support [\#165](https://github.com/arista-eosplus/rbeapi/pull/165) ([jerearista](https://github.com/jerearista))
- extend and fix ospf features [\#156](https://github.com/arista-eosplus/rbeapi/pull/156) ([rknaus](https://github.com/rknaus))

**Merged pull requests:**

- Style updates for Rubocop 0.45 [\#163](https://github.com/arista-eosplus/rbeapi/pull/163) ([jerearista](https://github.com/jerearista))
- fix for rspec failure on current develop [\#162](https://github.com/arista-eosplus/rbeapi/pull/162) ([mmailand](https://github.com/mmailand))

## [v1.0](https://github.com/arista-eosplus/rbeapi/tree/v1.0) (2016-09-26)
[Full Changelog](https://github.com/arista-eosplus/rbeapi/compare/v0.5.1...v1.0)

**Implemented enhancements:**

Expand All @@ -24,6 +45,8 @@

**Merged pull requests:**

- Release 1.0 [\#153](https://github.com/arista-eosplus/rbeapi/pull/153) ([jerearista](https://github.com/jerearista))
- Release 1.0 [\#152](https://github.com/arista-eosplus/rbeapi/pull/152) ([jerearista](https://github.com/jerearista))
- Add json option to get\_config [\#151](https://github.com/arista-eosplus/rbeapi/pull/151) ([jerearista](https://github.com/jerearista))
- Handle more multiline config commands [\#150](https://github.com/arista-eosplus/rbeapi/pull/150) ([jerearista](https://github.com/jerearista))
- Ensure get\_config, running\_config, and startup\_config return sane output [\#149](https://github.com/arista-eosplus/rbeapi/pull/149) ([jerearista](https://github.com/jerearista))
Expand Down
20 changes: 13 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
source ENV['GEM_SOURCE'] || 'https://rubygems.org'

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'rbeapi/version'

gem 'inifile'
gem 'net_http_unix'
gem 'netaddr'
Expand All @@ -12,20 +16,20 @@ group :development do
end

group :development, :test do
gem 'ci_reporter_rspec', require: false
gem 'listen', '<=3.0.3'
gem 'pry', require: false
gem 'pry-doc', require: false
gem 'pry-stack_explorer', require: false
gem 'rake', '~> 10.1.0'
gem 'rbeapi', Rbeapi::VERSION, path: '.'
gem 'redcarpet', '~> 3.1.2'
gem 'rspec', '~> 3.0.0'
gem 'rspec-mocks', '~> 3.0.0'
gem 'simplecov'
gem 'yard'
gem 'redcarpet', '~> 3.1.2'
gem 'pry', require: false
gem 'pry-doc', require: false
gem 'pry-stack_explorer', require: false
gem 'rbeapi', '1.0', path: '.'
gem 'ci_reporter_rspec', require: false
gem 'simplecov-json', require: false
gem 'simplecov-rcov', require: false
gem 'yard'
end

# Rubocop > 0.37 requires a gem that only works with ruby 2.x
Expand All @@ -35,6 +39,8 @@ if RUBY_VERSION.to_f < 2.0
gem 'rubocop', '>=0.35.1', '< 0.38'
end
else
# Rubocop thinks these are duplicates.
# rubocop:disable Bundler/DuplicatedGem
gem 'json'
group :development, :test do
gem 'rubocop', '>=0.35.1'
Expand Down
15 changes: 8 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ end

RPM_OPTS = '--define "_topdir %(pwd)/rpmbuild" --define "_builddir ' \
'%{_topdir}" --define "_rpmdir %(pwd)/rpms" --define "_srcrpmdir ' \
'%{_rpmdir}" --define "_sourcedir %(pwd)" --define "_specdir %(pwd)" -bb'
'%{_rpmdir}" --define "_sourcedir %(pwd)" --define "_specdir %(pwd)" '\
'-bb'.freeze
desc 'Generate regular and puppet-enterprise rbeapi RPMs for EOS'
task rpm: :build do
system "sed -e 's/^Version:.*/Version: #{Rbeapi::VERSION}/g' " \
'rbeapi.spec.tmpl > rbeapi.spec'
system "rpmbuild #{RPM_OPTS} rbeapi.spec"
RPMS = `find rpms/noarch -name "*rbeapi*rpm"`
RPMS = `find rpms/noarch -name "*rbeapi*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
Expand All @@ -32,7 +33,7 @@ task :inifile do
system "sed -e 's/^Version:.*/Version: #{INIFILE_VERSION}/g' " \
'gems/inifile/inifile.spec.tmpl > gems/inifile/inifile.spec'
system "rpmbuild #{RPM_OPTS} gems/inifile/inifile.spec"
RPMS = `find rpms/noarch -name "*inifile*rpm"`
RPMS = `find rpms/noarch -name "*inifile*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
Expand All @@ -50,7 +51,7 @@ task :net_http_unix do
'gems/net_http_unix/net_http_unix.spec.tmpl > ' \
'gems/net_http_unix/net_http_unix.spec'
system "rpmbuild #{RPM_OPTS} gems/net_http_unix/net_http_unix.spec"
RPMS = `find rpms/noarch -name "*net_http_unix*rpm"`
RPMS = `find rpms/noarch -name "*net_http_unix*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
Expand All @@ -67,7 +68,7 @@ task :netaddr do
system "sed -e 's/^Version:.*/Version: #{NETADDR_VERSION}/g' " \
'gems/netaddr/netaddr.spec.tmpl > gems/netaddr/netaddr.spec'
system "rpmbuild #{RPM_OPTS} gems/netaddr/netaddr.spec"
RPMS = `find rpms/noarch -name "*netaddr*rpm"`
RPMS = `find rpms/noarch -name "*netaddr*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
Expand Down Expand Up @@ -114,7 +115,7 @@ end
desc 'Generate SWIX files from RPMs'
task swix: :all_rpms do
SWIX = 'PYTHONPATH=${PYTHONPATH}:/nfs/misc/tools/swix \
/nfs/misc/tools/swix/swix'
/nfs/misc/tools/swix/swix'.freeze
system "(cd rpms/noarch;
rm -f rbeapi-#{Rbeapi::VERSION}-1.swix;
#{SWIX} create rbeapi-#{Rbeapi::VERSION}-1.swix \
Expand All @@ -141,7 +142,7 @@ task swix: :all_rpms do
rubygem-inifile-puppet-aio-3.0.0-5.eos4.noarch.rpm \
rubygem-netaddr-puppet-aio-1.5.1-4.eos4.noarch.rpm \
rubygem-net_http_unix-puppet-aio-0.2.2-5.eos4.noarch.rpm)"
SWIXS = `find rpms/noarch -name "rbeapi*swix" -ls`
SWIXS = `find rpms/noarch -name "rbeapi*swix" -ls`.freeze
puts "\n################################################\n#"
puts "The following artifacts are in rpms/noarch/\n#{SWIXS}"
puts "#\n################################################\n\n"
Expand Down
160 changes: 160 additions & 0 deletions lib/rbeapi/api/alias.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#
## Copyright (c) 2016, Arista Networks, Inc.
## All rights reserved.
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions are
## met:
##
## Redistributions of source code must retain the above copyright notice,
## this list of conditions and the following disclaimer.
##
## 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.
##
## 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.
##
## 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.
##
require 'rbeapi/api'

##
# Rbeapi toplevel namespace.
module Rbeapi
##
# Api is module namespace for working with the EOS command API.
module Api
##
# The Alias class manages aliass entries on an EOS node.
class Alias < Entity
##
# get returns the current alias configuration hash extracted from the
# nodes running configuration.
#
# @example
# {
# alias: array<strings>
# }
#
# @return [Hash<Symbol, Object>] Returns the alias resource as a hash
# object from the nodes current configuration.
def get(name)
# Complex regex handles the following cases:
# All aliases start with 'alian <name>' followed by
# <space><single-line command>
# <carriage return><multiple lines of commands>
pattern = /^alias #{name}((?:(?= )(?:.+?)(?=\n)|\n(?:.+?)(?=\n\!)))/m
aliases = config.scan(pattern)
return nil unless aliases[0]
parse_alias_entry(name, aliases[0])
end

##
# getall returns a collection of alias resource hashes from the nodes
# running configuration. The alias resource collection hash is keyed
# by the unique alias name.
#
# @example
# [
# <alias>: {
# command: <string>
# },
# <alias>: {
# command: <string>
# },
# ...
# ]
#
# @return [Hash<Symbol, Object>] Returns a hash that represents the
# entire alias collection from the nodes running configuration. If
# there are no aliass configured, this method will return an empty
# hash.
def getall
entries = config.scan(/^alias (\w+)(.+)?/)
entries.inspect
response = {}
entries.each do |aliases|
response[aliases[0]] = get aliases[0]
end
response
end

##
# parse_alias_entry maps the tokens found to the hash entries.
#
# @api private
#
# @param alias [Array] An array of values returned from the regular
# expression scan of the aliass configuration.
#
# @return [Hash<Symbol, Object>] Returns the resource hash attribute.
def parse_alias_entry(name, command)
hsh = {}
hsh[:name] = name
com = command[0]
hsh[:command] = com.strip
hsh
end
private :parse_alias_entry

##
# create will create a alias entry in the nodes current
# configuration with the specified address.
#
# @since eos_version 4.13.7M
#
# ===Commands
# alias <name> <address>
#
# @param name [String] The name of the alias.
#
# @param opts [hash] Optional keyword arguments.
#
# @option opts command [String] Configures the alias ip address
#
# @return [Boolean] Returns true if the command completed successfully.
def create(name, opts = {})
raise ArgumentError, 'a command must be provided' unless \
opts[:command] =~ /.+/
command = opts.fetch(:command)
cmd = ["alias #{name} "]
if command =~ /\\n/
command.split('\\n').each { |a| cmd << a }
else
cmd[0] << command
end
configure(cmd)
end

##
# delete will delete an existing alias entry from the nodes current
# running configuration. If the delete method is called and the alias
# entry does not exist, this method will succeed.
#
# @since eos_version 4.13.7M
#
# ===Commands
# no alias <name>
#
# @param name [String] The alias name entry to delete from the node.
#
# @return [Boolean] Returns true if the command completed successfully.
def delete(name)
configure("no alias #{name}")
end
end
end
end
18 changes: 9 additions & 9 deletions lib/rbeapi/api/bgp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def parse_networks(config)
def create(bgp_as, opts = {})
if opts[:maximum_ecmp_paths] && !opts[:maximum_paths]
message = 'maximum_paths must be set if maximum_ecmp_paths is set'
fail ArgumentError, message
raise ArgumentError, message
end
cmds = ["router bgp #{bgp_as}"]
if opts.key?(:enable)
Expand Down Expand Up @@ -284,7 +284,7 @@ def default
# @return [Boolean] Returns true if the command complete successfully.
def configure_bgp(cmd)
config = get_block('^router bgp .*')
fail 'BGP router is not configured' unless config
raise 'BGP router is not configured' unless config
bgp_as = Bgp.parse_bgp_as(config)
cmds = ["router bgp #{bgp_as[:bgp_as]}", cmd]
configure(cmds)
Expand Down Expand Up @@ -341,10 +341,10 @@ def set_router_id(opts = {})
#
# @return [Boolean] Returns true if the command complete successfully.
def set_shutdown(opts = {})
fail 'set_shutdown has the value option set' if opts[:value]
raise 'set_shutdown has the value option set' if opts[:value]
# Shutdown semantics are opposite of enable semantics so invert enable
value = !opts[:enable]
opts.merge!(enable: value)
opts[:enable] = value
configure_bgp(command_builder('shutdown', opts))
end

Expand Down Expand Up @@ -697,7 +697,7 @@ def parse_route_map_out(config, name)
# @return [Boolean] Returns true if the command complete successfully.
def configure_bgp(cmd)
config = get_block('^router bgp .*')
fail 'BGP router is not configured' unless config
raise 'BGP router is not configured' unless config
bgp_as = Bgp.parse_bgp_as(config)
cmds = ["router bgp #{bgp_as[:bgp_as]}", cmd]
configure(cmds)
Expand Down Expand Up @@ -831,10 +831,10 @@ def set_remote_as(name, opts = {})
#
# @return [Boolean] Returns true if the command complete successfully.
def set_shutdown(name, opts = {})
fail 'set_shutdown has value option set' if opts[:value]
raise 'set_shutdown has value option set' if opts[:value]
# Shutdown semantics are opposite of enable semantics so invert enable.
value = !opts[:enable]
opts.merge!(enable: value)
opts[:enable] = value
configure_bgp(neigh_command_builder(name, 'shutdown', opts))
end

Expand All @@ -859,7 +859,7 @@ def set_shutdown(name, opts = {})
#
# @return [Boolean] Returns true if the command complete successfully.
def set_send_community(name, opts = {})
fail 'send_community has the value option set' if opts[:value]
raise 'send_community has the value option set' if opts[:value]
configure_bgp(neigh_command_builder(name, 'send-community', opts))
end

Expand All @@ -885,7 +885,7 @@ def set_send_community(name, opts = {})
#
# @return [Boolean] Returns true if the command complete successfully.
def set_next_hop_self(name, opts = {})
fail 'set_next_hop_self has the value option set' if opts[:value]
raise 'set_next_hop_self has the value option set' if opts[:value]
configure_bgp(neigh_command_builder(name, 'next-hop-self', opts))
end

Expand Down
4 changes: 3 additions & 1 deletion lib/rbeapi/api/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def set_domain_list(opts = {})
default = opts[:default] || false

if value
fail ArgumentError, 'value must be an Array' unless value.is_a?(Array)
unless value.is_a?(Array)
raise ArgumentError, 'value must be an Array'
end
end

cmds = []
Expand Down
Loading

0 comments on commit 9607f21

Please sign in to comment.