infoblox 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,10 +17,13 @@ Or install it yourself as:
17
17
  $ gem install infoblox
18
18
 
19
19
  # Usage
20
- An instance of the Infoblox::Connection class is necessary:
20
+
21
+ ## Connecting
22
+ An instance of the `Infoblox::Connection` class is necessary:
21
23
 
22
24
  connection = Infoblox::Connection.new(:username => '', :password => '', :host => '')
23
25
 
26
+ ## Querying
24
27
  Once a connection is made, one can use the resource class methods to query records:
25
28
 
26
29
  Infoblox::Network.all(connection)
@@ -29,6 +32,11 @@ Once a connection is made, one can use the resource class methods to query recor
29
32
  Infoblox::Host.find(connection, {"name~" => "demo[0-9]{1,}-web.domain"})
30
33
  # => [...]
31
34
 
35
+ You can also search across the Infoblox cluster using the `Infoblox::Search` resource. The response will contain any number of `Infoblox::Resource` subclass instances.
36
+
37
+ result = Infoblox::Search.new(connection, "search_string~" => "webserver-")
38
+
39
+ ## Creating, updating, and deleting resources
32
40
  The resource class instances support `get`, `post`, `put`, and `delete`. For example, creating a network is pretty straightforward:
33
41
 
34
42
  network = Infoblox::Network.new(:connection => connection)
@@ -39,6 +47,7 @@ The resource class instances support `get`, `post`, `put`, and `delete`. For ex
39
47
  network.network = "10.20.31.0/24"
40
48
  network.put # true
41
49
 
50
+
42
51
  ## Contributing
43
52
 
44
53
  1. Fork it
data/lib/infoblox.rb CHANGED
@@ -7,14 +7,10 @@ require 'infoblox/version'
7
7
  require 'infoblox/connection'
8
8
  require 'infoblox/resource'
9
9
 
10
- require 'infoblox/resource/cname'
11
- require 'infoblox/resource/host'
12
- require 'infoblox/resource/host_ipv4addr'
13
- require 'infoblox/resource/arecord'
14
- require 'infoblox/resource/ipv4addr'
15
- require 'infoblox/resource/network'
16
- require 'infoblox/resource/network_container'
17
- require 'infoblox/resource/ptr'
10
+ # Require everything in the resource directory
11
+ Dir[File.expand_path('../infoblox/resource/*.rb', __FILE__)].each do |f|
12
+ require f
13
+ end
18
14
 
19
15
  module Infoblox
20
16
  WAPI_VERSION = '1.0'
@@ -3,7 +3,12 @@ module Infoblox
3
3
  attr_accessor :_ref, :connection
4
4
 
5
5
  def self.wapi_object(obj=nil)
6
- obj.nil? ? @wapi_object : @wapi_object = obj
6
+ if obj.nil?
7
+ @wapi_object
8
+ else
9
+ self.resource_map[obj] = self
10
+ @wapi_object = obj
11
+ end
7
12
  end
8
13
 
9
14
  ##
@@ -87,6 +92,14 @@ module Infoblox
87
92
  BASE_PATH + self.wapi_object
88
93
  end
89
94
 
95
+ ##
96
+ # A hash that maps Infoblox WAPI object identifiers to subclasses of Resource.
97
+ # Used by the Search resource for mapping response objects.
98
+ #
99
+ def self.resource_map
100
+ @@resource_map ||= {}
101
+ end
102
+
90
103
  def initialize(attrs={})
91
104
  attrs.each do |k,v|
92
105
  self.send("#{k}=", v)
