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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ansible_tower_client/api.rb', line 114

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



26
27
28
# File 'lib/ansible_tower_client/api.rb', line 26

def activity_stream
  Collection.new(self, activity_stream_class)
end

#activity_stream_classObject

Object class accessors patched for the appropriate version of the API



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

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

#ad_hoc_command_classObject



144
145
146
# File 'lib/ansible_tower_client/api.rb', line 144

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

#ad_hoc_commandsObject



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

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



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

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

#credentialsObject



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

def credentials
  Collection.new(self, credential_class)
end

#group_classObject



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

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

#groupsObject



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

def groups
  Collection.new(self, group_class)
end

#host_classObject



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

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

#hostsObject



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

def hosts
  Collection.new(self, host_class)
end

#inventoriesObject



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

def inventories
  Collection.new(self, inventory_class)
end

#inventory_classObject



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

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

#inventory_source_classObject



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

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

#inventory_sourcesObject



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

def inventory_sources
  Collection.new(self, inventory_source_class)
end

#inventory_update_classObject



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

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

#inventory_updatesObject



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

def inventory_updates
  Collection.new(self, inventory_update_class)
end

#job_classObject



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

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

#job_event_classObject



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

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

#job_eventsObject



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

def job_events
  Collection.new(self, job_event_class)
end

#job_play_classObject



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

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

#job_playsObject



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

def job_plays
  Collection.new(self, job_play_class)
end

#job_template_classObject



184
185
186
187
188
189
190
191
192
# File 'lib/ansible_tower_client/api.rb', line 184

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



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

def job_templates
  Collection.new(self, job_template_class)
end

#jobsObject



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

def jobs
  Collection.new(self, job_class)
end

#organization_classObject



194
195
196
# File 'lib/ansible_tower_client/api.rb', line 194

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

#organizationsObject



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

def organizations
  Collection.new(self, organization_class)
end

#project_classObject



198
199
200
# File 'lib/ansible_tower_client/api.rb', line 198

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

#project_update_classObject



202
203
204
# File 'lib/ansible_tower_client/api.rb', line 202

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

#project_updatesObject



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

def project_updates
  Collection.new(self, project_update_class)
end

#projectsObject



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

def projects
  Collection.new(self, project_class)
end

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

Returns:

  • (Boolean)


134
135
136
# File 'lib/ansible_tower_client/api.rb', line 134

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

#schedule_classObject



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

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

#schedulesObject



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

def schedules
  Collection.new(self, schedule_class)
end

#system_job_classObject



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

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

#system_job_template_classObject



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

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

#system_job_templatesObject



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

def system_job_templates
  Collection.new(self, system_job_template_class)
end

#system_jobsObject



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

def system_jobs
  Collection.new(self, system_job_class)
end

#verify_credentialsObject



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

def verify_credentials
  JSON.parse(get("me/").body).fetch_path("results", 0, "username")
end

#versionObject



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

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

#workflow_job_classObject



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

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

#workflow_job_node_classObject



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

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

#workflow_job_nodesObject



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

def workflow_job_nodes
  Collection.new(self, workflow_job_node_class)
end

#workflow_job_template_classObject



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

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

#workflow_job_template_node_classObject



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

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

#workflow_job_template_nodesObject



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

def workflow_job_template_nodes
  Collection.new(self, workflow_job_template_node_class)
end

#workflow_job_templatesObject



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

def workflow_job_templates
  Collection.new(self, workflow_job_template_class)
end

#workflow_jobsObject



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

def workflow_jobs
  Collection.new(self, workflow_job_class)
end