ansible_tower_client 0.3.3 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b4033eccf795a162c27652f2edc7153a2e4a231
4
- data.tar.gz: ccf4bb477367817aaff6ab888201a85d5b145b4a
3
+ metadata.gz: acc09f7903cf4344a5aecf388e01e96ec4ddbacb
4
+ data.tar.gz: 1f9c7426089f8e860848e95a5fc10cb73d7748fd
5
5
  SHA512:
6
- metadata.gz: 86d98c1afcb527c6c8795e2613d64d313c25df0f8b3a659afc27fcec04432ef16deb5bba25754571e18eb308c00004264a2db6aa0f6717e724c66c67b2243d1c
7
- data.tar.gz: 91f5bb1f97fd1092358e3741d3e150a459aa7be27315ec1cdcaefbf9a9f6b87545ce6fd69132868727c219f8c3346d9cbaac1a66aea4e150a3e03879d66e2a90
6
+ metadata.gz: e2907f826fc08aded95a7db83c5278a410cdc7ac1be5c770d30fc92658c12bb551e8df55073b02afdcb1375c952be321be13da6749135492155bd3bd99639a9c
7
+ data.tar.gz: a235ecafbf062ed0e5e5bba221383ea808943d3823fb8b2f7fbbc743d8a407ccc06fe6acb9fac6774ae578e92ecb8c9cf550a8e2c866762bda585adfc7674cb0
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in ansible_tower_client.gemspec
4
4
  gemspec