@@ -0,0 +1,8 @@
1
+ module Infoblox
2
+ class Mx < Resource
3
+ remote_attr_accessor :mail_exchanger, :name, :preference,
4
+ :extensible_attributes, :view
5
+
6
+ wapi_object "record:mx"
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ module Infoblox
2
+ class Search < Resource
3
+ wapi_object "search"
4
+
5
+ # does not return objects not implemented in this library
6
+ def self.find(connection, params)
7
+ JSON.parse(connection.get(resource_uri,params).body).map do |jobj|
8
+ klass = resource_map[jobj["_ref"].split("/").first]
9
+ if klass.nil?
10
+ puts jobj['_ref']
11
+ warn "umapped resource: #{jobj["_ref"]}"
12
+ else
13
+ klass.new(jobj.merge({:connection => connection}))
14
+ end
15
+ end.compact
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Infoblox
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
@@ -61,5 +61,15 @@ describe Infoblox::Resource, "#add_ipv4addr" do
61
61
  f.post
62
62
  f._ref.should eq('abcdefg')
63
63
  end
64
+
65
+ it 'should map wapi objects to classes' do
66
+ @expected = {}
67
+ ObjectSpace.each_object(Class) do |p|
68
+ if p < Infoblox::Resource
69
+ @expected[p.wapi_object] = p
70
+ end
71
+ end
72
+ Infoblox::Resource.resource_map.should eq(@expected)
73
+ end
64
74
  end
65
75
 
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+ SearchResponse = Struct.new(:body)
3
+
4
+ describe Infoblox::Search, ".find" do
5
+ it "searches correctly" do
6
+ conn = double
7
+
8
+ # empty response
9
+ return_json = SearchResponse.new("[]")
10
+ uri = Infoblox::BASE_PATH + Infoblox::Search.wapi_object
11
+ allow(conn).to receive(:get).with(uri, {"search_string~" => "foo"}).and_return(return_json)
12
+ Infoblox::Search.find(conn, "search_string~" => "foo").should eq([])
13
+
14
+ # response with host
15
+ return_json = SearchResponse.new('[
16
+ {
17
+ "_ref": "record:host/ZG5zLmhvc3QkLl9kZWZhdWx0LmdkaS50b3BzLmRtei1tYWlsc2VuZGVycy5xYy1nb3ZpcG10YTItZXA:foo-bar-baz.inner.domain/Organization",
18
+ "ipv4addrs": [
19
+ {
20
+ "_ref": "record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQuZ2RpLnRvcHMuZG16LW1haWxzZW5kZXJzLnFjLWdvdmlwbXRhMi1lcC4xNzIuMjQuNC4xODQu:10.10.10.10/foo-bar-baz.inner.domain/Organization",
21
+ "configure_for_dhcp": false,
22
+ "host": "foo-bar-baz.inner.domain",
23
+ "ipv4addr": "10.10.10.10"
24
+ }
25
+ ],
26
+ "name": "foo-bar-baz.inner.domain",
27
+ "view": "Organization"
28
+ }
29
+ ]')
30
+ allow(conn).to receive(:get).with(uri, {"search_string~" => "foo"}).and_return(return_json)
31
+ result = Infoblox::Search.find(conn, "search_string~" => "foo")
32
+ result[0].should be_a(Infoblox::Host)
33
+ host = result[0]
34
+ host.name.should eq("foo-bar-baz.inner.domain")
35
+ end
36
+ end
37
+
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infoblox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Billy Reisinger
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-03-04 00:00:00.000000000 Z
12
+ date: 2014-03-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: faraday
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: faraday_middleware
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rspec
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: bundler
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ~>
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ~>
67
76
  - !ruby/object:Gem::Version
@@ -69,6 +78,7 @@ dependencies:
69
78
  - !ruby/object:Gem::Dependency
70
79
  name: rake
71
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
72
82
  requirements:
73
83
  - - ! '>='
74
84
  - !ruby/object:Gem::Version
@@ -76,6 +86,7 @@ dependencies:
76
86
  type: :development
77
87
  prerelease: false
78
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
79
90
  requirements:
80
91
  - - ! '>='
81
92
  - !ruby/object:Gem::Version
@@ -83,6 +94,7 @@ dependencies:
83
94
  - !ruby/object:Gem::Dependency
84
95
  name: pry
