Class: AnsibleTowerClient::Api

Inherits:
Connection show all
Includes:
Logging
Defined in:
lib/ansible_tower_client/api.rb

Constant Summary collapse

DEFAULT_ERROR_MSG =
"An unknown error was returned from the provider".freeze

Instance Attribute Summary collapse

Attributes inherited from Connection

#connection

Instance Method Summary collapse

Methods included from Logging

#log_from_response

Methods inherited from Connection

#api

Constructor Details

#initialize(connection) ⇒ Api

Returns a new instance of Api.



10
11
12
# File 'lib/ansible_tower_client/api.rb', line 10

def initialize(connection)
  @instance = connection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/ansible_tower_client/api.rb', line 121

def method_missing(method_name, *args, &block)
  require 'faraday'
  if instance.respond_to?(method_name)
    path = build_path_to_resource(args.shift)
    args.unshift(path)
    logger.debug { "#{self.class.name} Sending <#{method_name}> with <#{args.inspect}>" }
    instance.send(method_name, *args, &block).tap do |response|
      logger.debug { "#{self.class.name} Response:\n#{log_from_response(response)}" }
    end
  else
    super
  end
rescue Faraday::ConnectionFailed => err
  raise AnsibleTowerClient::ConnectionError, err
rescue Faraday::SSLError => err
  raise AnsibleTowerClient::SSLError, err
rescue Faraday::ClientError => err
  raise AnsibleTowerClient::ConnectionError, err
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



9
10
11
# File 'lib/ansible_tower_client/api.rb', line 9

def instance
  @instance
end

Instance Method Details

#activity_streamObject



29
30
31
# File 'lib/ansible_tower_client/api.rb', line 29

def activity_stream
  Collection.new(self, activity_stream_class)
end

#activity_stream_classObject

Object class accessors patched for the appropriate version of the API



147
148
149
# File 'lib/ansible_tower_client/api.rb', line 147

def activity_stream_class
  @activity_stream_class ||= AnsibleTowerClient::ActivityStream
end

#ad_hoc_command_classObject



151
152
153
# File 'lib/ansible_tower_client/api.rb', line 151

def ad_hoc_command_class
  @ad_hoc_command_class ||= AnsibleTowerClient::AdHocCommand
end

#ad_hoc_commandsObject



33
34
35
# File 'lib/ansible_tower_client/api.rb', line 33

def ad_hoc_commands
  Collection.new(self, ad_hoc_command_class)
end

#configObject



14
15
16
# File 'lib/ansible_tower_client/api.rb', line 14

def config
  JSON.parse(get("config/").body)
end

#credential_classObject



155
156
157
# File 'lib/ansible_tower_client/api.rb', line 155

def credential_class
  @credential_class ||= AnsibleTowerClient::Credential
end

#credential_type_classObject



159
160
161
# File 'lib/ansible_tower_client/api.rb', line 159

def credential_type_class
  @credential_type_class ||= AnsibleTowerClient::CredentialType
end

#credential_typesObject



41
42
43
# File 'lib/ansible_tower_client/api.rb', line 41

def credential_types
  Collection.new(self, credential_type_class)
end

#credentialsObject



37
38
39
# File 'lib/ansible_tower_client/api.rb', line 37

def credentials
  Collection.new(self, credential_class)
end

#group_classObject



163
164
165
# File 'lib/ansible_tower_client/api.rb', line 163

def group_class
  @group_class ||= AnsibleTowerClient::Group
end

#groupsObject



45
46
47
# File 'lib/ansible_tower_client/api.rb', line 45

def groups
  Collection.new(self, group_class)
end

#host_classObject



167
168
169
# File 'lib/ansible_tower_client/api.rb', line 167

def host_class
  @host_class ||= AnsibleTowerClient::Host
end

#hostsObject



49
50
51
# File 'lib/ansible_tower_client/api.rb', line 49

def hosts
  Collection.new(self, host_class)
end

#inventoriesObject



53
54
55
# File 'lib/ansible_tower_client/api.rb', line 53

def inventories
  Collection.new(self, inventory_class)
end

#inventory_classObject



171
172
173
# File 'lib/ansible_tower_client/api.rb', line 171

def inventory_class
  @inventory_class ||= AnsibleTowerClient::Inventory
end

#inventory_source_classObject



175
176
177
# File 'lib/ansible_tower_client/api.rb', line 175

def inventory_source_class
  @inventory_source_class ||= AnsibleTowerClient::InventorySource
end

#inventory_sourcesObject



57
58
59
# File 'lib/ansible_tower_client/api.rb', line 57

def inventory_sources
  Collection.new(self, inventory_source_class)
end

#inventory_update_classObject



179
180
181
# File 'lib/ansible_tower_client/api.rb', line 179

def inventory_update_class
  @inventory_update_class ||= AnsibleTowerClient::InventoryUpdate
end

#inventory_updatesObject



61
62
63
# File 'lib/ansible_tower_client/api.rb', line 61

def inventory_updates
  Collection.new(self, inventory_update_class)
end

#job_classObject



183
184
185
# File 'lib/ansible_tower_client/api.rb', line 183

def job_class
  @job_class ||= AnsibleTowerClient::Job
end

#job_event_classObject



187
188
189
# File 'lib/ansible_tower_client/api.rb', line 187

def job_event_class
  @job_event_class ||= AnsibleTowerClient::JobEvent
end

#job_eventsObject



69
70
71
# File 'lib/ansible_tower_client/api.rb', line 69

