infoblox 0.2.18 → 0.2.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +71 -17
- data/lib/infoblox/resource/range.rb +22 -0
- data/lib/infoblox/version.rb +1 -1
- data/spec/range_spec.rb +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508ca735479d7b411af21c7ce8550d4ef25c975c
|
4
|
+
data.tar.gz: 4f03b3a3aea91f5e4c550d421c4275c408e2b815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68601ca1df42b361dcef26994e0d593a9fb109999be9b1c4619e96b40872041676eb4852da3136c93caf6beeaa8ac2ef29879438b5d9559cbcb290696af209bc
|
7
|
+
data.tar.gz: 30207ba646bcaff6a93fdce90c6772444352f74f837d8eb6ffc1ddf1e5891267b7213ede175da772a019662c4bf51fcfd3a27919bfa1e3e3bd9de57aef6d06c5
|
data/README.md
CHANGED
@@ -22,33 +22,36 @@ Or install it yourself as:
|
|
22
22
|
## Connecting
|
23
23
|
An instance of the `Infoblox::Connection` class is necessary:
|
24
24
|
|
25
|
-
connection = Infoblox::Connection.new(:
|
25
|
+
connection = Infoblox::Connection.new(username: '', password: '', host: '')
|
26
26
|
|
27
|
-
##
|
28
|
-
|
27
|
+
## Reading
|
28
|
+
Each resource class implements `all` and `find`. You can use the `_max_results` and `_return_fields` parameters for both of these methods. See the Infoblox WAPI documentation on how to use these parameters.
|
29
29
|
|
30
30
|
# Find all networks. Note that this is limited to 1000 objects, as per the
|
31
31
|
# Infoblox WAPI documentation.
|
32
32
|
Infoblox::Network.all(connection)
|
33
33
|
# => [...]
|
34
34
|
|
35
|
-
#
|
36
|
-
Infoblox::Network.all(connection, :
|
35
|
+
# If you want more than 1,000 records, use `_max_results`:
|
36
|
+
Infoblox::Network.all(connection, _max_results: 7890)
|
37
37
|
|
38
|
-
#
|
38
|
+
# You can find hosts that match a regular expression:
|
39
39
|
Infoblox::Host.find(connection, {"name~" => "demo[0-9]{1,}-web.domain"})
|
40
40
|
# => [...]
|
41
41
|
|
42
|
+
The usage of search parameters is well-documented in the Infoblox WAPI documentation, and this client supports them fully.
|
43
|
+
|
44
|
+
## Searching
|
42
45
|
You can also search across the Infoblox cluster using the `Infoblox::Search` resource. The response will contain any number of `Infoblox::Resource` subclass instances.
|
43
46
|
|
44
47
|
result = Infoblox::Search.find(connection, "search_string~" => "webserver-")
|
45
48
|
# => [#<Infoblox::Host>, #<Infoblox::Ptr>, ...]
|
46
49
|
|
47
|
-
##
|
48
|
-
The resource class instances
|
50
|
+
## Writing and deleting
|
51
|
+
The resource class instances implement `get`, `post`, `put`, and `delete` methods, which correspond to the REST verbs supported by the WAPI. For example, here is how to create, update, and delete a network:
|
49
52
|
|
50
53
|
# create
|
51
|
-
network = Infoblox::Network.new(:
|
54
|
+
network = Infoblox::Network.new(connection: connection)
|
52
55
|
network.network = "10.20.30.0/24"
|
53
56
|
network.extensible_attributes = {"VLAN" => "my_vlan"}
|
54
57
|
network.auto_create_reversezone = true
|
@@ -58,6 +61,27 @@ The resource class instances support `get`, `post`, `put`, and `delete`. For ex
|
|
58
61
|
network.network = "10.20.31.0/24"
|
59
62
|
network.put
|
60
63
|
|
64
|
+
# delete
|
65
|
+
network.delete
|
66
|
+
|
67
|
+
This pattern applies for interacting with every resource. Supported resources include:
|
68
|
+
|
69
|
+
Infoblox::Arecord
|
70
|
+
Infoblox::Cname
|
71
|
+
Infoblox::FixedAddress
|
72
|
+
Infoblox::Host
|
73
|
+
Infoblox::HostIpv4addr
|
74
|
+
Infoblox::Ipv4address
|
75
|
+
Infoblox::Mx
|
76
|
+
Infoblox::Network
|
77
|
+
Infoblox::NetworkContainer
|
78
|
+
Infoblox::Ptr
|
79
|
+
Infoblox::Search
|
80
|
+
Infoblox::Srv
|
81
|
+
Infoblox::Txt
|
82
|
+
|
83
|
+
The specific attributes supported by each resource are listed in the source code.
|
84
|
+
|
61
85
|
## Changing IP on an existing host
|
62
86
|
To change the IP of an existing host, you have to poke around in the ipv4addrs collection to find the one you are looking for. The example below assumes that there is only one ipv4 address and just overwrites it.
|
63
87
|
|
@@ -71,21 +95,34 @@ To do basic create/update/delete operations on an a_record/ptr_record set:
|
|
71
95
|
|
72
96
|
Create:
|
73
97
|
|
74
|
-
a_record = Infoblox::Arecord.new(
|
98
|
+
a_record = Infoblox::Arecord.new(
|
99
|
+
connection: connection,
|
100
|
+
name: <fqdn>,
|
101
|
+
ipv4addr: <ip_address>)
|
75
102
|
a_record.post
|
76
103
|
|
77
|
-
ptr_record = Infoblox::Ptr.new(
|
104
|
+
ptr_record = Infoblox::Ptr.new(
|
105
|
+
connection: connection,
|
106
|
+
ptrdname: <fqdn>,
|
107
|
+
ipv4addr: <ip_address>)
|
78
108
|
ptr_record.post
|
79
109
|
|
80
110
|
Update:
|
81
111
|
|
82
|
-
a_record = Infoblox::Arecord.find(connection, {
|
83
|
-
|
112
|
+
a_record = Infoblox::Arecord.find(connection, {
|
113
|
+
name: <fqdn>,
|
114
|
+
ipv4addr: <ip_address>
|
115
|
+
}).first
|
116
|
+
a_record.name = <fqdn>
|
84
117
|
a_record.ipv4addr = <ip_address>
|
85
|
-
a_record.view
|
118
|
+
a_record.view = nil
|
86
119
|
a_record.put
|
87
120
|
|
88
|
-
ptr_record = Infoblox::Ptr.find(connection, {
|
121
|
+
ptr_record = Infoblox::Ptr.find(connection, {
|
122
|
+
ptrdname: <fqdn>,
|
123
|
+
ipv4addr: <ip_address>
|
124
|
+
}).first
|
125
|
+
|
89
126
|
ptr_record.ptrdname = <fqdn>
|
90
127
|
ptr_record.ipv4addr = <ip_address>
|
91
128
|
ptr_record.view = nil
|
@@ -93,12 +130,29 @@ Update:
|
|
93
130
|
|
94
131
|
Delete:
|
95
132
|
|
96
|
-
a_record = Infoblox::Arecord.find(connection, {
|
133
|
+
a_record = Infoblox::Arecord.find(connection, {
|
134
|
+
name: <fqdn>,
|
135
|
+
ipv4addr: <ip_address>
|
136
|
+
}).first
|
97
137
|
a_record.delete
|
98
138
|
|
99
|
-
ptr_record = Infoblox::Ptr.find(connection, {
|
139
|
+
ptr_record = Infoblox::Ptr.find(connection, {
|
140
|
+
ptrdname: <fqdn>,
|
141
|
+
ipv4addr: <ip_address>
|
142
|
+
}).first
|
100
143
|
ptr_record.delete
|
101
144
|
|
145
|
+
## Next Available IP
|
146
|
+
|
147
|
+
The `Infoblox::Network` object supports the `next_available_ip` WAPI function:
|
148
|
+
|
149
|
+
network = Infoblox::Network.find(connection,
|
150
|
+
network: '10.21.0.0/24').first
|
151
|
+
puts network.next_available_ip.inspect
|
152
|
+
#=> ["10.21.0.22"]
|
153
|
+
|
154
|
+
Note that this function does not work on a `Network` that has not been created. In other words, if you want to get the next available IP for a given network segment, you have to create that segment beforehand. See the CRUD examples above.
|
155
|
+
|
102
156
|
## Contributing
|
103
157
|
|
104
158
|
1. Fork it
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Infoblox
|
2
|
+
class Range < Resource
|
3
|
+
remote_attr_accessor :start_addr, :end_addr, :network_view, :extattrs
|
4
|
+
|
5
|
+
wapi_object "range"
|
6
|
+
|
7
|
+
##
|
8
|
+
# Invoke the same-named function on the range resource in WAPI,
|
9
|
+
# returning an array of available IP addresses.
|
10
|
+
# You may optionally specify how many IPs you want (num) and which ones to
|
11
|
+
# exclude from consideration (array of IPv4 addrdess strings).
|
12
|
+
#
|
13
|
+
def next_available_ip(num=1, exclude=[])
|
14
|
+
post_body = {
|
15
|
+
num: num.to_i,
|
16
|
+
exclude: exclude
|
17
|
+
}
|
18
|
+
JSON.parse(connection.post(resource_uri + "?_function=next_available_ip", post_body).body)["ips"]
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/infoblox/version.rb
CHANGED
data/spec/range_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RangeResponse = Struct.new(:body)
|
4
|
+
|
5
|
+
describe Infoblox::Host, "#next_available_ip" do
|
6
|
+
it "returns empty array when no IP is available." do
|
7
|
+
connection = double
|
8
|
+
uri = Infoblox::BASE_PATH + Infoblox::Range.wapi_object
|
9
|
+
return_json = RangeResponse.new('{"ips": "[]"}')
|
10
|
+
allow(connection).to receive(:post).with(uri + "?_function=next_available_ip" , {:num=>1, :exclude=>[]}).and_return(return_json)
|
11
|
+
response = Infoblox::Range.new(:connection => connection)
|
12
|
+
expect(response.next_available_ip).to eq '[]'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "gets next available ip from range" do
|
16
|
+
connection = double
|
17
|
+
uri = Infoblox::BASE_PATH + Infoblox::Range.wapi_object
|
18
|
+
return_json = RangeResponse.new('
|
19
|
+
{
|
20
|
+
"ips": "[\"1.1.1.1\", \"1.1.1.2\"]"
|
21
|
+
}')
|
22
|
+
allow(connection).to receive(:post).with(uri + "?_function=next_available_ip" , {:num=>1, :exclude=>[]}).and_return(return_json)
|
23
|
+
response = Infoblox::Range.new(:connection => connection)
|
24
|
+
expect(response.next_available_ip).to eq '["1.1.1.1", "1.1.1.2"]'
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infoblox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Billy Reisinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/infoblox/resource/network.rb
|
123
123
|
- lib/infoblox/resource/network_container.rb
|
124
124
|
- lib/infoblox/resource/ptr.rb
|
125
|
+
- lib/infoblox/resource/range.rb
|
125
126
|
- lib/infoblox/resource/search.rb
|
126
127
|
- lib/infoblox/resource/srv.rb
|
127
128
|
- lib/infoblox/resource/txt.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- spec/connection_spec.rb
|
130
131
|
- spec/host_ipv4addr_spec.rb
|
131
132
|
- spec/host_spec.rb
|
133
|
+
- spec/range_spec.rb
|
132
134
|
- spec/resource_spec.rb
|
133
135
|
- spec/search_spec.rb
|
134
136
|
- spec/spec_helper.rb
|
@@ -161,6 +163,7 @@ test_files:
|
|
161
163
|
- spec/connection_spec.rb
|
162
164
|
- spec/host_ipv4addr_spec.rb
|
163
165
|
- spec/host_spec.rb
|
166
|
+
- spec/range_spec.rb
|
164
167
|
- spec/resource_spec.rb
|
165
168
|
- spec/search_spec.rb
|
166
169
|
- spec/spec_helper.rb
|