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, CloudFoldersInterface, CloudPoliciesInterface, CloudResourcePoolsInterface, CloudsInterface, ClustersInterface, ContainersInterface, CustomInstanceTypesInterface, CypherInterface, DashboardInterface, DeployInterface, DeploymentsInterface, EnvironmentsInterface, ExecuteSchedulesInterface, ExecutionRequestInterface, FileCopyRequestInterface, GroupPoliciesInterface, GroupsInterface, ImageBuilderBootScriptsInterface, ImageBuilderImageBuildsInterface, ImageBuilderInterface, ImageBuilderPreseedScriptsInterface, InstanceTypesInterface, InstancesInterface, KeyPairsInterface, LibraryComputeTypeLayoutsInterface, LibraryContainerScriptsInterface, LibraryContainerTemplatesInterface, LibraryContainerTypesInterface, LibraryContainerUpgradesInterface, LibraryInstanceTypesInterface, LibraryLayoutsInterface, LicenseInterface, LoadBalancersInterface, LogsInterface, MonitoringAppsInterface, MonitoringChecksInterface, MonitoringContactsInterface, MonitoringGroupsInterface, MonitoringIncidentsInterface, MonitoringInterface, NetworkDomainRecordsInterface, NetworkDomainsInterface, NetworkGroupsInterface, NetworkPoolIpsInterface, NetworkPoolServersInterface, NetworkPoolsInterface, NetworkProxiesInterface, NetworkServicesInterface, NetworkSubnetTypesInterface, NetworkSubnetsInterface, NetworkTypesInterface, NetworksInterface, OldCypherInterface, OptionTypeListsInterface, OptionTypesInterface, OptionsInterface, PackagesInterface, PoliciesInterface, PowerSchedulesInterface, ProcessesInterface, ProvisionTypesInterface, ReportsInterface, RolesInterface, SecurityGroupRulesInterface, SecurityGroupsInterface, ServerTypesInterface, ServersInterface, ServicePlansInterface, SetupInterface, StorageProvidersInterface, SubnetsInterface, TaskSetsInterface, TasksInterface, UserGroupsInterface, UserSettingsInterface, UserSourcesInterface, UsersInterface, VirtualImagesInterface, WhoamiInterface, WikiInterface
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_folders ⇒ Object
-
#cloud_policies ⇒ Object
-
#cloud_resource_pools ⇒ Object
-
#clouds ⇒ Object
-
#clusters ⇒ 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
-
#environments ⇒ 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
Initialize a new APIClient client = APIClient.new(url:"https://morpheus.yourcompany.com", verify_ssl:false) This old method signature is being deprecated: client = APIClient.new(access_token, refresh_token, expires_in, base_url, verify_ssl, options={}).
-
#inspect ⇒ Object
-
#instance_types ⇒ Object
-
#instances ⇒ Object
-
#key_pairs ⇒ Object
-
#library_compute_type_layouts ⇒ 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
-
#logged_in? ⇒ Boolean
-
#login(username, password) ⇒ Object
-
#logout ⇒ Object
-
#logs ⇒ Object
-
#monitoring ⇒ Object
-
#network_domain_records ⇒ Object
-
#network_domains ⇒ Object
-
#network_groups ⇒ Object
-
#network_pool_ips ⇒ Object
-
#network_pool_servers ⇒ Object
-
#network_pools ⇒ Object
-
#network_proxies ⇒ Object
-
#network_services ⇒ Object
-
#network_subnet_types ⇒ Object
-
#network_subnets ⇒ Object
-
#network_types ⇒ 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
-
#refresh_token ⇒ Object
-
#reports ⇒ Object
-
#roles ⇒ Object
-
#security_group_rules ⇒ Object
-
#security_groups ⇒ Object
-
#server_types ⇒ Object
-
#servers ⇒ Object
-
#service_plans ⇒ 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
-
#to_s ⇒ Object
-
#url ⇒ Object
-
#user_groups ⇒ Object
-
#user_settings ⇒ Object
-
#user_sources ⇒ Object
-
#users ⇒ Object
-
#virtual_images ⇒ Object
-
#whoami ⇒ Object
-
#wiki ⇒ 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
Initialize a new APIClient
client = APIClient.new(url:"https://morpheus.yourcompany.com", verify_ssl:false)
This old method signature is being deprecated:
client = APIClient.new(access_token, refresh_token, expires_in, base_url, verify_ssl, options={})
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/morpheus/api/api_client.rb', line 11
def initialize(access_token, refresh_token=nil,expires_in = nil, base_url=nil, verify_ssl=true, options={})
if access_token.is_a?(Hash)
client_opts = access_token.clone()
access_token = client_opts[:access_token]
refresh_token = client_opts[:refresh_token]
base_url = client_opts[:url] || client_opts[:base_url]
expires_in = client_opts[:expires_in]
verify_ssl = client_opts.key?(:verify_ssl) ? client_opts[:verify_ssl] : true
options = refresh_token.is_a?(Hash) ? refresh_token.clone() : {}
end
@access_token = access_token
@refresh_token = refresh_token
@base_url = base_url
if @base_url.to_s.empty?
raise "#{self.class} requires option :url"
end
@base_url = @base_url.chomp("/")
if expires_in != nil
@expires_at = Time.now + expires_in
end
set_ssl_verification_enabled(verify_ssl)
setopts(options)
end
|
Instance Method Details
#accounts ⇒ Object
368
369
370
|
# File 'lib/morpheus/api/api_client.rb', line 368
def accounts
Morpheus::AccountsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#apps ⇒ Object
340
341
342
|
# File 'lib/morpheus/api/api_client.rb', line 340
def apps
Morpheus::AppsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#archive_buckets ⇒ Object
#blueprints ⇒ Object
344
345
346
|
# File 'lib/morpheus/api/api_client.rb', line 344
def blueprints
Morpheus::BlueprintsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#cloud_datastores ⇒ Object
#cloud_resource_pools ⇒ Object
#clouds ⇒ Object
280
281
282
|
# File 'lib/morpheus/api/api_client.rb', line 280
def clouds
Morpheus::CloudsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#clusters ⇒ Object
364
365
366
|
# File 'lib/morpheus/api/api_client.rb', line 364
def clusters
Morpheus::ClustersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#containers ⇒ Object
304
305
306
|
# File 'lib/morpheus/api/api_client.rb', line 304
def containers
Morpheus::ContainersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#custom_instance_types ⇒ Object
#cypher ⇒ Object
551
552
553
|
# File 'lib/morpheus/api/api_client.rb', line 551
def cypher
Morpheus::CypherInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#dashboard ⇒ Object
412
413
414
|
# File 'lib/morpheus/api/api_client.rb', line 412
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'
66
67
68
|
# File 'lib/morpheus/api/api_client.rb', line 66
def default_content_type
nil
end
|
#deploy ⇒ Object
348
349
350
|
# File 'lib/morpheus/api/api_client.rb', line 348
def deploy
Morpheus::DeployInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#dry ⇒ Object
53
54
55
|
# File 'lib/morpheus/api/api_client.rb', line 53
def dry()
dry_run(true)
end
|
#dry_run(val = true) ⇒ Object
48
49
50
51
|
# File 'lib/morpheus/api/api_client.rb', line 48
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. => '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 => 'application/json'.
:timeout - A custom timeout in seconds for api requests. The default is 30. todo: separate timeout options
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/morpheus/api/api_client.rb', line 123
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
272
273
274
|
# File 'lib/morpheus/api/api_client.rb', line 272
def groups
Morpheus::GroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#inspect ⇒ Object
44
45
46
|
# File 'lib/morpheus/api/api_client.rb', line 44
def inspect
to_s
end
|
#instances ⇒ Object
300
301
302
|
# File 'lib/morpheus/api/api_client.rb', line 300
def instances
Morpheus::InstancesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#key_pairs ⇒ Object
392
393
394
|
# File 'lib/morpheus/api/api_client.rb', line 392
def key_pairs
Morpheus::KeyPairsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#library_compute_type_layouts ⇒ 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
396
397
398
|
# File 'lib/morpheus/api/api_client.rb', line 396
def license
Morpheus::LicenseInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#logged_in? ⇒ Boolean
218
219
220
|
# File 'lib/morpheus/api/api_client.rb', line 218
def logged_in?
!!@access_token
end
|
#login(username, password) ⇒ Object
222
223
224
225
226
227
228
229
230
231
232
|
# File 'lib/morpheus/api/api_client.rb', line 222
def login(username, password)
@access_token, @refresh_token, @expires_at = nil, nil, nil
response = auth.login(username, password)
@access_token = response['access_token']
@refresh_token = response['refresh_token']
if response['expires_in'] != nil
@expires_at = Time.now + response['expires_in']
end
return self
end
|
#logout ⇒ Object
249
250
251
252
253
254
|
# File 'lib/morpheus/api/api_client.rb', line 249
def logout
@access_token = nil
@refresh_token = nil
@expires_at = nil
return self
end
|
#logs ⇒ Object
384
385
386
|
# File 'lib/morpheus/api/api_client.rb', line 384
def logs
Morpheus::LogsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#monitoring ⇒ Object
428
429
430
|
# File 'lib/morpheus/api/api_client.rb', line 428
def monitoring
Morpheus::MonitoringInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#network_domain_records ⇒ Object
#network_domains ⇒ Object
#network_pool_ips ⇒ Object
#network_pool_servers ⇒ Object
#network_proxies ⇒ Object
#network_services ⇒ Object
#network_subnet_types ⇒ Object
#network_subnets ⇒ Object
#networks ⇒ Object
454
455
456
|
# File 'lib/morpheus/api/api_client.rb', line 454
def networks
Morpheus::NetworksInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#old_cypher ⇒ Object
555
556
557
|
# File 'lib/morpheus/api/api_client.rb', line 555
def old_cypher
Morpheus::OldCypherInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#option_type_lists ⇒ Object
#option_types ⇒ Object
404
405
406
|
# File 'lib/morpheus/api/api_client.rb', line 404
def option_types
Morpheus::OptionTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#options ⇒ Object
268
269
270
|
# File 'lib/morpheus/api/api_client.rb', line 268
def options
Morpheus::OptionsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#packages ⇒ Object
547
548
549
|
# File 'lib/morpheus/api/api_client.rb', line 547
def packages
Morpheus::PackagesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#policies ⇒ Object
def incidents
Morpheus::MonitoringIncidentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
monitoring.incidents
end
442
443
444
|
# File 'lib/morpheus/api/api_client.rb', line 442
def policies
Morpheus::PoliciesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#power_schedules ⇒ Object
#processes ⇒ Object
567
568
569
|
# File 'lib/morpheus/api/api_client.rb', line 567
def processes
Morpheus::ProcessesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#provision_types ⇒ Object
#refresh_token ⇒ Object
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/morpheus/api/api_client.rb', line 234
def refresh_token()
if @refresh_token.nil?
raise "#{self.class} does not currently have a refresh_token"
end
response = auth.use_refresh_token(@refresh_token)
@access_token = response['access_token']
@refresh_token = response['refresh_token']
if response['expires_in'] != nil
@expires_at = Time.now + response['expires_in']
end
@access_token = response['access_token']
return self
end
|
#reports ⇒ Object
571
572
573
|
# File 'lib/morpheus/api/api_client.rb', line 571
def reports
Morpheus::ReportsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#roles ⇒ Object
388
389
390
|
# File 'lib/morpheus/api/api_client.rb', line 388
def roles
Morpheus::RolesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#security_group_rules ⇒ Object
#security_groups ⇒ Object
#server_types ⇒ Object
312
313
314
|
# File 'lib/morpheus/api/api_client.rb', line 312
def server_types
Morpheus::ServerTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#servers ⇒ Object
296
297
298
|
# File 'lib/morpheus/api/api_client.rb', line 296
def servers
Morpheus::ServersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#set_ssl_verification_enabled(val) ⇒ Object
61
62
63
|
# File 'lib/morpheus/api/api_client.rb', line 61
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({})
86
87
88
89
90
91
92
|
# File 'lib/morpheus/api/api_client.rb', line 86
def setopts(new_options)
@options = new_options
if @options[:dry_run]
dry_run(true)
end
self
end
|
#ssl_verification_enabled? ⇒ Boolean
57
58
59
|
# File 'lib/morpheus/api/api_client.rb', line 57
def ssl_verification_enabled?
@verify_ssl
end
|
#storage_providers ⇒ Object
#task_sets ⇒ Object
332
333
334
|
# File 'lib/morpheus/api/api_client.rb', line 332
def task_sets
Morpheus::TaskSetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#tasks ⇒ Object
328
329
330
|
# File 'lib/morpheus/api/api_client.rb', line 328
def tasks
Morpheus::TasksInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#to_s ⇒ Object
40
41
42
|
# File 'lib/morpheus/api/api_client.rb', line 40
def to_s
"<##{self.class}:#{self.object_id.to_s(8)} @url=#{@base_url} @verify_ssl=#{@verify_ssl} @access_token=#{@access_token ? '************' : nil} @refresh_token=#{@access_token ? '************' : nil} @expires_at=#{@expires_at} @options=#{@options}>"
end
|
#url ⇒ Object
36
37
38
|
# File 'lib/morpheus/api/api_client.rb', line 36
def url
@base_url
end
|
#user_groups ⇒ Object
376
377
378
|
# File 'lib/morpheus/api/api_client.rb', line 376
def user_groups
Morpheus::UserGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#user_sources ⇒ Object
380
381
382
|
# File 'lib/morpheus/api/api_client.rb', line 380
def user_sources
Morpheus::UserSourcesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#users ⇒ Object
372
373
374
|
# File 'lib/morpheus/api/api_client.rb', line 372
def users
Morpheus::UsersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#whoami ⇒ Object
260
261
262
|
# File 'lib/morpheus/api/api_client.rb', line 260
def whoami
Morpheus::WhoamiInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end
|
#wiki ⇒ Object
579
580
581
|
# File 'lib/morpheus/api/api_client.rb', line 579
def wiki
Morpheus::WikiInterface.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
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/morpheus/api/api_client.rb', line 98
def withopts(tmp_options, &block)
@_old_options = @options
begin
@options = tmp_options
result = block.call()
ensure
@options = @_old_options
end
return result
end
|