def job_events
  Collection.new(self, job_event_class)
end

#job_play_classObject



191
192
193
# File 'lib/ansible_tower_client/api.rb', line 191

def job_play_class
  @job_play_class ||= AnsibleTowerClient::JobPlay
end

#job_playsObject



73
74
75
# File 'lib/ansible_tower_client/api.rb', line 73

def job_plays
  Collection.new(self, job_play_class)
end

#job_template_classObject



195
196
197
198
199
200
201
202
203
# File 'lib/ansible_tower_client/api.rb', line 195

def job_template_class
  @job_template_class ||= begin
    if Gem::Version.new(version).between?(Gem::Version.new(2), Gem::Version.new(3))
      AnsibleTowerClient::JobTemplateV2
    else
      AnsibleTowerClient::JobTemplate
    end
  end
end

#job_templatesObject



77
78
79
# File 'lib/ansible_tower_client/api.rb', line 77

def job_templates
  Collection.new(self, job_template_class)
end

#jobsObject



65
66
67
# File 'lib/ansible_tower_client/api.rb', line 65

def jobs
  Collection.new(self, job_class)
end

#organization_classObject



205
206
207
# File 'lib/ansible_tower_client/api.rb', line 205

def organization_class
  @organization_class ||= AnsibleTowerClient::Organization
end

#organizationsObject



81
82
83
# File 'lib/ansible_tower_client/api.rb', line 81

def organizations
  Collection.new(self, organization_class)
end

#project_classObject



209
210
211
# File 'lib/ansible_tower_client/api.rb', line 209

def project_class
  @project_class ||= AnsibleTowerClient::Project
end

#project_update_classObject



213
214
215
# File 'lib/ansible_tower_client/api.rb', line 213

def project_update_class
  @project_update_class ||= AnsibleTowerClient::ProjectUpdate
end

#project_updatesObject



89
90
91
# File 'lib/ansible_tower_client/api.rb', line 89

def project_updates
  Collection.new(self, project_update_class)
end

#projectsObject



85
86
87
# File 'lib/ansible_tower_client/api.rb', line 85

def projects
  Collection.new(self, project_class)
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/ansible_tower_client/api.rb', line 141

def respond_to_missing?(method, _include_private = false)
  instance.respond_to?(method)
end

#schedule_classObject



217
218
219
# File 'lib/ansible_tower_client/api.rb', line 217

def schedule_class
  @schedule_class ||= AnsibleTowerClient::Schedule
end

#schedulesObject



93
94
95
# File 'lib/ansible_tower_client/api.rb', line 93

def schedules
  Collection.new(self, schedule_class)
end

#system_job_classObject



221
222
223
# File 'lib/ansible_tower_client/api.rb', line 221

def system_job_class
  @system_job_class ||= AnsibleTowerClient::SystemJob
end

#system_job_template_classObject



225
226
227
# File 'lib/ansible_tower_client/api.rb', line 225

def system_job_template_class
  @system_job_template_class ||= AnsibleTowerClient::SystemJobTemplate
end

#system_job_templatesObject



101
102
103
# File 'lib/ansible_tower_client/api.rb', line 101

def system_job_templates
  Collection.new(self, system_job_template_class)
end

#system_jobsObject



97
98
99
# File 'lib/ansible_tower_client/api.rb', line 97

def system_jobs
  Collection.new(self, system_job_class)
end

#verify_credentialsObject



22
23
24
25
26
27
# File 'lib/ansible_tower_client/api.rb', line 22

def verify_credentials
  results = get("me/").body
  JSON.parse(results).fetch_path("results", 0, "username")
rescue JSON::ParserError
  raise AnsibleTowerClient::ConnectionError, "unexpected response"
end

#versionObject



18
19
20
# File 'lib/ansible_tower_client/api.rb', line 18

def version
  @version ||= config["version"]
end

#workflow_job_classObject



229
230
231
# File 'lib/ansible_tower_client/api.rb', line 229

def workflow_job_class
  @workflow_job_class ||= AnsibleTowerClient::WorkflowJob
end

#workflow_job_node_classObject



233
234
235
# File 'lib/ansible_tower_client/api.rb', line 233

def workflow_job_node_class
  @workflow_job_node_class ||= AnsibleTowerClient::WorkflowJobNode
end

#workflow_job_nodesObject



105
106
107
# File 'lib/ansible_tower_client/api.rb', line 105

def workflow_job_nodes
  Collection.new(self, workflow_job_node_class)
end

#workflow_job_template_classObject



237
238
239
# File 'lib/ansible_tower_client/api.rb', line 237

def workflow_job_template_class
  @workflow_job_template_class ||= AnsibleTowerClient::WorkflowJobTemplate
end

#workflow_job_template_node_classObject



241
242
243
# File 'lib/ansible_tower_client/api.rb', line 241

def workflow_job_template_node_class
  @workflow_job_template_node_class ||= AnsibleTowerClient::WorkflowJobTemplateNode
end

#workflow_job_template_nodesObject



117
118
119
# File 'lib/ansible_tower_client/api.rb', line 117

def workflow_job_template_nodes
  Collection.new(self, workflow_job_template_node_class)
end

#workflow_job_templatesObject



113
114
115
# File 'lib/ansible_tower_client/api.rb', line 113

def workflow_job_templates
  Collection.new(self, workflow_job_template_class)
end

#workflow_jobsObject



109
110
111
# File 'lib/ansible_tower_client/api.rb', line 109

def workflow_jobs
  Collection.new(self, workflow_job_class)
end