5
+
6
+ # HACK: Rails 5 dropped support for Ruby < 2.2.2
7
+ active_support_version = "< 5" if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
8
+ gem "activesupport", active_support_version
data/README.md CHANGED
@@ -4,6 +4,8 @@
4
4
  [![Build Status](https://travis-ci.org/ManageIQ/ansible_tower_client.svg)](https://travis-ci.org/ManageIQ/ansible_tower_client)
5
5
  [![Code Climate](https://codeclimate.com/github/ManageIQ/ansible_tower_client/badges/gpa.svg)](https://codeclimate.com/github/ManageIQ/ansible_tower_client)
6
6
  [![Dependency Status](https://gemnasium.com/ManageIQ/ansible_tower_client.svg)](https://gemnasium.com/ManageIQ/ansible_tower_client)
7
+ [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/ansible_tower_client.svg)](https://coveralls.io/r/ManageIQ/ansible_tower_client)
8
+ [![Security](https://hakiri.io/github/ManageIQ/ansible_tower_client/master.svg)](https://hakiri.io/github/ManageIQ/ansible_tower_client/master)
7
9
 
8
10
  ## Installation
9
11
 
@@ -19,10 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- # HACK: Rails 5 dropped support for Ruby < 2.2.2
23
- active_support_version = "< 5" if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new("2.2.2")
24
- spec.add_runtime_dependency "activesupport", active_support_version
25
-
22
+ spec.add_runtime_dependency "activesupport"
26
23
  spec.add_runtime_dependency "faraday"
27
24
  spec.add_runtime_dependency "faraday_middleware"
28
25
  spec.add_runtime_dependency "more_core_extensions", "~> 3.0"
@@ -11,14 +11,17 @@ require "ansible_tower_client/hash_model"
11
11
  require "ansible_tower_client/base_model"
12
12
  require "ansible_tower_client/collection"
13
13
 
14
- require "ansible_tower_client/ad_hoc_command"
15
- require "ansible_tower_client/group"
16
- require "ansible_tower_client/host"
17
- require "ansible_tower_client/inventory"
18
- require "ansible_tower_client/inventory_source"
19
- require "ansible_tower_client/inventory_update"
20
- require "ansible_tower_client/job"
21
- require "ansible_tower_client/job_template"
14
+ require "ansible_tower_client/base_models/ad_hoc_command"
15
+ require "ansible_tower_client/base_models/group"
16
+ require "ansible_tower_client/base_models/host"
17
+ require "ansible_tower_client/base_models/inventory"
18
+ require "ansible_tower_client/base_models/inventory_source"
19
+ require "ansible_tower_client/base_models/inventory_update"
20
+ require "ansible_tower_client/base_models/job"
21
+ require "ansible_tower_client/base_models/job_template"
22
+
23
+ require "ansible_tower_client/v2/job_template_v2"
24
+
22
25
  require "more_core_extensions/all"
23
26
  require "active_support/inflector"
24
27
 
@@ -5,36 +5,48 @@ module AnsibleTowerClient
5
5
  @instance = connection
6
6
  end
7
7
 
8
- def hosts
9
- Collection.new(self, Host)
8
+ def config
9
+ JSON.parse(get("config").body)
10
+ end
11
+
12
+ def version
13
+ @version ||= config["version"]
14
+ end
15
+
16
+ def verify_credentials
17
+ JSON.parse(get("me").body).fetch_path("results", 0, "username")
18
+ end
19
+
20
+ def ad_hoc_commands
21
+ Collection.new(self, ad_hoc_command_class)
10
22
  end
11
23
 
12
24
  def groups
13
- Collection.new(self, Group)
25
+ Collection.new(self, group_class)
26
+ end
27
+
28
+ def hosts
29
+ Collection.new(self, host_class)
14
30
  end
15
31
 
16
32
  def inventories
17
- Collection.new(self, Inventory)
33
+ Collection.new(self, inventory_class)
18
34
  end
19
35
 
20
36
  def inventory_sources
21
- Collection.new(self, InventorySource)
37
+ Collection.new(self, inventory_source_class)
22
38
  end
23
39
 
24
40
  def inventory_updates
25
- Collection.new(self, InventoryUpdate)
26
- end
27
-
28
- def job_templates
29
- Collection.new(self, JobTemplate)
41
+ Collection.new(self, inventory_update_class)
30
42
  end
31
43
 
32
- def ad_hoc_commands
33
- Collection.new(self, AdHocCommand)
44
+ def jobs
45
+ Collection.new(self, job_class)
34
46
  end
35
47
 
36
- def jobs
37
- Collection.new(self, Job)
48
+ def job_templates
49
+ Collection.new(self, job_template_class)
38
50
  end
39
51
 
40
52
  def method_missing(method_name, *args, &block)
@@ -50,5 +62,45 @@ module AnsibleTowerClient
50
62
  def respond_to_missing?(method, _include_private = false)
51
63
  instance.respond_to?(method)
52
64
  end
65
+
66
+ # Object class accessors patched for the appropriate version of the API
67
+
68
+ def ad_hoc_command_class
69
+ @ad_hoc_command_class ||= AnsibleTowerClient::AdHocCommand
70
+ end
71
+
72
+ def group_class
73
+ @group_class ||= AnsibleTowerClient::Group
74
+ end
75
+
76
+ def host_class
77
+ @host_class ||= AnsibleTowerClient::Host
78
+ end
79
+
80
+ def inventory_class
81
+ @inventory_class ||= AnsibleTowerClient::Inventory
82
+ end
83
+
84
+ def inventory_source_class
85
+ @inventory_source_class ||= AnsibleTowerClient::InventorySource
86
+ end
87
+
88
+ def inventory_update_class
89
+ @inventory_update_class ||= AnsibleTowerClient::InventoryUpdate
90
+ end
91
+
92
+ def job_class
93
+ @job_class ||= AnsibleTowerClient::Job
94
+ end
95
+
96
+ def job_template_class
97
+ @job_template_class ||= begin
98
+ if Gem::Version.new(version).between?(Gem::Version.new(2), Gem::Version.new(3))
99
+ AnsibleTowerClient::JobTemplateV2
100
+ else
101
+ AnsibleTowerClient::JobTemplate
102
+ end
103
+ end
104
+ end
53
105
  end
54
106
  end
@@ -2,6 +2,10 @@ module AnsibleTowerClient
2
2
  class BaseModel < HashModel
3
3
  attr_reader :api
4
4
 
5
+ def self.base_class
6
+ superclass == AnsibleTowerClient::BaseModel ? self : superclass.base_class
7
+ end
8
+
5
9
  # Constructs and returns a new JSON wrapper class. Pass in a plain
6
10
  # JSON string and it will automatically give you accessor methods
7
11
  # that make it behave like a typical Ruby object. You may also pass
@@ -9,4 +9,3 @@ module AnsibleTowerClient
9
9
  end
10
10
  end
11
11
  end
12
-
@@ -5,14 +5,14 @@ module AnsibleTowerClient
5
5
  end
6
6
 
7
7
  def can_update?
8
- response = api.get("#{related['update']}").body
8
+ response = api.get(related['update'].to_s).body
9
9
 
10
10
  updatable = JSON.parse(response)
11
11
  updatable['can_update']
12
12
  end
13
13
 
14
14
  def update
15
- response = api.post("#{related['update']}").body
15
+ response = api.post(related['update'].to_s).body
16
16
 
17
17
  update = JSON.parse(response)
18
18
  api.inventory_updates.find(update['inventory_update'])
@@ -0,0 +1,28 @@
1
+ module AnsibleTowerClient
2
+ class JobTemplate < BaseModel
3
+ def launch(options = {})
4
+ launch_url = "#{url}launch/"
5
+ response = api.post(launch_url, options).body
6
+ job = JSON.parse(response)
7
+ api.jobs.find(job['job'])
8
+ end
9
+
10
+ def survey_spec
11
+ spec_url = related['survey_spec']
12
+ return nil unless spec_url
13
+ api.get(spec_url).body
14
+ end
15
+
16
+ def survey_spec_hash
17
+ survey_spec.nil? ? {} : hashify(:survey_spec)
18
+ end
19
+
20
+ def extra_vars_hash
21
+ extra_vars.empty? ? {} : hashify(:extra_vars)
22
+ end
23
+
24
+ def self.endpoint
25
+ "job_templates".freeze
26
+ end
27
+ end
28
+ end
@@ -30,8 +30,7 @@ module AnsibleTowerClient
30
30
  private
31
31
 
32
32
  def class_from_type(type)
33
- camelized = type.split("_").collect(&:capitalize).join
34
- AnsibleTowerClient.const_get(camelized)
33
+ api.send("#{type}_class")
35
34
  end
36
35
 
37
36
  def fetch_more_results(next_page)
@@ -25,17 +25,5 @@ module AnsibleTowerClient
25
25
  def api
26
26
  @api ||= Api.new(connection)
27
27
  end
28
-
29
- def config
30
- JSON.parse(api.get("config").body)
31
- end
32
-
33
- def version
34
- config["version"]
35
- end
36
-
37
- def verify_credentials
38
- JSON.parse(api.get("me").body).fetch_path("results", 0, "username")
39
- end
40
28
  end
41
29
  end
@@ -1,5 +1,5 @@
1
1
  module AnsibleTowerClient
2
- class JobTemplate < BaseModel
2
+ class JobTemplateV2 < JobTemplate
3
3
  def launch(options = {})
4
4
  launch_url = "#{url}launch/"
5
5
  options = options.dup
@@ -12,24 +12,6 @@ module AnsibleTowerClient
12
12
  api.jobs.find(job['job'])
13
13
  end
14
14
 
15
- def survey_spec
16
- spec_url = related['survey_spec']
17
- return nil unless spec_url
18
- api.get(spec_url).body
19
- end
20
-
21
- def survey_spec_hash
22
- survey_spec.nil? ? {} : hashify(:survey_spec)
23
- end
24
-
25
- def extra_vars_hash
26
- extra_vars.empty? ? {} : hashify(:extra_vars)
27
- end
28
-
29
- def self.endpoint
30
- "job_templates".freeze
31
- end
32
-
33
15
  private
34
16
 
35
17
  def with_temporary_changes(in_limit)
@@ -1,3 +1,3 @@
1
1
  module AnsibleTowerClient
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.3
4
+ version: 0.4.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-08-11 00:00:00.000000000 Z
12
+ date: 2016-10-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -156,23 +156,24 @@ files:
156
156
  - bin/console
157
157
  - bin/setup
158
158
  - lib/ansible_tower_client.rb
159
- - lib/ansible_tower_client/ad_hoc_command.rb
160
159
  - lib/ansible_tower_client/api.rb
161
160
  - lib/ansible_tower_client/base_model.rb
161
+ - lib/ansible_tower_client/base_models/ad_hoc_command.rb
162
+ - lib/ansible_tower_client/base_models/group.rb
163
+ - lib/ansible_tower_client/base_models/host.rb
164
+ - lib/ansible_tower_client/base_models/inventory.rb
165
+ - lib/ansible_tower_client/base_models/inventory_source.rb
166
+ - lib/ansible_tower_client/base_models/inventory_update.rb
167
+ - lib/ansible_tower_client/base_models/job.rb
168
+ - lib/ansible_tower_client/base_models/job_template.rb
162
169
  - lib/ansible_tower_client/collection.rb
163
170
  - lib/ansible_tower_client/connection.rb
164
171
  - lib/ansible_tower_client/exception.rb
165
- - lib/ansible_tower_client/group.rb
166
172
  - lib/ansible_tower_client/hash_model.rb
167
- - lib/ansible_tower_client/host.rb
168
- - lib/ansible_tower_client/inventory.rb
169
- - lib/ansible_tower_client/inventory_source.rb
170
- - lib/ansible_tower_client/inventory_update.rb
171
- - lib/ansible_tower_client/job.rb
172
- - lib/ansible_tower_client/job_template.rb
173
173
  - lib/ansible_tower_client/logging.rb
174
174
  - lib/ansible_tower_client/middleware/raise_tower_error.rb
175
175
  - lib/ansible_tower_client/null_logger.rb
176
+ - lib/ansible_tower_client/v2/job_template_v2.rb
176
177
  - lib/ansible_tower_client/version.rb
177
178
  homepage: https://github.com/ManageIQ/ansible_tower_client
178
179
  licenses: