bjreath-cisco 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Brian J Reath
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = cisco
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Brian J Reath. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "cisco"
8
+ gem.summary = %Q{Ruby gem for interacting with Cisco routers via telnet}
9
+ gem.email = "brian.reath@ccisystems.com"
10
+ gem.homepage = "http://github.com/bjreath/cisco"
11
+ gem.authors = ["Brian J Reath"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "cisco #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
56
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/cisco.gemspec ADDED
@@ -0,0 +1,49 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{cisco}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brian J Reath"]
9
+ s.date = %q{2009-08-20}
10
+ s.email = %q{brian.reath@ccisystems.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "cisco.gemspec",
23
+ "init.rb",
24
+ "lib/cisco.rb",
25
+ "lib/cisco/session.rb",
26
+ "lib/cisco/string_ext.rb",
27
+ "test/cisco_test.rb",
28
+ "test/test_helper.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/bjreath/cisco}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Ruby gem for interacting with Cisco routers via telnet}
35
+ s.test_files = [
36
+ "test/cisco_test.rb",
37
+ "test/test_helper.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "cisco"
data/lib/cisco.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "cisco/session"
2
+ require "cisco/string_ext"
@@ -0,0 +1,46 @@
1
+ require "net/telnet"
2
+
3
+ module Cisco
4
+ class Session
5
+
6
+ def initialize(options = {}, &blk)
7
+ @host = options[:host]
8
+ @user = options[:user]
9
+ @user_prompt = options[:user_prompt] || "Username: "
10
+ @password = options[:password]
11
+ @pwd_prompt = options[:pwd_prompt] || "Password: "
12
+ @cmd_prompt = options[:cmd_prompt] || "#"
13
+
14
+ begin
15
+ @socket = Net::Telnet.new("Host" => @host)
16
+ login_to_device
17
+ yield(self)
18
+ ensure
19
+ close_session if @socket
20
+ end
21
+ end
22
+
23
+ def cmd(command, timeout = 10)
24
+ @socket.cmd("String" => command, "Match" => Regexp.new(Regexp.escape(@prompt)), "Timeout" => timeout)
25
+ end
26
+
27
+ private
28
+
29
+ def login_to_device
30
+ expect(@user_prompt)
31
+ @socket.puts(@user)
32
+ expect(@pwd_prompt)
33
+ @socket.puts(@password)
34
+ @prompt = expect(@cmd_prompt)
35
+ end
36
+
37
+ def expect(str, timeout = 10)
38
+ @socket.waitfor("String" => str, "Timeout" => timeout).split("\n").last.strip
39
+ end
40
+
41
+ def close_session
42
+ @socket.close
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,15 @@
1
+ class String
2
+ def mac_convert
3
+ if self.length == 14
4
+ self.gsub! /\./, ""
5
+ [2, 5, 8, 11, 14].each { |idx| self.insert(idx, ":") }
6
+ self
7
+ elsif self.length == 17
8
+ self.gsub! /:/, ""
9
+ [4, 9].each { |idx| self.insert(idx, ".") }
10
+ self
11
+ else
12
+ raise ArgumentError
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class CiscoTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'cisco'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bjreath-cisco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian J Reath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: brian.reath@ccisystems.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - cisco.gemspec
33
+ - init.rb
34
+ - lib/cisco.rb
35
+ - lib/cisco/session.rb
36
+ - lib/cisco/string_ext.rb
37
+ - test/cisco_test.rb
38
+ - test/test_helper.rb
39
+ has_rdoc: false
40
+ homepage: http://github.com/bjreath/cisco
41
+ licenses:
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --charset=UTF-8
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ruby gem for interacting with Cisco routers via telnet
66
+ test_files:
67
+ - test/cisco_test.rb
68
+ - test/test_helper.rb