infoblocks 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ Gemfile.lock
2
+ infoblocks.cfg
3
+ results.html
4
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ group :development do
5
+ gem 'pry'
6
+ end
@@ -0,0 +1,6 @@
1
+ = infoblocks
2
+
3
+ Command line interface to infoblox.
4
+
5
+ :include:infoblocks.rdoc
6
+
@@ -0,0 +1,45 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('infoblocks.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ #task :default => [:test,:features]
45
+ task :default => [:test]
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env ruby
2
+ require 'gli'
3
+ require 'infoblocks'
4
+ require 'infoblox'
5
+ require 'pry'
6
+
7
+ include GLI::App
8
+
9
+ config_file '.infoblocks.rc'
10
+
11
+ program_desc 'CLI interface for the Infoblox WAPI'
12
+
13
+ version Infoblocks::VERSION
14
+ sort_help :manually
15
+
16
+ desc 'Username for Infoblox WAPI'
17
+ arg_name '<username>'
18
+ flag [:user,:u]
19
+
20
+ desc 'Password for Infoblox WAPI'
21
+ arg_name '<password>'
22
+ flag [:pass,:p]
23
+
24
+ desc 'Host or base URL for Infoblox WAPI'
25
+ arg_name '<hostname>'
26
+ flag [:host,:H]
27
+
28
+ desc 'Manipulates host objects'
29
+ command :host do |c|
30
+ c.flag [:view,:v], :desc => 'DNS View', :required => true
31
+
32
+ c.desc 'Adds host object'
33
+ c.arg_name '<hostname> <ip_address>'
34
+ c.command :add do |subadd|
35
+ subadd.action do |global_options,options,args|
36
+ raise ArgumentError, "Invalid arguments" if args.length != 2
37
+
38
+ hostobj = Infoblox::Host.new({
39
+ :connection => @connection,
40
+ :name => args[0],
41
+ :ipv4addrs => [{ :ipv4addr => args[1] }],
42
+ :configure_for_dns => true,
43
+ :view => options[:view]
44
+ })
45
+ hostobj.post
46
+ end
47
+ end
48
+
49
+ c.desc 'Deletes host object'
50
+ c.arg_name '<hostname>'
51
+ c.command :del do |subdel|
52
+ subdel.action do |global_options,options,args|
53
+ raise ArgumentError, "Invalid arguments" if args.length != 1
54
+
55
+ hostarray = Infoblox::Host.find(@connection, {'name' => args[0], 'view' => options[:view]})
56
+ raise StandardError, "Multiple records found" if hostarray.length != 1
57
+
58
+ hostarray[0].delete
59
+ end
60
+ end
61
+
62
+ c.desc 'Searches for hosts'
63
+ c.arg_name '<hostname>'
64
+ c.command :search do |subsearch|
65
+ subsearch.action do |global_options,options,args|
66
+ raise ArgumentError, "Invalid arguments" if args.length != 1
67
+
68
+ Infoblox::Host.find(@connection, {'name' => args[0], 'view' => options[:view]}).each do |host|
69
+ Infoblocks::Display.disp(host)
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ desc 'Searches infoblox globally'
76
+ arg_name '<search_string>'
77
+ command :search do |c|
78
+ c.flag [:matchtype,:m], :desc => 'How to treat search string', :default_value => 'exact', :must_match => ['exact','loose','regex']
79
+ c.flag [:objtype,:o], :desc => 'Restricts search to specific object type'
80
+ c.action do |global_options,options,args|
81
+ raise ArgumentError, "Missing argument" if args.length != 1
82
+
83
+ searchmap = { 'exact' => '', 'loose' => ':', 'regex' => '~' } # infoblox holdovers from the perl api
84
+ search_string = { "search_string#{searchmap[options[:matchtype]]}" => args[0] }
85
+ search_string.merge!({ 'objtype' => options[:objtype] }) unless options[:objtype].nil?
86
+
87
+ Infoblox::Search.find(@connection, search_string).each do |obj|
88
+ Infoblocks::Display.disp(obj)
89
+ end
90
+ end
91
+ end
92
+
93
+ pre do |global,command,options,args|
94
+ [:user,:pass,:host].each do |required|
95
+ raise ArgumentError, "Missing #{required} argument." unless global[required]
96
+ end
97
+ @connection = Infoblox::Connection.new(:username => global[:user], :password => global[:pass], :host => global[:host])
98
+ true
99
+ end
100
+
101
+ post do |global,command,options,args|
102
+ # Post logic here
103
+ # Use skips_post before a command to skip this
104
+ # block on that command only
105
+ end
106
+
107
+ on_error do |exception|
108
+ # Error logic here
109
+ # return false to skip default error handling
110
+ true
111
+ end
112
+
113
+ exit run(ARGV)
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
@@ -0,0 +1,13 @@
1
+ Feature: The infoblocks CLI does things a sane CLI should do.
2
+
3
+ Scenario: Run infoblocks with no commands
4
+ When I run `infoblocks`
5
+ Then the output should contain "SYNOPSIS"
6
+
7
+ Scenario: Run infoblocks with help arguments
8
+ When I run `infoblocks -h`
9
+ Then the output should contain "COMMANDS"
10
+
11
+ Scenario: Run infoblocks with an invalid command
12
+ When I run `infoblocks not_a_command`
13
+ Then the output should contain "error: Unknown command"
@@ -0,0 +1,24 @@
1
+ # Ensure we require the local version and not one we might have installed already
2
+ require File.join([File.dirname(__FILE__),'lib','infoblocks','version.rb'])
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'infoblocks'
5
+ s.version = Infoblocks::VERSION
6
+ s.author = 'Sam Rees'
7
+ s.email = 'srees@enova.com'
8
+ s.homepage = 'http://www.enova.com'
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = 'CLI Interface into Infoblox'
11
+ s.files = `git ls-files`.split("
12
+ ")
13
+ s.require_paths << 'lib'
14
+ s.has_rdoc = true
15
+ s.extra_rdoc_files = ['README.rdoc','infoblocks.rdoc']
16
+ s.rdoc_options << '--title' << 'infoblocks' << '--main' << 'README.rdoc' << '-ri'
17
+ s.bindir = 'bin'
18
+ s.executables << 'infoblocks'
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rdoc')
21
+ s.add_development_dependency('aruba')
22
+ s.add_runtime_dependency('gli','2.9.0')
23
+ s.add_runtime_dependency('infoblox','0.2.6')
24
+ end
@@ -0,0 +1,5 @@
1
+ = infoblocks
2
+
3
+ Generate this with
4
+ infoblocks rdoc
5
+ After you have described your command line interface
@@ -0,0 +1,3 @@
1
+ require 'infoblocks/version.rb'
2
+ require 'infoblocks/display.rb'
3
+
@@ -0,0 +1,17 @@
1
+ require 'erb'
2
+
3
+ module Infoblocks
4
+ class Display
5
+ def self.disp(obj=nil)
6
+ template_path = File.expand_path("templates/#{obj.class.to_s.split(':').last.downcase}.erb", File.dirname(__FILE__))
7
+
8
+ if File.exists?(template_path)
9
+ template = ERB.new(IO.read(template_path), nil, '-')
10
+ puts template(obj).result obj.instance_eval('binding')
11
+ else
12
+ puts obj._ref
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ hostname: <%= @name %>
2
+ <% @ipv4addrs.each do |ip| -%>
3
+ ip: <%= ip.ipv4addr %>
4
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ module Infoblocks
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ class DefaultTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def teardown
9
+ end
10
+
11
+ def test_the_truth
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ require 'test/unit'
2
+ require_relative '../lib/infoblocks.rb'
3
+
4
+ # Add test libraries you want to use here, e.g. mocha
5
+
6
+ class Test::Unit::TestCase
7
+
8
+ # Add global extensions to the test case class here
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infoblocks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Rees
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-03-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rdoc
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: aruba
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: gli
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 2.9.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.9.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: infoblox
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - '='
84
+ - !ruby/object:Gem::Version
85
+ version: 0.2.6
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.2.6
94
+ description:
95
+ email: srees@enova.com
96
+ executables:
97
+ - infoblocks
98
+ extensions: []
99
+ extra_rdoc_files:
100
+ - README.rdoc
101
+ - infoblocks.rdoc
102
+ files:
103
+ - .gitignore
104
+ - Gemfile
105
+ - README.rdoc
106
+ - Rakefile
107
+ - bin/infoblocks
108
+ - features/support/env.rb
109
+ - features/userhelp.feature
110
+ - infoblocks.gemspec
111
+ - infoblocks.rdoc
112
+ - lib/infoblocks.rb
113
+ - lib/infoblocks/display.rb
114
+ - lib/infoblocks/templates/host.erb
115
+ - lib/infoblocks/version.rb
116
+ - test/default_test.rb
117
+ - test/test_helper.rb
118
+ homepage: http://www.enova.com
119
+ licenses: []
120
+ post_install_message:
121
+ rdoc_options:
122
+ - --title
123
+ - infoblocks
124
+ - --main
125
+ - README.rdoc
126
+ - -ri
127
+ require_paths:
128
+ - lib
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 1.8.23
145
+ signing_key:
146
+ specification_version: 3
147
+ summary: CLI Interface into Infoblox
148
+ test_files: []