Class: Morpheus::APIClient

Inherits:
Object
  • Object
show all
Defined in:
lib/morpheus/api/api_client.rb

Direct Known Subclasses

AccountGroupsInterface, AccountsInterface, ApplianceSettingsInterface, ApprovalsInterface, AppsInterface, ArchiveBucketsInterface, ArchiveFilesInterface, AuthInterface, BackupSettingsInterface, BlueprintsInterface, BudgetsInterface, CloudDatastoresInterface, CloudFoldersInterface, CloudPoliciesInterface, CloudResourcePoolsInterface, CloudsInterface, ClustersInterface, ContainersInterface, CustomInstanceTypesInterface, CypherInterface, DashboardInterface, DatastoresInterface, DeployInterface, DeploymentsInterface, EnvironmentsInterface, ExecuteSchedulesInterface, ExecutionRequestInterface, FileCopyRequestInterface, GroupPoliciesInterface, GroupsInterface, GuidanceInterface, HealthInterface, ImageBuilderBootScriptsInterface, ImageBuilderImageBuildsInterface, ImageBuilderInterface, ImageBuilderPreseedScriptsInterface, InstanceTypesInterface, InstancesInterface, IntegrationsInterface, InvoicesInterface, JobsInterface, KeyPairsInterface, LibraryClusterLayoutsInterface, LibraryContainerScriptsInterface, LibraryContainerTemplatesInterface, LibraryContainerTypesInterface, LibraryContainerUpgradesInterface, LibraryInstanceTypesInterface, LibraryLayoutsInterface, LibrarySpecTemplateTypesInterface, LibrarySpecTemplatesInterface, LicenseInterface, LoadBalancersInterface, LogSettingsInterface, LogsInterface, MonitoringAlertsInterface, MonitoringAppsInterface, MonitoringChecksInterface, MonitoringContactsInterface, MonitoringGroupsInterface, MonitoringIncidentsInterface, MonitoringInterface, NetworkDomainRecordsInterface, NetworkDomainsInterface, NetworkGroupsInterface, NetworkPoolIpsInterface, NetworkPoolServersInterface, NetworkPoolsInterface, NetworkProxiesInterface, NetworkRoutersInterface, NetworkSecurityServersInterface, NetworkServicesInterface, NetworkSubnetsInterface, NetworkTypesInterface, NetworksInterface, OptionTypeListsInterface, OptionTypesInterface, OptionsInterface, PackagesInterface, PoliciesInterface, PowerSchedulesInterface, PriceSetsInterface, PricesInterface, ProcessesInterface, ProvisionTypesInterface, ProvisioningLicenseTypesInterface, ProvisioningLicensesInterface, ProvisioningSettingsInterface, ReportsInterface, RolesInterface, SecurityGroupRulesInterface, SecurityGroupsInterface, ServerTypesInterface, ServersInterface, ServicePlansInterface, SetupInterface, StorageProvidersInterface, SubnetTypesInterface, SubnetsInterface, TaskSetsInterface, TasksInterface, UserGroupsInterface, UserSettingsInterface, UserSourcesInterface, UsersInterface, VirtualImagesInterface, WhitelabelSettingsInterface, WhoamiInterface, WikiInterface

Constant Summary collapse

CLIENT_ID =
'morph-cli'

Instance Attribute Summary collapse

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={})

def initialize(attrs={}, options={})



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/morpheus/api/api_client.rb', line 16

def initialize(access_token, refresh_token=nil,expires_in = nil, base_url=nil, verify_ssl=true, options={})
  self.client_id = CLIENT_ID
  attrs = {}
  if access_token.is_a?(Hash)
    attrs = access_token.clone()
    access_token = attrs[:access_token]
    refresh_token = attrs[:refresh_token]
    base_url = attrs[:url] || attrs[:base_url]
    expires_in = attrs[:expires_in]
    verify_ssl = attrs.key?(:verify_ssl) ? attrs[:verify_ssl] : true
    self.client_id = attrs[:client_id] ? attrs[:client_id] : CLIENT_ID
    if attrs[:client_id]
      self.client_id = attrs[:client_id]
    end
    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 Attribute Details

