Class: Morpheus::APIClient

Inherits:
Object
  • Object
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

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("/")
  # todo: validate URI
  if expires_in != nil
    @expires_at = Time.now + expires_in
  end
  set_ssl_verification_enabled(verify_ssl)
  setopts(options)
end

Instance Method Details

#account_groupsObject



276
277
278
# File 'lib/morpheus/api/api_client.rb', line 276

def 
  Morpheus::AccountGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#accountsObject



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

#appsObject



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_bucketsObject



502
503
504
# File 'lib/morpheus/api/api_client.rb', line 502

def archive_buckets
  Morpheus::ArchiveBucketsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#archive_filesObject



506
507
508
# File 'lib/morpheus/api/api_client.rb', line 506

def archive_files
  Morpheus::ArchiveFilesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#authObject



256
257
258
# File 'lib/morpheus/api/api_client.rb', line 256

def auth
  Morpheus::AuthInterface.new(@base_url, @access_token).setopts(@options)
end

#blueprintsObject



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_datastoresObject



284
285
286
# File 'lib/morpheus/api/api_client.rb', line 284

def cloud_datastores
  Morpheus::CloudDatastoresInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#cloud_foldersObject



292
293
294
# File 'lib/morpheus/api/api_client.rb', line 292

def cloud_folders
  Morpheus::CloudFoldersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#cloud_policiesObject



450
451
452
# File 'lib/morpheus/api/api_client.rb', line 450

def cloud_policies
  Morpheus::CloudPoliciesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#cloud_resource_poolsObject



288
289
290
# File 'lib/morpheus/api/api_client.rb', line 288

def cloud_resource_pools
  Morpheus::CloudResourcePoolsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#cloudsObject



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

#clustersObject



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

#containersObject



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_typesObject



400
401
402
# File 'lib/morpheus/api/api_client.rb', line 400

def custom_instance_types
  Morpheus::CustomInstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#cypherObject



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

#dashboardObject



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_typeObject

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

#deployObject



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

#deploymentsObject



352
353
354
# File 'lib/morpheus/api/api_client.rb', line 352

def deployments
  Morpheus::DeploymentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#dryObject



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

#environmentsObject



575
576
577
# File 'lib/morpheus/api/api_client.rb', line 575

def environments
  Morpheus::EnvironmentsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
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={})
  # merge in common global @options
  if @options
    options = options.merge(@options)
  else
    options = options.clone
  end

  # default HTTP method
  if opts[:method].nil?
    # why not a default? you will get an error from RestClient
    # opts[:method] = :get
  else
    # convert to lowercase Symbol like :get, :post, :put, or :delete
    opts[:method] = opts[:method].to_s.downcase.to_sym
  end

  # apply default headers
  opts[:headers] ||= {}
  # Authorization: apply our access token
  if @access_token
    if opts[:headers][:authorization].nil? && opts[:headers]['Authorization'].nil?
      opts[:headers][:authorization] = "Bearer #{@access_token}"
    else
      # authorization header has already been set.
    end
  end

  # Content-Type: apply interface default
  if opts[:headers]['Content-Type'].nil? && default_content_type
    opts[:headers]['Content-Type'] = default_content_type
  end

  # use custom timeout eg. from --timeout option
  if options[:timeout]
    opts[:timeout] = options[:timeout].to_f
  end

  # add extra headers, eg. from --header option
  # headers should be a Hash and not an Array, dont make me split you here!
  if options[:headers]
    opts[:headers] = opts[:headers].merge(options[:headers])
  end

  # this is confusing, but RestClient expects :params inside the headers...?
  # right?
  # move/copy params to headers.params for simplification.
  # remove this if issues arise
  if opts[:params] && (opts[:headers][:params].nil? || opts[:headers][:params].empty?)
    opts[:headers][:params] = opts[:params] # .delete(:params) maybe?
  end

  # :command_options for these
  # if options[:curl]
  #   opts[:curl] = options[:curl]
  # end
  # if options.key?(:pretty_json)
  #   opts[:pretty_json] = options[:pretty_json]
  # end
  # if options.key?(:scrub)
  #   opts[:scrub] = options[:scrub]
  # end

  # @verify_ssl is not used atm
  # todo: finish this and use it instead of the global variable RestClient.ssl_verification_enabled?
  # gotta clean up all APIClient subclasses new() methods to support this
  # the CliCommand subclasses should be changed to @users_interface = @api_client.users
  # also.. Credentials.new()
  if @verify_ssl == false
    opts[:verify_ssl] = OpenSSL::SSL::VERIFY_NONE
  end

  if @dry_run
    # JD: could return a Request object instead...
    # print_dry_run needs options somehow...
    opts[:command_options] = options # trash this..we got @options with setopts now
    return opts
  end

  # uhh can't use LIST at the moment
  # fix it!
  # if opts[:method] == :list
  #   opts[:method]
  # end

  # Morpheus::Logging::DarkPrinter.puts "Morpheus::RestClient.execute(#{opts})" if Morpheus::Logging.debug?
  # instead, using ::RestClient.log = STDOUT 
  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_schedulesObject



420
421
422
# File 'lib/morpheus/api/api_client.rb', line 420

def execute_schedules
  Morpheus::ExecuteSchedulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#execution_requestObject



559
560
561
# File 'lib/morpheus/api/api_client.rb', line 559

def execution_request
  Morpheus::ExecutionRequestInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#file_copy_requestObject



563
564
565
# File 'lib/morpheus/api/api_client.rb', line 563

def file_copy_request
  Morpheus::FileCopyRequestInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#group_policiesObject



446
447
448
# File 'lib/morpheus/api/api_client.rb', line 446

def group_policies
  Morpheus::GroupPoliciesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#groupsObject



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

#image_builderObject



510
511
512
# File 'lib/morpheus/api/api_client.rb', line 510

def image_builder
  Morpheus::ImageBuilderInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#inspectObject



44
45
46
# File 'lib/morpheus/api/api_client.rb', line 44

def inspect
  to_s
end

#instance_typesObject



308
309
310
# File 'lib/morpheus/api/api_client.rb', line 308

def instance_types
  Morpheus::InstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#instancesObject



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_pairsObject



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_layoutsObject



543
544
545
# File 'lib/morpheus/api/api_client.rb', line 543

def library_compute_type_layouts
  Morpheus::LibraryComputeTypeLayoutsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_container_scriptsObject



534
535
536
# File 'lib/morpheus/api/api_client.rb', line 534

def library_container_scripts
  Morpheus::LibraryContainerScriptsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_container_templatesObject



538
539
540
# File 'lib/morpheus/api/api_client.rb', line 538

def library_container_templates
  Morpheus::LibraryContainerTemplatesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_container_typesObject



530
531
532
# File 'lib/morpheus/api/api_client.rb', line 530

def library_container_types
  Morpheus::LibraryContainerTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_container_upgradesObject



526
527
528
# File 'lib/morpheus/api/api_client.rb', line 526

def library_container_upgrades
  Morpheus::LibraryContainerUpgradesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_instance_typesObject



518
519
520
# File 'lib/morpheus/api/api_client.rb', line 518

def library_instance_types
  Morpheus::LibraryInstanceTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#library_layoutsObject



522
523
524
# File 'lib/morpheus/api/api_client.rb', line 522

def library_layouts
  Morpheus::LibraryLayoutsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#licenseObject



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

#load_balancersObject



324
325
326
# File 'lib/morpheus/api/api_client.rb', line 324

def load_balancers
  Morpheus::LoadBalancersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#logged_in?Boolean

Returns:

  • (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 (username, password)
  @access_token, @refresh_token, @expires_at = nil, nil, nil
  response = auth.(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 response
  return self
end

#logoutObject



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

#logsObject



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

#monitoringObject



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_recordsObject



494
495
496
# File 'lib/morpheus/api/api_client.rb', line 494

def network_domain_records
  Morpheus::NetworkDomainRecordsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_domainsObject



490
491
492
# File 'lib/morpheus/api/api_client.rb', line 490

def network_domains
  Morpheus::NetworkDomainsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_groupsObject



470
471
472
# File 'lib/morpheus/api/api_client.rb', line 470

def network_groups
  Morpheus::NetworkGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_pool_ipsObject



478
479
480
# File 'lib/morpheus/api/api_client.rb', line 478

def network_pool_ips
  Morpheus::NetworkPoolIpsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_pool_serversObject



486
487
488
# File 'lib/morpheus/api/api_client.rb', line 486

def network_pool_servers
  Morpheus::NetworkPoolServersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_poolsObject



474
475
476
# File 'lib/morpheus/api/api_client.rb', line 474

def network_pools
  Morpheus::NetworkPoolsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_proxiesObject



498
499
500
# File 'lib/morpheus/api/api_client.rb', line 498

def network_proxies
  Morpheus::NetworkProxiesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_servicesObject



482
483
484
# File 'lib/morpheus/api/api_client.rb', line 482

def network_services
  Morpheus::NetworkServicesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_subnet_typesObject



466
467
468
# File 'lib/morpheus/api/api_client.rb', line 466

def network_subnet_types
  Morpheus::NetworkSubnetTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_subnetsObject



462
463
464
# File 'lib/morpheus/api/api_client.rb', line 462

def network_subnets
  Morpheus::NetworkSubnetsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#network_typesObject



458
459
460
# File 'lib/morpheus/api/api_client.rb', line 458

def network_types
  Morpheus::NetworkTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#networksObject



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_cypherObject



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_listsObject



408
409
410
# File 'lib/morpheus/api/api_client.rb', line 408

def option_type_lists
  Morpheus::OptionTypeListsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#option_typesObject



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

#optionsObject



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

#packagesObject



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

#policiesObject

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_schedulesObject



416
417
418
# File 'lib/morpheus/api/api_client.rb', line 416

def power_schedules
  Morpheus::PowerSchedulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#processesObject



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_typesObject



316
317
318
# File 'lib/morpheus/api/api_client.rb', line 316

def provision_types
  Morpheus::ProvisionTypesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#refresh_tokenObject



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 response
  return self
end

#reportsObject



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

#rolesObject



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_rulesObject



360
361
362
# File 'lib/morpheus/api/api_client.rb', line 360

def security_group_rules
  Morpheus::SecurityGroupRulesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#security_groupsObject



356
357
358
# File 'lib/morpheus/api/api_client.rb', line 356

def security_groups
  Morpheus::SecurityGroupsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#server_typesObject



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

#serversObject



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

#service_plansObject



320
321
322
# File 'lib/morpheus/api/api_client.rb', line 320

def service_plans
  Morpheus::ServicePlansInterface.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({})

Parameters:

  • opts (Hash)

    globally supported options like :dry_run, :json, :curl, :headers, :timeout, etc



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

#setupObject



424
425
426
# File 'lib/morpheus/api/api_client.rb', line 424

def setup
  Morpheus::SetupInterface.new(@base_url).setopts(@options).setopts(@options)
end

#ssl_verification_enabled?Boolean

Returns:

  • (Boolean)


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

def ssl_verification_enabled?
  @verify_ssl
end

#storage_providersObject



514
515
516
# File 'lib/morpheus/api/api_client.rb', line 514

def storage_providers
  Morpheus::StorageProvidersInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#task_setsObject



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

#tasksObject



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_sObject



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

#urlObject



36
37
38
# File 'lib/morpheus/api/api_client.rb', line 36

def url
  @base_url
end

#user_groupsObject



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_settingsObject



264
265
266
# File 'lib/morpheus/api/api_client.rb', line 264

def 
  Morpheus::UserSettingsInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#user_sourcesObject



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

#usersObject



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

#virtual_imagesObject



336
337
338
# File 'lib/morpheus/api/api_client.rb', line 336

def virtual_images
  Morpheus::VirtualImagesInterface.new(@access_token, @refresh_token, @expires_at, @base_url).setopts(@options)
end

#whoamiObject



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

#wikiObject



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

Parameters:

  • opts (Hash)

    globally supported options like :dry_run, :json, :curl, :headers, :timeout, etc

Returns:

  • result of block, usually the a result Hash from client.execute({})



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