-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge cisco_os_shim content into cisco_node_utils
- Loading branch information
Glenn Matthews
committed
Dec 9, 2015
1 parent
c1dda7a
commit 9715d84
Showing
36 changed files
with
2,128 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
pkg/* | ||
vendor/* | ||
coverage | ||
ext/Rakefile | ||
Gemfile.lock | ||
*.gem | ||
*.swp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,37 @@ | ||
# Use Docker infrastructure | ||
sudo: false | ||
# We'd like to use the Docker infrastructure, | ||
# but can't install libgrpc-dev at present in that environment. Sigh. | ||
# sudo: false | ||
sudo: true | ||
|
||
|
||
language: ruby | ||
cache: bundler | ||
rvm: | ||
- 2.2.2 | ||
- 2.1.6 | ||
- 2.0.0 | ||
|
||
before_install: | ||
# sudo apt-get install libgrpc-dev doesn't work in Travis. | ||
# So instead we compile and install from source, | ||
# which takes about 10 minutes. Not too painful. | ||
- sudo apt-get install build-essential autoconf libtool | ||
- git clone https://github.com/grpc/grpc.git | ||
- cd grpc | ||
- git checkout release-0_12 | ||
- git submodule update --init | ||
- make | ||
- sudo make install | ||
- cd src/ruby/ | ||
- gem build grpc.gemspec | ||
- gem install --local --force grpc-*.gem | ||
- mkdir -p ../../../vendor/cache | ||
- gem install --force --local grpc-*.gem | ||
- cp grpc-*.gem ../../../vendor/cache | ||
- cd ../../.. | ||
- rm -rf grpc | ||
# Also install net_http_unix to keep the nxapi submodule happy | ||
- gem install net_http_unix | ||
|
||
script: | ||
- bundle exec rake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Inspired by: | ||
# https://github.com/ruby-debug/ruby-debug-ide/blob/master/ext/mkrf_conf.rb | ||
|
||
# This file needs to be named mkrf_conf.rb | ||
# so that rubygems will recognize it as a ruby extension | ||
# file and not think it is a C extension file | ||
|
||
require 'rubygems/specification' | ||
require 'rubygems/dependency' | ||
require 'rubygems/dependency_installer' | ||
|
||
# Load up the rubygems dependency installer to install the dependencies | ||
# we need based on the platform we are running under. | ||
installer = Gem::DependencyInstaller.new | ||
deps = [] | ||
begin | ||
# Try to detect Cisco NX-OS and IOS XR environments | ||
os = nil | ||
if File.exist?('/etc/os-release') | ||
cisco_release_file = nil | ||
File.foreach('/etc/os-release') do |line| | ||
next unless line[/^CISCO_RELEASE_INFO=/] | ||
cisco_release_file = line[/^CISCO_RELEASE_INFO=(.*)$/, 1] | ||
break | ||
end | ||
unless cisco_release_file.nil? | ||
File.foreach(cisco_release_file) do |line| | ||
next unless line[/^ID=/] | ||
os = line[/^ID=(.*)$/, 1] | ||
break | ||
end | ||
end | ||
end | ||
puts "Detected client OS as '#{os}'" unless os.nil? | ||
|
||
# IOS XR doesn't need net_http_unix | ||
os == 'ios_xr' || deps << Gem::Dependency.new('net_http_unix', | ||
'~> 0.2', '>= 0.2.1') | ||
# NX-OS doesn't need gRPC | ||
os == 'nexus' || deps << Gem::Dependency.new('grpc', '~> 0.11') | ||
|
||
deps.each do |dep| | ||
installed = dep.matching_specs | ||
if installed.empty? | ||
puts "Installing #{dep}" | ||
installed = installer.install dep | ||
fail installer.errors[0] unless installer.errors.empty? | ||
fail "Did not install #{dep}" if installed.empty? | ||
else | ||
puts "Found installed gems matching #{dep}:" | ||
installed.each { |i| puts " #{i.name} (#{i.version})" } | ||
end | ||
end | ||
rescue StandardError => e | ||
puts e | ||
puts e.backtrace.join("\n ") | ||
exit(1) | ||
end | ||
|
||
# Create a dummy Rakefile to report successful 'compilation' | ||
f = File.open(File.join(File.dirname(__FILE__), 'Rakefile'), 'w') | ||
f.write("task :default\n") | ||
f.close |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright (c) 2015 Cisco and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require_relative 'client/core' | ||
|
||
# Try to load known extensions | ||
extensions = ['client/nxapi', | ||
'client/grpc', | ||
] | ||
extensions.each do |ext| | ||
begin | ||
require_relative ext | ||
rescue LoadError => e | ||
# ignore missing client-(grpc|nxapi), they're not always required | ||
raise unless e.message =~ /#{Regexp.escape(ext)}/ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) 2015 Cisco and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Namespace for Cisco-specific code | ||
module Cisco | ||
# Namespace for Cisco Client shim | ||
module Client | ||
end | ||
end | ||
|
||
# Auto-load all Ruby files in the subdirectory | ||
Dir.glob(__dir__ + '/core/*.rb') { |file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
# Cisco Logger Library. | ||
# | ||
# January 2015, Jie Yang | ||
# | ||
# Copyright (c) 2015 Cisco and/or its affiliates. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
require 'logger' | ||
|
||
# Module for logging in CiscoNxapi and CiscoNodeUtils. Will automatically | ||
# tie into Puppet or Chef logging modules if available. | ||
module CiscoLogger | ||
module_function | ||
|
||
# Figure out what provider logging utility we | ||
# should use: Puppet or Chef. | ||
# If not found use the Ruby Logger/STDOUT/INFO. | ||
if defined? (Puppet::Util::Logging) | ||
@@logger = Puppet # rubocop:disable Style/ClassVars | ||
def error(string) | ||
@@logger.err(string) | ||
end | ||
|
||
def warn(string) | ||
@@logger.warning(string) | ||
end | ||
else | ||
if defined? (Chef::Log) | ||
@@logger = Chef::Log # rubocop:disable Style/ClassVars | ||
else | ||
@@logger = Logger.new(STDOUT) # rubocop:disable Style/ClassVars | ||
@@logger.level = Logger::INFO | ||
|
||
def debug_enable | ||
@@logger.level = Logger::DEBUG | ||
end | ||
|
||
def debug_disable | ||
@@logger.level = Logger::INFO | ||
end | ||
end | ||
|
||
def error(string) | ||
@@logger.error(string) | ||
end | ||
|
||
def warn(string) | ||
@@logger.warn(string) | ||
end | ||
end | ||
|
||
def debug(string) | ||
@@logger.debug(string) | ||
end | ||
|
||
def info(string) | ||
@@logger.info(string) | ||
end | ||
end # module |
Oops, something went wrong.