#client_idObject

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

Instance Method Details

#account_groupsObject



302
303
304
# File 'lib/morpheus/api/api_client.rb', line 302

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

#accountsObject



430
431
432
# File 'lib/morpheus/api/api_client.rb', line 430

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

#appliance_settingsObject



334
335
336
# File 'lib/morpheus/api/api_client.rb', line 334

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

#approvalsObject



434
435
436
# File 'lib/morpheus/api/api_client.rb', line 434

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

#appsObject



402
403
404
# File 'lib/morpheus/api/api_client.rb', line 402

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

#archive_bucketsObject



577
578
579
# File 'lib/morpheus/api/api_client.rb', line 577

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

#archive_filesObject



581
582
583
# File 'lib/morpheus/api/api_client.rb', line 581

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

#authObject



282
283
284
# File 'lib/morpheus/api/api_client.rb', line 282

def auth
  Morpheus::AuthInterface.new({url: @base_url, client_id: @client_id}).setopts(@options)
end

#backup_settingsObject



661
662
663
# File 'lib/morpheus/api/api_client.rb', line 661

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

#blueprintsObject



406
407
408
# File 'lib/morpheus/api/api_client.rb', line 406

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

#budgetsObject



677
678
679
# File 'lib/morpheus/api/api_client.rb', line 677

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

#cloud_datastoresObject



310
311
312
# File 'lib/morpheus/api/api_client.rb', line 310

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

#cloud_foldersObject



318
319
320
# File 'lib/morpheus/api/api_client.rb', line 318

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

#cloud_policiesObject



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

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

#cloud_resource_poolsObject



314
315
316
# File 'lib/morpheus/api/api_client.rb', line 314

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

#cloudsObject



306
307
308
# File 'lib/morpheus/api/api_client.rb', line 306

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

#clustersObject



426
427
428
# File 'lib/morpheus/api/api_client.rb', line 426

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

#common_iface_optsObject



278
279
280
# File 'lib/morpheus/api/api_client.rb', line 278

def common_iface_opts
  {url: @base_url, access_token: @access_token, refresh_token: @refresh_token, expires_at: @expires_at}
end

#containersObject



350
351
352
# File 'lib/morpheus/api/api_client.rb', line 350

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

#custom_instance_typesObject



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

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

#cypherObject



633
634
635
# File 'lib/morpheus/api/api_client.rb', line 633

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

#dashboardObject



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

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

#datastoresObject



322
323
324
# File 'lib/morpheus/api/api_client.rb', line 322

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

#default_content_typeObject

set this in your interface, eg. to ‘application/json’



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

def default_content_type
  nil
end

#deployObject



410
411
412
# File 'lib/morpheus/api/api_client.rb', line 410

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

#deploymentsObject



414
415
416
# File 'lib/morpheus/api/api_client.rb', line 414

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

#dryObject



64
65
66
# File 'lib/morpheus/api/api_client.rb', line 64

def dry()
  dry_run(true)
end

#dry_run(val = true) ⇒ Object



59
60
61
62
# File 'lib/morpheus/api/api_client.rb', line 59

def dry_run(val=true)
  @dry_run = !!val
  self
end

#environmentsObject



