infoblox 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in infoblox.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Billy Reisinger
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Infoblox
2
+
3
+ Interact with the Infoblox WAPI with Ruby. Use this gem to list, create, and delete host records.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'infoblox'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install infoblox
18
+
19
+ ## Usage
20
+
21
+ Create a new client:
22
+
23
+ client = Infoblox::Client.new(:username => "foo",
24
+ :password => "bar",
25
+ :host => "https://foo-bar-dns.example.com")
26
+
27
+ Creating a host record:
28
+
29
+ client.create_host("build-machine.internal", "10.10.3.3")
30
+
31
+ Delete the host:
32
+
33
+ client.delete_host("build-machine.internal")
34
+
35
+ Find hosts (fuzzy matches on host name):
36
+
37
+ client.find_host_by_name("build-")
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/infoblox ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'infoblox'
4
+ require 'pp'
5
+ require 'optparse'
6
+
7
+ def print_host(*hosts)
8
+ hosts.flatten.each do |h|
9
+ puts "Host\t#{h.name}"
10
+ puts "IP \t" + h.ipv4addrs.map{|i| i["ipv4addr"]}.join(",")
11
+ puts "Ref \t" + h._ref
12
+ end
13
+ end
14
+
15
+ options = {}
16
+ OptionParser.new do |opts|
17
+ opts.banner = "Usage: #{$0}.rb [options]"
18
+ opts.on("-u", "--user USER", "username for infoblox") do |u|
19
+ options[:username] = u
20
+ end
21
+ opts.on("-p", "--pass PASSWORD", "password for infoblox") do |p|
22
+ options[:password] = p
23
+ end
24
+ opts.on("-f", "--find SEARCH", "find the specified hosts (fuzzy match) and print info") do |f|
25
+ options[:find] = f
26
+ end
27
+ opts.on("-h", "--host INFOBLOX_HOST", "the hostname of the Infoblox appliance, including protocol") do |h|
28
+ options[:host] = h
29
+ end
30
+ opts.on("-c", "--create HOST_AND_IP", "create the specified host. Supply the host and ip address, separated by a comma (no space).") do |c|
31
+ options[:create] = c
32
+ end
33
+ opts.on("-d", "--delete HOST", "delete the specified host ") do |d|
34
+ options[:delete] = d
35
+ end
36
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
37
+ options[:verbose] = v
38
+ end
39
+
40
+ end.parse!
41
+
42
+ if options[:verbose]
43
+ options[:logger] = Logger.new(STDOUT)
44
+ end
45
+
46
+ client = Infoblox::Client.new(options)
47
+
48
+ if options[:find]
49
+ print_host client.find_host_by_name(options[:find])
50
+ end
51
+ if options[:delete]
52
+ print_host client.delete_host(options[:delete])
53
+ end
54
+ if options[:create]
55
+ pp client.create_host(*options[:create].split(','))
56
+ end
data/infoblox.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'infoblox/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "infoblox"
8
+ spec.version = Infoblox::VERSION
9
+ spec.authors = ["Billy Reisinger"]
10
+ spec.email = ["billy.reisinger@govdelivery.com"]
11
+ spec.description = %q{A Ruby wrapper to the Infoblox WAPI}
12
+ spec.summary = %q{This gem is a Ruby interface to the Infoblox WAPI. Only a few operations are supported as of yet.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "faraday"
22
+ spec.add_runtime_dependency "faraday_middleware"
23
+
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "pry"
28
+ end
data/lib/infoblox.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'logger'
2
+ require 'json'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'openssl'
6
+ require 'infoblox/version'
7
+ require 'infoblox/connection'
8
+ require 'infoblox/resource'
9
+ require 'infoblox/host'
10
+ require 'infoblox/client'
11
+
12
+ module Infoblox
13
+ VERSION = '1.0'
14
+ BASE_PATH = '/wapi/v' + VERSION + '/'
15
+ DEBUG = ENV['DEBUG']
16
+ end
17
+
18
+ #OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
@@ -0,0 +1,38 @@
1
+ module Infoblox
2
+ class Client
3
+ ##
4
+ # :username
5
+ # :password
6
+ # :host (host if infoblox appliance, including protocol)
7
+ def initialize(options={})
8
+ Resource.connection = Connection.new(options)
9
+ end
10
+
11
+ def all_hosts
12
+ Host.all
13
+ end
14
+
15
+ def find_host_by_name(name)
16
+ Host.find(:"name~" => name)
17
+ end
18
+
19
+ ##
20
+ # hostname : string
21
+ # ip : ipv4 string, i.e. "10.40.20.3"
22
+ def create_host(hostname, ip, dns=true)
23
+ host = Host.new(:name => hostname, :configure_for_dns => true)
24
+ host.add_ipv4addr(ip)
25
+ host.create
26
+ end
27
+
28
+ def delete_host(hostname)
29
+ if !(hosts = Host.find(:name => hostname)).empty?
30
+ hosts.map(&:delete)
31
+ hosts
32
+ else
33
+ raise Exception.new("host #{hostname} not found")
34
+ false
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,55 @@
1
+ module Infoblox
2
+ class Connection
3
+ attr_accessor :username, :password, :host, :connection, :logger, :ssl_opts
4
+
5
+ def get(href, params={})
6
+ wrap do
7
+ connection.get(href, params)
8
+ end
9
+ end
10
+
11
+ def post(href, body)
12
+ wrap do
13
+ connection.post do |req|
14
+ req.url href
15
+ req.body = body.to_json
16
+ end
17
+ end
18
+ end
19
+
20
+ def delete(href)
21
+ wrap do
22
+ connection.delete(href)
23
+ end
24
+ end
25
+
26
+ def initialize(opts={})
27
+ self.username = opts[:username]
28
+ self.password = opts[:password]
29
+ self.host = opts[:host]
30
+ self.logger = opts[:logger]
31
+ self.ssl_opts = opts[:ssl_opts]
32
+ end
33
+
34
+ def connection
35
+ @connection ||= Faraday.new(:url => self.host, :ssl => {:verify => false}) do |faraday|
36
+ faraday.use Faraday::Response::Logger, logger if logger
37
+
38
+ faraday.request :json
39
+ faraday.basic_auth(self.username, self.password)
40
+ faraday.adapter :net_http
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def wrap
47
+ yield.tap do |response|
48
+ unless response.status < 300
49
+ raise Exception.new("Error: #{response.status} #{response.body}")
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,13 @@
1
+ module Infoblox
2
+ class Host < Resource
3
+ remote_attr_accessor :ipv4addrs, :name, :configure_for_dns
4
+ attr_accessor :view
5
+
6
+ wapi_object "record:host"
7
+
8
+ def add_ipv4addr(address)
9
+ @ipv4addrs ||= []
10
+ @ipv4addrs << {:ipv4addr => address}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,78 @@
1
+ module Infoblox
2
+ class Resource
3
+ attr_accessor :_ref
4
+
5
+ def self.wapi_object(obj=nil)
6
+ obj.nil? ? @wapi_object : @wapi_object = obj
7
+ end
8
+
9
+ def self.remote_attr_accessor(*args)
10
+ args.each do |a|
11
+ attr_accessor a
12
+ remote_attrs << a
13
+ end
14
+ end
15
+
16
+ def self.remote_attrs
17
+ @remote_attrs ||= []
18
+ end
19
+
20
+ def self.all
21
+ JSON.parse(connection.get(resource_uri).body).map do |item|
22
+ new(item)
23
+ end
24
+ end
25
+
26
+ def self.find(params)
27
+ JSON.parse(connection.get(resource_uri, params).body).map do |item|
28
+ new(item)
29
+ end
30
+ end
31
+
32
+ def self.connection
33
+ @@connection
34
+ end
35
+
36
+ def self.connection=(con)
37
+ @@connection = con
38
+ end
39
+
40
+ def self.resource_uri
41
+ BASE_PATH + self.wapi_object
42
+ end
43
+
44
+ def initialize(attrs={})
45
+ attrs.each do |k,v|
46
+ self.send("#{k}=", v)
47
+ end
48
+ end
49
+
50
+ def create
51
+ self._ref = connection.post(resource_uri, remote_attribute_hash).body
52
+ true
53
+ end
54
+
55
+ def delete
56
+ connection.delete(resource_uri).status == 200
57
+ end
58
+
59
+ def resource_uri
60
+ self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref)
61
+ end
62
+
63
+ private
64
+
65
+ def remote_attribute_hash
66
+ {}.tap do |hsh|
67
+ self.class.remote_attrs.each do |k|
68
+ hsh[k] = self.send(k)
69
+ end
70
+ end
71
+ end
72
+
73
+ def connection
74
+ self.class.connection
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Infoblox
2
+ VERSION = "0.0.1"
3
+ end
data/spec/host_spec.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ describe Infoblox::Host, "#add_ipv4addr" do
3
+ it "adds an address correctly" do
4
+ host = Infoblox::Host.new
5
+ host.add_ipv4addr("10.10.10.10")
6
+ host.add_ipv4addr("10.10.10.12")
7
+ host.ipv4addrs.should eq([{:ipv4addr => "10.10.10.10"}, {:ipv4addr => "10.10.10.12"}])
8
+ end
9
+ end
10
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ class FooResource < Infoblox::Resource
3
+ remote_attr_accessor :name, :junction
4
+ attr_accessor :animal
5
+ wapi_object "foo:animal"
6
+ end
7
+
8
+ describe Infoblox::Resource, "#add_ipv4addr" do
9
+ it "hashes correctly" do
10
+ host = FooResource.new
11
+ host._ref = "123"
12
+ host.animal = "mom"
13
+ host.name = "lol"
14
+ hsh = host.send(:remote_attribute_hash)
15
+ hsh.should eq({:name => 'lol', :junction => nil})
16
+ end
17
+
18
+ it "should have a correct resource_uri" do
19
+ FooResource.resource_uri.should eq(Infoblox::BASE_PATH + "foo:animal")
20
+ f=FooResource.new
21
+ f.resource_uri.should eq(Infoblox::BASE_PATH + "foo:animal")
22
+ f._ref = "lkjlkj"
23
+ f.resource_uri.should eq(Infoblox::BASE_PATH + "lkjlkj")
24
+ end
25
+ end
26
+
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require File.expand_path("../../lib/infoblox", __FILE__)
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infoblox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Billy Reisinger
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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: faraday_middleware
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
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: rspec
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: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.3'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: A Ruby wrapper to the Infoblox WAPI
111
+ email:
112
+ - billy.reisinger@govdelivery.com
113
+ executables:
114
+ - infoblox
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/infoblox
125
+ - infoblox.gemspec
126
+ - lib/infoblox.rb
127
+ - lib/infoblox/client.rb
128
+ - lib/infoblox/connection.rb
129
+ - lib/infoblox/host.rb
130
+ - lib/infoblox/resource.rb
131
+ - lib/infoblox/version.rb
132
+ - spec/host_spec.rb
133
+ - spec/resource_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: ''
136
+ licenses:
137
+ - MIT
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.25
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: This gem is a Ruby interface to the Infoblox WAPI. Only a few operations
160
+ are supported as of yet.
161
+ test_files:
162
+ - spec/host_spec.rb
163
+ - spec/resource_spec.rb
164
+ - spec/spec_helper.rb
165
+ has_rdoc: