ansible_tower_client 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/ansible_tower_client.rb +2 -0
- data/lib/ansible_tower_client/api.rb +8 -0
- data/lib/ansible_tower_client/collection.rb +33 -19
- data/lib/ansible_tower_client/group.rb +1 -1
- data/lib/ansible_tower_client/host.rb +1 -1
- data/lib/ansible_tower_client/inventory.rb +11 -1
- data/lib/ansible_tower_client/inventory_source.rb +21 -0
- data/lib/ansible_tower_client/inventory_update.rb +7 -0
- data/lib/ansible_tower_client/job.rb +10 -1
- data/lib/ansible_tower_client/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f17e37f15be38fac17b1390b9ad60ef854b457df
|
4
|
+
data.tar.gz: ada9722dc153f60e6fdc07b4de9e905e63fb4ccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b64e64a6f44d0db7db90890a0c7a88d34112b01a941aa676ea67f7bfe6c419d1f9dbb807fa494c1e609396d49a2b8115c8d82cb9323e9de33067da928579542
|
7
|
+
data.tar.gz: 6e2364801b7ea833a6a353bae1983371fe3726f21f67dd67f14a18e6e0131133d205513e048b1d2458f57ed857769f8edf2ab352023c4c69556beb409e22d599
|
data/lib/ansible_tower_client.rb
CHANGED
@@ -14,6 +14,8 @@ require "ansible_tower_client/ad_hoc_command"
|
|
14
14
|
require "ansible_tower_client/group"
|
15
15
|
require "ansible_tower_client/host"
|
16
16
|
require "ansible_tower_client/inventory"
|
17
|
+
require "ansible_tower_client/inventory_source"
|
18
|
+
require "ansible_tower_client/inventory_update"
|
17
19
|
require "ansible_tower_client/job"
|
18
20
|
require "ansible_tower_client/job_template"
|
19
21
|
require "more_core_extensions/all"
|
@@ -17,6 +17,14 @@ module AnsibleTowerClient
|
|
17
17
|
Collection.new(self, Inventory)
|
18
18
|
end
|
19
19
|
|
20
|
+
def inventory_sources
|
21
|
+
Collection.new(self, InventorySource)
|
22
|
+
end
|
23
|
+
|
24
|
+
def inventory_updates
|
25
|
+
Collection.new(self, InventoryUpdate)
|
26
|
+
end
|
27
|
+
|
20
28
|
def job_templates
|
21
29
|
Collection.new(self, JobTemplate)
|
22
30
|
end
|
@@ -1,43 +1,57 @@
|
|
1
1
|
module AnsibleTowerClient
|
2
2
|
class Collection
|
3
3
|
attr_reader :api, :klass
|
4
|
-
def initialize(api, klass)
|
4
|
+
def initialize(api, klass = nil)
|
5
5
|
@api = api
|
6
6
|
@klass = klass
|
7
7
|
end
|
8
8
|
|
9
9
|
def all
|
10
|
-
|
10
|
+
find_all_by_url(klass.endpoint)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
break if body["next"].nil?
|
18
|
-
body = JSON.parse(api.get(body["next"]).body)
|
19
|
-
results += body["results"]
|
20
|
-
end
|
13
|
+
def find_all_by_url(url)
|
14
|
+
Enumerator.new do |yielder|
|
15
|
+
@collection = []
|
16
|
+
next_page = url
|
21
17
|
|
22
|
-
|
18
|
+
loop do
|
19
|
+
next_page = fetch_more_results(next_page) if @collection.empty?
|
20
|
+
raise StopIteration if @collection.empty?
|
21
|
+
yielder.yield(@collection.shift)
|
22
|
+
end
|
23
|
+
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def find(id)
|
26
|
-
|
27
|
-
klass.new(api, raw_body)
|
27
|
+
build_object(parse_response(api.get("#{klass.endpoint}/#{id}/")))
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
-
def build_collection(results)
|
33
|
-
results.collect do |result|
|
34
|
-
class_from_type(result["type"]).new(api, result)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
32
|
def class_from_type(type)
|
39
33
|
camelized = type.split("_").collect(&:capitalize).join
|
40
34
|
AnsibleTowerClient.const_get(camelized)
|
41
35
|
end
|
36
|
+
|
37
|
+
def fetch_more_results(next_page)
|
38
|
+
return if next_page.nil?
|
39
|
+
body = parse_response(api.get(next_page))
|
40
|
+
parse_result_set(body["results"])
|
41
|
+
|
42
|
+
body["next"]
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse_response(response)
|
46
|
+
JSON.parse(response.body)
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_result_set(results)
|
50
|
+
results.each { |result| @collection << build_object(result) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_object(result)
|
54
|
+
class_from_type(result["type"]).new(api, result)
|
55
|
+
end
|
42
56
|
end
|
43
57
|
end
|
@@ -4,8 +4,18 @@ module AnsibleTowerClient
|
|
4
4
|
"inventories".freeze
|
5
5
|
end
|
6
6
|
|
7
|
+
def inventory_sources
|
8
|
+
Collection.new(api).find_all_by_url(related['inventory_sources'])
|
9
|
+
end
|
10
|
+
|
11
|
+
def update_all_inventory_sources
|
12
|
+
inventory_sources.each do |inventory_source|
|
13
|
+
inventory_source.update if inventory_source.can_update?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
def root_groups
|
8
|
-
|
18
|
+
Collection.new(api).find_all_by_url(related['root_groups'])
|
9
19
|
end
|
10
20
|
end
|
11
21
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module AnsibleTowerClient
|
2
|
+
class InventorySource < BaseModel
|
3
|
+
def self.endpoint
|
4
|
+
"inventory_sources".freeze
|
5
|
+
end
|
6
|
+
|
7
|
+
def can_update?
|
8
|
+
response = api.get("#{related['update']}").body
|
9
|
+
|
10
|
+
updatable = JSON.parse(response)
|
11
|
+
updatable['can_update']
|
12
|
+
end
|
13
|
+
|
14
|
+
def update
|
15
|
+
response = api.post("#{related['update']}").body
|
16
|
+
|
17
|
+
update = JSON.parse(response)
|
18
|
+
api.inventory_updates.find(update['inventory_update'])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -3,6 +3,15 @@ module AnsibleTowerClient
|
|
3
3
|
def self.endpoint
|
4
4
|
"jobs".freeze
|
5
5
|
end
|
6
|
+
|
7
|
+
def extra_vars_hash
|
8
|
+
extra_vars.empty? ? {} : hashify(:extra_vars)
|
9
|
+
end
|
10
|
+
|
11
|
+
def stdout
|
12
|
+
out_url = related['stdout']
|
13
|
+
return unless out_url
|
14
|
+
api.get("#{out_url}?format=txt").body
|
15
|
+
end
|
6
16
|
end
|
7
17
|
end
|
8
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansible_tower_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dunne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -165,6 +165,8 @@ files:
|
|
165
165
|
- lib/ansible_tower_client/hash_model.rb
|
166
166
|
- lib/ansible_tower_client/host.rb
|
167
167
|
- lib/ansible_tower_client/inventory.rb
|
168
|
+
- lib/ansible_tower_client/inventory_source.rb
|
169
|
+
- lib/ansible_tower_client/inventory_update.rb
|
168
170
|
- lib/ansible_tower_client/job.rb
|
169
171
|
- lib/ansible_tower_client/job_template.rb
|
170
172
|
- lib/ansible_tower_client/logging.rb
|
@@ -191,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
193
|
version: '0'
|
192
194
|
requirements: []
|
193
195
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
196
|
+
rubygems_version: 2.6.3
|
195
197
|
signing_key:
|
196
198
|
specification_version: 4
|
197
199
|
summary: Ansible Tower REST API wrapper gem
|