657
658
659
# File 'lib/morpheus/api/api_client.rb', line 657

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. {'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


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
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/morpheus/api/api_client.rb', line 134

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



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

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

#execution_requestObject



641
642
643
# File 'lib/morpheus/api/api_client.rb', line 641

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

#file_copy_requestObject



645
646
647
# File 'lib/morpheus/api/api_client.rb', line 645

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

#group_policiesObject



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

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

#groupsObject



298
299
300
# File 'lib/morpheus/api/api_client.rb', line 298

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

#guidanceObject



689
690
691
# File 'lib/morpheus/api/api_client.rb', line 689

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

#healthObject



681
682
683
# File 'lib/morpheus/api/api_client.rb', line 681

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

#image_builderObject



585
586
587
# File 'lib/morpheus/api/api_client.rb', line 585

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

#inspectObject



55
56
57
# File 'lib/morpheus/api/api_client.rb', line 55

def inspect
  to_s
end

#instance_typesObject



354
355
356
# File 'lib/morpheus/api/api_client.rb', line 354

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

#instancesObject



330
331
332
# File 'lib/morpheus/api/api_client.rb', line 330

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

#integrationsObject



358
359
360
# File 'lib/morpheus/api/api_client.rb', line 358

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

#invoicesObject



685
686
687
# File 'lib/morpheus/api/api_client.rb', line 685

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

#jobsObject



362
363
364
# File 'lib/morpheus/api/api_client.rb', line 362

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

#key_pairsObject



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

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

#library_cluster_layoutsObject



617
618
619
# File 'lib/morpheus/api/api_client.rb', line 617

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

#library_container_scriptsObject



609
610
611
# File 'lib/morpheus/api/api_client.rb', line 609

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

#library_container_templatesObject



613
614
615
# File 'lib/morpheus/api/api_client.rb', line 613

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

#library_container_typesObject



605
606
607
# File 'lib/morpheus/api/api_client.rb', line 605

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

#library_container_upgradesObject



601
602
603
# File 'lib/morpheus/api/api_client.rb', line 601

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

#library_instance_typesObject



593
594
595
# File 'lib/morpheus/api/api_client.rb', line 593

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

#library_layoutsObject



597
598
599
# File 'lib/morpheus/api/api_client.rb', line 597

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

#library_spec_template_typesObject



625
626
627
# File 'lib/morpheus/api/api_client.rb', line 625

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

#library_spec_templatesObject



621
622
623
# File 'lib/morpheus/api/api_client.rb', line 621

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

#licenseObject



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

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

#load_balancersObject



386
387
388
# File 'lib/morpheus/api/api_client.rb', line 386

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

#log_settingsObject



665
666
667
# File 'lib/morpheus/api/api_client.rb', line 665

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

#logged_in?Boolean

Returns:

  • (Boolean)


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

def logged_in?
  !!@access_token
end

#login(username, password, use_client_id = nil) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/morpheus/api/api_client.rb', line 241

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



271
272
273
274
275
276
# File 'lib/morpheus/api/api_client.rb', line 271

def logout
  @access_token = nil
  @refresh_token = nil
  @expires_at = nil
  return self
end

#logsObject



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

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

#monitoringObject



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

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

#network_domain_recordsObject



569
570
571
# File 'lib/morpheus/api/api_client.rb', line 569

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

#network_domainsObject



565
566
567
# File 'lib/morpheus/api/api_client.rb', line 565

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

#network_groupsObject



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

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

#network_pool_ipsObject



545
546
547
# File 'lib/morpheus/api/api_client.rb', line 545

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

#network_pool_serversObject



561
562
563
# File 'lib/morpheus/api/api_client.rb', line 561

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

#network_poolsObject



541
542
543
# File 'lib/morpheus/api/api_client.rb', line 541

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

#network_proxiesObject



573
574
575
# File 'lib/morpheus/api/api_client.rb', line 573

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

#network_routersObject



549
550
551
# File 'lib/morpheus/api/api_client.rb', line 549

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

#network_security_serversObject



557
558
559
# File 'lib/morpheus/api/api_client.rb', line 557

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

#network_servicesObject



553
554
555
# File 'lib/morpheus/api/api_client.rb', line 553

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

#network_typesObject



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

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

#networksObject



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

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

#old_cypherObject



637
638
639
# File 'lib/morpheus/api/api_client.rb', line 637

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

#option_type_listsObject



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

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

#option_typesObject



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

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

#optionsObject



294
295
296
# File 'lib/morpheus/api/api_client.rb', line 294

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

#packagesObject



629
630
631
# File 'lib/morpheus/api/api_client.rb', line 629

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



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

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

#power_schedulesObject



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

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

#price_setsObject



378
379
380
# File 'lib/morpheus/api/api_client.rb', line 378

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

#pricesObject



382
383
384
# File 'lib/morpheus/api/api_client.rb', line 382

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

#processesObject



649
650
651
# File 'lib/morpheus/api/api_client.rb', line 649

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

#provision_typesObject



370
371
372
# File 'lib/morpheus/api/api_client.rb', line 370

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

#provisioning_license_typesObject



346
347
348
# File 'lib/morpheus/api/api_client.rb', line 346

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

#provisioning_licensesObject



342
343
344
# File 'lib/morpheus/api/api_client.rb', line 342

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

#provisioning_settingsObject



338
339
340
# File 'lib/morpheus/api/api_client.rb', line 338

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

#refresh_tokenObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/morpheus/api/api_client.rb', line 256

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, self.client_id)
  @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



