Class: Morpheus::APIClient
- Inherits:
-
Object
- Object
- Morpheus::APIClient
show all
- Defined in:
- lib/morpheus/api/api_client.rb
Direct Known Subclasses
AccountGroupsInterface, AccountsInterface, AppsInterface, ArchiveBucketsInterface, ArchiveFilesInterface, AuthInterface, BlueprintsInterface, CloudDatastoresInterface, CloudPoliciesInterface, CloudsInterface, ContainersInterface, CustomInstanceTypesInterface, CypherInterface, DashboardInterface, DeployInterface, DeploymentsInterface, ExecuteSchedulesInterface, ExecutionRequestInterface, FileCopyRequestInterface, GroupPoliciesInterface, GroupsInterface, ImageBuilderBootScriptsInterface, ImageBuilderImageBuildsInterface, ImageBuilderInterface, ImageBuilderPreseedScriptsInterface, InstanceTypesInterface, InstancesInterface, KeyPairsInterface, LibraryContainerScriptsInterface, LibraryContainerTemplatesInterface, LibraryContainerTypesInterface, LibraryContainerUpgradesInterface, LibraryInstanceTypesInterface, LibraryLayoutsInterface, LicenseInterface, LoadBalancersInterface, LogsInterface, MonitoringAppsInterface, MonitoringChecksInterface, MonitoringContactsInterface, MonitoringGroupsInterface, MonitoringIncidentsInterface, MonitoringInterface, NetworkDomainsInterface, NetworkGroupsInterface, NetworkPoolServersInterface, NetworkPoolsInterface, NetworkProxiesInterface, NetworkServicesInterface, NetworksInterface, OldCypherInterface, OptionTypeListsInterface, OptionTypesInterface, OptionsInterface, PackagesInterface, PoliciesInterface, PowerSchedulesInterface, ProcessesInterface, ProvisionTypesInterface, RolesInterface, SecurityGroupRulesInterface, SecurityGroupsInterface, ServersInterface, SetupInterface, StorageProvidersInterface, TaskSetsInterface, TasksInterface, UserGroupsInterface, UserSettingsInterface, UserSourcesInterface, UsersInterface, VirtualImagesInterface, WhoamiInterface
Instance Method Summary
collapse
-
#account_groups ⇒ Object
-
#accounts ⇒ Object
-
#apps ⇒ Object
-
#archive_buckets ⇒ Object
-
#archive_files ⇒ Object
-
#auth ⇒ Object
-
#blueprints ⇒ Object
-
#cloud_datastores ⇒ Object
-
#cloud_policies ⇒ Object
-
#clouds ⇒ Object
-
#containers ⇒ Object
-
#custom_instance_types ⇒ Object
-
#cypher ⇒ Object
-
#dashboard ⇒ Object
-
#default_content_type ⇒ Object
set this in your interface, eg.
-
#deploy ⇒ Object
-
#deployments ⇒ Object
-
#dry ⇒ Object
-
#dry_run(val = true) ⇒ Object
-
#execute(opts, options = {}) ⇒ Object
Execute an HTTP request with this client.
-
#execute_schedules ⇒ Object
-
#execution_request ⇒ Object
-
#file_copy_request ⇒ Object
-
#group_policies ⇒ Object
-
#groups ⇒ Object
-
#image_builder ⇒ Object
-
#initialize(access_token, refresh_token = nil, expires_in = nil, base_url = nil, verify_ssl = true, options = {}) ⇒ APIClient
constructor
A new instance of APIClient.
-
#instance_types ⇒ Object
-
#instances ⇒ Object
-
#key_pairs ⇒ Object
-
#library_container_scripts ⇒ Object
-
#library_container_templates ⇒ Object
-
#library_container_types ⇒ Object
-
#library_container_upgrades ⇒ Object
-
#library_instance_types ⇒ Object
-
#library_layouts ⇒ Object
-
#license ⇒ Object
-
#load_balancers ⇒ Object
-
#logs ⇒ Object
-
#monitoring ⇒ Object
-
#network_domains ⇒ Object
-
#network_groups ⇒ Object
-
#network_pool_servers ⇒ Object
-
#network_pools ⇒ Object
-
#network_proxies ⇒ Object
-
#network_services ⇒ Object
-
#networks ⇒ Object
-
#old_cypher ⇒ Object
-
#option_type_lists ⇒ Object
-
#option_types ⇒ Object
-
#options ⇒ Object
-
#packages ⇒ Object
-
#policies ⇒ Object
def incidents # Morpheus::MonitoringIncidentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options) monitoring.incidents end.
-
#power_schedules ⇒ Object
-
#processes ⇒ Object
-
#provision_types ⇒ Object
-
#roles ⇒ Object
-
#security_group_rules ⇒ Object
-
#security_groups ⇒ Object
-
#servers ⇒ Object
-
#set_ssl_verification_enabled(val) ⇒ Object
-
#setopts(new_options) ⇒ Object
(also: #set_options)
set common global @options for use with all requests meant for inline use just like dry(), set_options(dry_run:true) can be used in place of dry() Example: Prints curl -XGET …/whoami -H “Bearer” instead of actually request APIClient.new(token).whoami.setopts(curl:true).get({}).
-
#setup ⇒ Object
-
#ssl_verification_enabled? ⇒ Boolean
-
#storage_providers ⇒ Object
-
#task_sets ⇒ Object
-
#tasks ⇒ Object
-
#user_groups ⇒ Object
-
#user_settings ⇒ Object
-
#user_sources ⇒ Object
-
#users ⇒ Object
-
#virtual_images ⇒ Object
-
#whoami ⇒ Object
-
#withopts(tmp_options, &block) ⇒ Object
(also: #with_options)
with_options sets common global @options for the duration of the block only then returns the options to their prior values.
Constructor Details
#initialize(access_token, refresh_token = nil, expires_in = nil, base_url = nil, verify_ssl = true, options = {}) ⇒ APIClient
Returns a new instance of APIClient.
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/morpheus/api/api_client.rb', line 6
def initialize(access_token, refresh_token=nil,expires_in = nil, base_url=nil, verify_ssl=true, options={})
@access_token = access_token
@refresh_token = refresh_token
@base_url = base_url
if expires_in != nil
@expires_at = DateTime.now + expires_in.seconds
end
set_ssl_verification_enabled(verify_ssl)
setopts(options)
end
|
Instance Method Details
#accounts ⇒ Object
279
280
281
|
# File 'lib/morpheus/api/api_client.rb', line 279
def accounts
Morpheus::AccountsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#apps ⇒ Object
255
256
257
|
# File 'lib/morpheus/api/api_client.rb', line 255
def apps
Morpheus::AppsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#archive_buckets ⇒ Object
#blueprints ⇒ Object
259
260
261
|
# File 'lib/morpheus/api/api_client.rb', line 259
def blueprints
Morpheus::BlueprintsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#cloud_datastores ⇒ Object
#clouds ⇒ Object
211
212
213
|
# File 'lib/morpheus/api/api_client.rb', line 211
def clouds
Morpheus::CloudsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#containers ⇒ Object
227
228
229
|
# File 'lib/morpheus/api/api_client.rb', line 227
def containers
Morpheus::ContainersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#custom_instance_types ⇒ Object
#cypher ⇒ Object
437
438
439
|
# File 'lib/morpheus/api/api_client.rb', line 437
def cypher
Morpheus::CypherInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#dashboard ⇒ Object
323
324
325
|
# File 'lib/morpheus/api/api_client.rb', line 323
def dashboard
Morpheus::DashboardInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#default_content_type ⇒ Object
set this in your interface, eg. to ‘application/json’
35
36
37
|
# File 'lib/morpheus/api/api_client.rb', line 35
def default_content_type
nil
end
|
#deploy ⇒ Object
263
264
265
|
# File 'lib/morpheus/api/api_client.rb', line 263
def deploy
Morpheus::DeployInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#dry ⇒ Object
22
23
24
|
# File 'lib/morpheus/api/api_client.rb', line 22
def dry()
dry_run(true)
end
|
#dry_run(val = true) ⇒ Object
17
18
19
20
|
# File 'lib/morpheus/api/api_client.rb', line 17
def dry_run(val=true)
@dry_run = !!val
self
end
|
#execute(opts, options = {}) ⇒ Object
Execute an HTTP request with this client. opts - Hash of options for HTTP Request.
:url - The full url
:method - The default method is :get (GET)
:headers - Hash of headers to include in the request.
eg. {'Content-Type' => 'application/json'}. :params is a special key for query parameters.
:params - query parameters
:payload - The body of the request.
:timeout - A custom timeout in seconds for api requests. The default is 30. todo: separate timeout options
options - Hash of common global options that commands parse. eg. :headers, :timeout, :dry_run, :curl, etc
:headers - Extra headers to add. This expects a Hash like {'Content-Type' => 'application/json'}.
:timeout - A custom timeout in seconds for api requests. The default is 30. todo: separate timeout options
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/morpheus/api/api_client.rb', line 92
def execute(opts, options={})
if @options
options = options.merge(@options)
else
options = options.clone
end
if opts[:method].nil?
else
opts[:method] = opts[:method].to_s.downcase.to_sym
end
opts[:headers] ||= {}
if @access_token
if opts[:headers][:authorization].nil? && opts[:headers]['Authorization'].nil?
opts[:headers][:authorization] = "Bearer #{@access_token}"
else
end
end
if opts[:headers]['Content-Type'].nil? && default_content_type
opts[:headers]['Content-Type'] = default_content_type
end
if options[:timeout]
opts[:timeout] = options[:timeout].to_f
end
if options[:headers]
opts[:headers] = opts[:headers].merge(options[:headers])
end
if opts[:params] && (opts[:headers][:params].nil? || opts[:headers][:params].empty?)
opts[:headers][:params] = opts[:params] end
if @verify_ssl == false
opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
end
if @dry_run
opts[:command_options] = options return opts
end
response = Morpheus::RestClient.execute(opts)
if opts[:parse_json] != false && options[:parse_json] != false
return JSON.parse(response.to_s)
else
return response
end
end
|
#execute_schedules ⇒ Object
#execution_request ⇒ Object
#file_copy_request ⇒ Object
#groups ⇒ Object
203
204
205
|
# File 'lib/morpheus/api/api_client.rb', line 203
def groups
Morpheus::GroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#instances ⇒ Object
223
224
225
|
# File 'lib/morpheus/api/api_client.rb', line 223
def instances
Morpheus::InstancesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#key_pairs ⇒ Object
303
304
305
|
# File 'lib/morpheus/api/api_client.rb', line 303
def key_pairs
Morpheus::KeyPairsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#library_container_scripts ⇒ Object
#library_container_templates ⇒ Object
#library_container_types ⇒ Object
#library_container_upgrades ⇒ Object
#library_instance_types ⇒ Object
#library_layouts ⇒ Object
#license ⇒ Object
307
308
309
|
# File 'lib/morpheus/api/api_client.rb', line 307
def license
Morpheus::LicenseInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#logs ⇒ Object
295
296
297
|
# File 'lib/morpheus/api/api_client.rb', line 295
def logs
Morpheus::LogsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#monitoring ⇒ Object
339
340
341
|
# File 'lib/morpheus/api/api_client.rb', line 339
def monitoring
Morpheus::MonitoringInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#network_domains ⇒ Object
#network_pool_servers ⇒ Object
#network_proxies ⇒ Object
#network_services ⇒ Object
#networks ⇒ Object
365
366
367
|
# File 'lib/morpheus/api/api_client.rb', line 365
def networks
Morpheus::NetworksInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#old_cypher ⇒ Object
441
442
443
|
# File 'lib/morpheus/api/api_client.rb', line 441
def old_cypher
Morpheus::OldCypherInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#option_type_lists ⇒ Object
#option_types ⇒ Object
315
316
317
|
# File 'lib/morpheus/api/api_client.rb', line 315
def option_types
Morpheus::OptionTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#options ⇒ Object
199
200
201
|
# File 'lib/morpheus/api/api_client.rb', line 199
def options
Morpheus::OptionsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#packages ⇒ Object
433
434
435
|
# File 'lib/morpheus/api/api_client.rb', line 433
def packages
Morpheus::PackagesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#policies ⇒ Object
def incidents
monitoring.incidents
end
353
354
355
|
# File 'lib/morpheus/api/api_client.rb', line 353
def policies
Morpheus::PoliciesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#power_schedules ⇒ Object
#processes ⇒ Object
453
454
455
|
# File 'lib/morpheus/api/api_client.rb', line 453
def processes
Morpheus::ProcessesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#provision_types ⇒ Object
#roles ⇒ Object
299
300
301
|
# File 'lib/morpheus/api/api_client.rb', line 299
def roles
Morpheus::RolesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#security_group_rules ⇒ Object
#security_groups ⇒ Object
#servers ⇒ Object
219
220
221
|
# File 'lib/morpheus/api/api_client.rb', line 219
def servers
Morpheus::ServersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#set_ssl_verification_enabled(val) ⇒ Object
30
31
32
|
# File 'lib/morpheus/api/api_client.rb', line 30
def set_ssl_verification_enabled(val)
@verify_ssl = !!val
end
|
#setopts(new_options) ⇒ Object
Also known as:
set_options
set common global @options for use with all requests meant for inline use just like dry(), set_options(dry_run:true) can be used in place of dry() Example: Prints curl -XGET …/whoami -H “Bearer” instead of actually request APIClient.new(token).whoami.setopts(curl:true).get({})
55
56
57
58
59
60
61
|
# File 'lib/morpheus/api/api_client.rb', line 55
def setopts(new_options)
@options = new_options
if @options[:dry_run]
dry_run(true)
end
self
end
|
#ssl_verification_enabled? ⇒ Boolean
26
27
28
|
# File 'lib/morpheus/api/api_client.rb', line 26
def ssl_verification_enabled?
@verify_ssl
end
|
#storage_providers ⇒ Object
#task_sets ⇒ Object
247
248
249
|
# File 'lib/morpheus/api/api_client.rb', line 247
def task_sets
Morpheus::TaskSetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#tasks ⇒ Object
243
244
245
|
# File 'lib/morpheus/api/api_client.rb', line 243
def tasks
Morpheus::TasksInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#user_groups ⇒ Object
287
288
289
|
# File 'lib/morpheus/api/api_client.rb', line 287
def user_groups
Morpheus::UserGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#user_sources ⇒ Object
291
292
293
|
# File 'lib/morpheus/api/api_client.rb', line 291
def user_sources
Morpheus::UserSourcesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#users ⇒ Object
283
284
285
|
# File 'lib/morpheus/api/api_client.rb', line 283
def users
Morpheus::UsersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#whoami ⇒ Object
191
192
193
|
# File 'lib/morpheus/api/api_client.rb', line 191
def whoami
Morpheus::WhoamiInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#withopts(tmp_options, &block) ⇒ Object
Also known as:
with_options
with_options sets common global @options for the duration of the block only then returns the options to their prior values
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/morpheus/api/api_client.rb', line 67
def withopts(tmp_options, &block)
@_old_options = @options
begin
@options = tmp_options
result = block.call()
ensure
@options = @_old_options
end
return result
end
|