85
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
86
98
  requirements:
87
99
  - - ! '>='
88
100
  - !ruby/object:Gem::Version
@@ -90,6 +102,7 @@ dependencies:
90
102
  type: :development
91
103
  prerelease: false
92
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
93
106
  requirements:
94
107
  - - ! '>='
95
108
  - !ruby/object:Gem::Version
@@ -116,41 +129,52 @@ files:
116
129
  - lib/infoblox/resource/host.rb
117
130
  - lib/infoblox/resource/host_ipv4addr.rb
118
131
  - lib/infoblox/resource/ipv4addr.rb
132
+ - lib/infoblox/resource/mx.rb
119
133
  - lib/infoblox/resource/network.rb
120
134
  - lib/infoblox/resource/network_container.rb
121
135
  - lib/infoblox/resource/ptr.rb
136
+ - lib/infoblox/resource/search.rb
122
137
  - lib/infoblox/version.rb
123
138
  - spec/connection_spec.rb
124
139
  - spec/host_spec.rb
125
140
  - spec/resource_spec.rb
141
+ - spec/search_spec.rb
126
142
  - spec/spec_helper.rb
127
143
  homepage: https://github.com/govdelivery/infoblox
128
144
  licenses:
129
145
  - MIT
130
- metadata: {}
131
146
  post_install_message:
132
147
  rdoc_options: []
133
148
  require_paths:
134
149
  - lib
135
150
  required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
136
152
  requirements:
137
153
  - - ! '>='
138
154
  - !ruby/object:Gem::Version
139
155
  version: '0'
156
+ segments:
157
+ - 0
158
+ hash: 142878646732084018
140
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
141
161
  requirements:
142
162
  - - ! '>='
143
163
  - !ruby/object:Gem::Version
144
164
  version: '0'
165
+ segments:
166
+ - 0
167
+ hash: 142878646732084018
145
168
  requirements: []
146
169
  rubyforge_project:
147
- rubygems_version: 2.2.2
170
+ rubygems_version: 1.8.24
148
171
  signing_key:
149
- specification_version: 4
172
+ specification_version: 3
150
173
  summary: This gem is a Ruby interface to the Infoblox WAPI. Resources supported for
151
174
  REST operations include CNAME, Host, HostIpv4addr, Ipv4addr, Network, and NewtorkContainer.
152
175
  test_files:
153
176
  - spec/connection_spec.rb
154
177
  - spec/host_spec.rb
155
178
  - spec/resource_spec.rb
179
+ - spec/search_spec.rb
156
180
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWUzYzAzOGIwNGZlM2E2ZmY2N2E4MjRkMWE0MDgwNTE1MmFiZDdjNg==
5
- data.tar.gz: !binary |-
6
- NjJjMDM0MDBlOThhMzYzYjMyMDlhNWE2ZDZiODVkMGEyNWQ2MGIxNA==
7
- SHA512:
8
- metadata.gz: !binary |-
9
- N2VmODA3YWNlMmMwMzFkMTQ5NWZhYTM3Y2ZkNWRhMGEwYjI0ZDc2MDNhMDIx
10
- MTU5MzNkYjkyYzQxYzdlODBmNDQ1NWNiZTY2NDg2OTE5MjUyMzE0NGMzNjg1
11
- ZjM3MzIxZWUyMGUzYTlmZmU5ZjY4NzMzYjVlOTE5MGNmNTc3MWM=
12
- data.tar.gz: !binary |-
13
- MmUwYWFiN2Q0YTkxNWZkNzYyZjY5N2RmZjZjNmJjMzE1MjhiM2Y1YWQyNWY3
14
- YzdlNTg5OTk1MTJjMjYyZjA2ZGExNDg5NzY1N2JjOTI2MDYzOTg5Y2FmZjU5
15
- ZWNkZTFjODRmYzZjNDEzNjhhZjc1ZjM5MjAwZmRhYjQ3ZWYxNWY=