653
654
655
# File 'lib/morpheus/api/api_client.rb', line 653

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

#rolesObject



454
455
456
# File 'lib/morpheus/api/api_client.rb', line 454

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

#security_group_rulesObject



422
423
424
# File 'lib/morpheus/api/api_client.rb', line 422

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

#security_groupsObject



418
419
420
# File 'lib/morpheus/api/api_client.rb', line 418

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

#server_typesObject



366
367
368
# File 'lib/morpheus/api/api_client.rb', line 366

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

#serversObject



326
327
328
# File 'lib/morpheus/api/api_client.rb', line 326

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

#service_plansObject



374
375
376
# File 'lib/morpheus/api/api_client.rb', line 374

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

#set_ssl_verification_enabled(val) ⇒ Object



72
73
74
# File 'lib/morpheus/api/api_client.rb', line 72

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



97
98
99
100
101
102
103
# File 'lib/morpheus/api/api_client.rb', line 97

def setopts(new_options)
  @options = new_options
  if @options[:dry_run]
    dry_run(true)
  end
  self
end

#setupObject



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

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

#ssl_verification_enabled?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/morpheus/api/api_client.rb', line 68

def ssl_verification_enabled?
  @verify_ssl
end

#storage_providersObject



589
590
591
# File 'lib/morpheus/api/api_client.rb', line 589

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

#subnet_typesObject



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

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

#subnetsObject



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

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

#task_setsObject



394
395
396
# File 'lib/morpheus/api/api_client.rb', line 394

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

#tasksObject



390
391
392
# File 'lib/morpheus/api/api_client.rb', line 390

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

#to_sObject



51
52
53
# File 'lib/morpheus/api/api_client.rb', line 51

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} @client_id=#{@client_id} @options=#{@options}>"
end

#urlObject



47
48
49
# File 'lib/morpheus/api/api_client.rb', line 47

def url
  @base_url
end

#user_groupsObject



442
443
444
# File 'lib/morpheus/api/api_client.rb', line 442

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

#user_settingsObject



290
291
292
# File 'lib/morpheus/api/api_client.rb', line 290

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

#user_sourcesObject



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

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

#usersObject



438
439
440
# File 'lib/morpheus/api/api_client.rb', line 438

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

#virtual_imagesObject



398
399
400
# File 'lib/morpheus/api/api_client.rb', line 398

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

#whitelabel_settingsObject



669
670
671
# File 'lib/morpheus/api/api_client.rb', line 669

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

#whoamiObject



286
287
288
# File 'lib/morpheus/api/api_client.rb', line 286

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

#wikiObject



673
674
675
# File 'lib/morpheus/api/api_client.rb', line 673

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({})



109
110
111
112
113
114
115
116
117
118
# File 'lib/morpheus/api/api_client.rb', line 109

def withopts(tmp_options, &block)
  @_old_options = @options
  begin
    @options = tmp_options
    result = block.call()
  ensure
    @options = @_old_options
  end
  return result
end