Class: Morpheus::APIClient

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

Overview

require 'rest-client'

Direct Known Subclasses

AccountGroupsInterface, ActivityInterface, ApplianceSettingsInterface, ApprovalsInterface, AppsInterface, ArchiveBucketsInterface, ArchiveFilesInterface, AuthInterface, BackupSettingsInterface, BillingInterface, BlueprintsInterface, BudgetsInterface, ClientsInterface, CloudDatastoresInterface, CloudFoldersInterface, CloudPoliciesInterface, CloudResourcePoolsInterface, CloudsInterface, ClustersInterface, ContainersInterface, CustomInstanceTypesInterface, CypherInterface, DashboardInterface, DatastoresInterface, DeployInterface, DocInterface, EnvironmentsInterface, ExecuteSchedulesInterface, ExecutionRequestInterface, FileCopyRequestInterface, ForgotPasswordInterface, GroupPoliciesInterface, GroupsInterface, GuidanceInterface, HealthInterface, ImageBuilderBootScriptsInterface, ImageBuilderImageBuildsInterface, ImageBuilderInterface, ImageBuilderPreseedScriptsInterface, InstanceTypesInterface, InstancesInterface, InvoicesInterface, JobsInterface, KeyPairsInterface, LibraryClusterLayoutsInterface, LibraryContainerScriptsInterface, LibraryContainerTemplatesInterface, LibraryContainerTypesInterface, LibraryContainerUpgradesInterface, LibraryInstanceTypesInterface, LibraryLayoutsInterface, LibrarySpecTemplateTypesInterface, LibrarySpecTemplatesInterface, LicenseInterface, 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, PingInterface, PoliciesInterface, PowerSchedulesInterface, PriceSetsInterface, PricesInterface, ProcessesInterface, ProjectsInterface, ProvisionTypesInterface, ProvisioningLicenseTypesInterface, ProvisioningLicensesInterface, ProvisioningSettingsInterface, ReadInterface, ReportsInterface, RestInterface, RolesInterface, SearchInterface, SecondaryReadInterface, SecondaryRestInterface, SecurityGroupRulesInterface, SecurityGroupsInterface, ServerTypesInterface, ServersInterface, ServiceCatalogInterface, ServicePlansInterface, SetupInterface, SnapshotsInterface, StorageProvidersInterface, SubnetTypesInterface, SubnetsInterface, TaskSetsInterface, TasksInterface, UsageInterface, UserGroupsInterface, UserSettingsInterface, UserSourcesInterface, VdiInterface, 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={})



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
46
47
48
# File 'lib/morpheus/api/api_client.rb', line 19

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} initialized without a required 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_id ⇒ Object

Returns the value of attribute client_id.



12
13
14
# File 'lib/morpheus/api/api_client.rb', line 12

def client_id
  @client_id
end

Instance Method Details

#account_groups ⇒ Object



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

def 
  Morpheus::AccountGroupsInterface.new(common_interface_options).setopts(@options)
end

#account_users ⇒ Object



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

def 
  Morpheus::AccountUsersInterface.new(common_interface_options).setopts(@options)
end

#accounts ⇒ Object



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

def accounts
  Morpheus::AccountsInterface.new(common_interface_options).setopts(@options)
end

#activity ⇒ Object



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

def activity
  Morpheus::ActivityInterface.new(common_interface_options).setopts(@options)
end

#appliance_settings ⇒ Object



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

def appliance_settings
  Morpheus::ApplianceSettingsInterface.new(common_interface_options).setopts(@options)
end

#approvals ⇒ Object



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

def approvals
  Morpheus::ApprovalsInterface.new(common_interface_options).setopts(@options)
end

#apps ⇒ Object



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

def apps
  Morpheus::AppsInterface.new(common_interface_options).setopts(@options)
end

#archive_buckets ⇒ Object



692
693
694
# File 'lib/morpheus/api/api_client.rb', line 692

def archive_buckets
  Morpheus::ArchiveBucketsInterface.new(common_interface_options).setopts(@options)
end

#archive_files ⇒ Object



696
697
698
# File 'lib/morpheus/api/api_client.rb', line 696

def archive_files
  Morpheus::ArchiveFilesInterface.new(common_interface_options).setopts(@options)
end

#audit ⇒ Object



816
817
818
# File 'lib/morpheus/api/api_client.rb', line 816

def audit
  Morpheus::AuditInterface.new(common_interface_options).setopts(@options)
end

#auth ⇒ Object



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

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

#authorization_required? ⇒ Boolean

Authorization is required, except for a couple commands like Ping and Setup

Returns:

  • (Boolean)


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

def authorization_required?
  true
end

#backup_jobs ⇒ Object



844
845
846
# File 'lib/morpheus/api/api_client.rb', line 844

def backup_jobs
  Morpheus::BackupJobsInterface.new(common_interface_options).setopts(@options)
end

#backup_service_types ⇒ Object



852
853
854
# File 'lib/morpheus/api/api_client.rb', line 852

def backup_service_types
  Morpheus::BackupServiceTypesInterface.new(common_interface_options).setopts(@options)
end

#backup_services ⇒ Object



848
849
850
# File 'lib/morpheus/api/api_client.rb', line 848

def backup_services
  Morpheus::BackupServicesInterface.new(common_interface_options).setopts(@options)
end

#backup_settings ⇒ Object



796
797
798
# File 'lib/morpheus/api/api_client.rb', line 796

def backup_settings
  Morpheus::BackupSettingsInterface.new(common_interface_options).setopts(@options)
end

#backups ⇒ Object



840
841
842
# File 'lib/morpheus/api/api_client.rb', line 840

def backups
  Morpheus::BackupsInterface.new(common_interface_options).setopts(@options)
end

#billing ⇒ Object



868
869
870
# File 'lib/morpheus/api/api_client.rb', line 868

def billing
  Morpheus::BillingInterface.new(common_interface_options).setopts(@options)
end

#blueprints ⇒ Object



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

def blueprints
  Morpheus::BlueprintsInterface.new(common_interface_options).setopts(@options)
end

#budgets ⇒ Object



820
821
822
# File 'lib/morpheus/api/api_client.rb', line 820

def budgets
  Morpheus::BudgetsInterface.new(common_interface_options).setopts(@options)
end

#catalog ⇒ Object



860
861
862
# File 'lib/morpheus/api/api_client.rb', line 860

def catalog
  Morpheus::ServiceCatalogInterface.new(common_interface_options).setopts(@options)
end

#catalog_item_types ⇒ Object



856
857
858
# File 'lib/morpheus/api/api_client.rb', line 856

def catalog_item_types
  Morpheus::CatalogItemTypesInterface.new(common_interface_options).setopts(@options)
end

#certificate_types ⇒ Object



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

def certificate_types
  Morpheus::CertificateTypesInterface.new(common_interface_options).setopts(@options)
end

#certificates ⇒ Object



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

def certificates
  Morpheus::CertificatesInterface.new(common_interface_options).setopts(@options)
end

#clients ⇒ Object



924
925
926
# File 'lib/morpheus/api/api_client.rb', line 924

def clients
  Morpheus::ClientsInterface.new(common_interface_options).setopts(@options)
end

#cloud_datastores ⇒ Object



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

def cloud_datastores
  Morpheus::CloudDatastoresInterface.new(common_interface_options).setopts(@options)
end

#cloud_folders ⇒ Object



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

def cloud_folders
  Morpheus::CloudFoldersInterface.new(common_interface_options).setopts(@options)
end

#cloud_policies ⇒ Object



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

def cloud_policies
  Morpheus::CloudPoliciesInterface.new(common_interface_options).setopts(@options)
end

#cloud_resource_pools ⇒ Object



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

def cloud_resource_pools
  Morpheus::CloudResourcePoolsInterface.new(common_interface_options).setopts(@options)
end

#clouds ⇒ Object



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

def clouds
  Morpheus::CloudsInterface.new(common_interface_options).setopts(@options)
end

#clusters ⇒ Object



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

def clusters
  Morpheus::ClustersInterface.new(common_interface_options).setopts(@options)
end

#common_interface_options ⇒ Object



327
328
329
330
331
332
333
334
335
336
# File 'lib/morpheus/api/api_client.rb', line 327

def common_interface_options
  {
    url:           @base_url,
    access_token:  @access_token,
    refresh_token: @refresh_token,
    expires_at:    @expires_at,
    client_id:     @client_id,
    verify_ssl:    @verify_ssl
  }
end

#containers ⇒ Object



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

def containers
  Morpheus::ContainersInterface.new(common_interface_options).setopts(@options)
end

#credential_types ⇒ Object



920
921
922
# File 'lib/morpheus/api/api_client.rb', line 920

def credential_types
  Morpheus::CredentialTypesInterface.new(common_interface_options).setopts(@options)
end

#credentials ⇒ Object



916
917
918
# File 'lib/morpheus/api/api_client.rb', line 916

def credentials
  Morpheus::CredentialsInterface.new(common_interface_options).setopts(@options)
end

#cypher ⇒ Object



768
769
770
# File 'lib/morpheus/api/api_client.rb', line 768

def cypher
  Morpheus::CypherInterface.new(common_interface_options).setopts(@options)
end

#dashboard ⇒ Object



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

def dashboard
  Morpheus::DashboardInterface.new(common_interface_options).setopts(@options)
end

#datastores ⇒ Object



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

def datastores
  Morpheus::DatastoresInterface.new(common_interface_options).setopts(@options)
end

#default_content_type ⇒ Object

set this in your interface, eg. to 'application/json' or let it it default to json when payload is present.



81
82
83
# File 'lib/morpheus/api/api_client.rb', line 81

def default_content_type
  nil
end

#default_timeout ⇒ Object

set default seconds for interface to timeout after or let it use system default? none, it should not timeout by default.. I think execute() may use 30 seconds for get by default. and it should remove timeout when method is post, put, or delete



89
90
91
# File 'lib/morpheus/api/api_client.rb', line 89

def default_timeout
  nil
end

#deploy ⇒ Object



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

def deploy
  Morpheus::DeployInterface.new(common_interface_options).setopts(@options)
end

#deployments ⇒ Object



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

def deployments
  Morpheus::DeploymentsInterface.new(common_interface_options).setopts(@options)
end

#doc ⇒ Object



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

def doc
  Morpheus::DocInterface.new(common_interface_options).setopts(@options)
end

#dry ⇒ Object



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

def dry()
  dry_run(true)
end

#dry_run(val = true) ⇒ Object



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

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

#environments ⇒ Object



792
793
794
# File 'lib/morpheus/api/api_client.rb', line 792

def environments
  Morpheus::EnvironmentsInterface.new(common_interface_options).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



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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/morpheus/api/api_client.rb', line 151

def execute(opts, options={})
  # Morpheus::Logging::DarkPrinter.puts "Morpheus::RestClient.execute(#{opts})" if Morpheus::Logging.debug?
  # ok, always prepend @base_url, let the caller specify it exactly or leave it off.
  # this allows the Interface definition be lazy and not specify the base_url in every call to execute()
    # it will be used though...
  if opts[:url]
    if !opts[:url].include?(@base_url)
      opts[:url] = "#{@base_url}#{opts[:url]}"
    end
  end
  # merge in common global @options
  if @options
    options = options.merge(@options)
  else
    options = options.clone
  end

  # determine HTTP method
  if opts[:method].nil?
    opts[:method] = :get
  else
    # convert to lowercase Symbol like :get, :post, :put, or :delete
    opts[:method] = opts[:method].to_s.downcase.to_sym
  end

  # could validate method here...

  # apply default headers
  opts[:headers] ||= {}

  is_multipart = (opts[:payload].is_a?(Hash) && opts[:payload][:multipart] == true)

  # Authorization: apply our access token
  if authorization_required?
    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
  end

  # POST and PUT requests default Content-Type is application/json
  # set Content-Type or pass :form_data => true if you want application/x-www-form-urlencoded
  # or use opts[:payload][:multipart] = true if you need multipart/form-data
  if opts[:method] == :post || opts[:method] == :put
    if opts[:headers]['Content-Type'].nil? && opts[:payload] && is_multipart != true && opts[:form_data] != true
      opts[:headers]['Content-Type'] = (default_content_type || 'application/json')
    end

    # Auto encode payload as JSON, just to be nice
    if opts[:headers]['Content-Type'] == 'application/json' && !opts[:payload].is_a?(String)
      opts[:payload] = opts[:payload].to_json
    end

  end

  # always use custom timeout eg. from --timeout option
  # or use default_timeout for GET requests only.
  if opts[:timeout].nil?
    if options[:timeout]
      opts[:timeout] = options[:timeout].to_f
    elsif default_timeout && opts[:method] == :get
      opts[:timeout] = default_timeout.to_f
    end
  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...?
  # 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.delete(: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 @foos_interface = @api_client.foos
  # 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_schedules ⇒ Object



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

def execute_schedules
  Morpheus::ExecuteSchedulesInterface.new(common_interface_options).setopts(@options)
end

#execution_request ⇒ Object



776
777
778
# File 'lib/morpheus/api/api_client.rb', line 776

def execution_request
  Morpheus::ExecutionRequestInterface.new(common_interface_options).setopts(@options)
end

#file_copy_request ⇒ Object



780
781
782
# File 'lib/morpheus/api/api_client.rb', line 780

def file_copy_request
  Morpheus::FileCopyRequestInterface.new(common_interface_options).setopts(@options)
end

#forgot ⇒ Object



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

def forgot
  Morpheus::ForgotPasswordInterface.new(common_interface_options).setopts(@options)
end

#group_policies ⇒ Object



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

def group_policies
  Morpheus::GroupPoliciesInterface.new(common_interface_options).setopts(@options)
end

#groups ⇒ Object



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

def groups
  Morpheus::GroupsInterface.new(common_interface_options).setopts(@options)
end

#guidance ⇒ Object



832
833
834
# File 'lib/morpheus/api/api_client.rb', line 832

def guidance
  Morpheus::GuidanceInterface.new(common_interface_options).setopts(@options)
end

#health ⇒ Object



812
813
814
# File 'lib/morpheus/api/api_client.rb', line 812

def health
  Morpheus::HealthInterface.new(common_interface_options).setopts(@options)
end

#image_builder ⇒ Object



700
701
702
# File 'lib/morpheus/api/api_client.rb', line 700

def image_builder
  Morpheus::ImageBuilderInterface.new(common_interface_options).setopts(@options)
end

#inspect ⇒ Object



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

def inspect
  to_s
end

#instance_types ⇒ Object



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

def instance_types
  Morpheus::InstanceTypesInterface.new(common_interface_options).setopts(@options)
end

#instances ⇒ Object



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

def instances
  Morpheus::InstancesInterface.new(common_interface_options).setopts(@options)
end

#integration_types ⇒ Object



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

def integration_types
  Morpheus::IntegrationTypesInterface.new(common_interface_options).setopts(@options)
end

#integrations ⇒ Object



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

def integrations
  Morpheus::IntegrationsInterface.new(common_interface_options).setopts(@options)
end

#interface(type) ⇒ Object Also known as: get_interface



944
945
946
947
948
949
950
951
# File 'lib/morpheus/api/api_client.rb', line 944

def interface(type)
  type = type.to_s.singularize.underscore
  interface_name = type.pluralize
  if !respond_to?(interface_name)
    raise "#{self.class} has not defined an interface method named '#{interface_name}'"
  end
  return send(interface_name)
end

#invoice_line_items ⇒ Object



828
829
830
# File 'lib/morpheus/api/api_client.rb', line 828

def invoice_line_items
  Morpheus::InvoiceLineItemsInterface.new(common_interface_options).setopts(@options)
end

#invoices ⇒ Object



824
825
826
# File 'lib/morpheus/api/api_client.rb', line 824

def invoices
  Morpheus::InvoicesInterface.new(common_interface_options).setopts(@options)
end

#jobs ⇒ Object



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

def jobs
  Morpheus::JobsInterface.new(common_interface_options).setopts(@options)
end

#key_pairs ⇒ Object



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

def key_pairs
  Morpheus::KeyPairsInterface.new(common_interface_options).setopts(@options)
end

#library_cluster_layouts ⇒ Object



748
749
750
# File 'lib/morpheus/api/api_client.rb', line 748

def library_cluster_layouts
  Morpheus::LibraryClusterLayoutsInterface.new(common_interface_options).setopts(@options)
end

#library_container_scripts ⇒ Object



740
741
742
# File 'lib/morpheus/api/api_client.rb', line 740

def library_container_scripts
  Morpheus::LibraryContainerScriptsInterface.new(common_interface_options).setopts(@options)
end

#library_container_templates ⇒ Object



744
745
746
# File 'lib/morpheus/api/api_client.rb', line 744

def library_container_templates
  Morpheus::LibraryContainerTemplatesInterface.new(common_interface_options).setopts(@options)
end

#library_container_types ⇒ Object



736
737
738
# File 'lib/morpheus/api/api_client.rb', line 736

def library_container_types
  Morpheus::LibraryContainerTypesInterface.new(common_interface_options).setopts(@options)
end

#library_container_upgrades ⇒ Object



732
733
734
# File 'lib/morpheus/api/api_client.rb', line 732

def library_container_upgrades
  Morpheus::LibraryContainerUpgradesInterface.new(common_interface_options).setopts(@options)
end

#library_instance_types ⇒ Object



724
725
726
# File 'lib/morpheus/api/api_client.rb', line 724

def library_instance_types
  Morpheus::LibraryInstanceTypesInterface.new(common_interface_options).setopts(@options)
end

#library_layouts ⇒ Object



728
729
730
# File 'lib/morpheus/api/api_client.rb', line 728

def library_layouts
  Morpheus::LibraryLayoutsInterface.new(common_interface_options).setopts(@options)
end

#library_spec_template_types ⇒ Object



756
757
758
# File 'lib/morpheus/api/api_client.rb', line 756

def library_spec_template_types
  Morpheus::LibrarySpecTemplateTypesInterface.new(common_interface_options).setopts(@options)
end

#library_spec_templates ⇒ Object



752
753
754
# File 'lib/morpheus/api/api_client.rb', line 752

def library_spec_templates
  Morpheus::LibrarySpecTemplatesInterface.new(common_interface_options).setopts(@options)
end

#license ⇒ Object



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

def license
  Morpheus::LicenseInterface.new(common_interface_options).setopts(@options)
end

#load_balancer_monitors ⇒ Object



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

def load_balancer_monitors
  Morpheus::LoadBalancerMonitorsInterface.new(common_interface_options).setopts(@options)
end

#load_balancer_pools ⇒ Object



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

def load_balancer_pools
  Morpheus::LoadBalancerPoolsInterface.new(common_interface_options).setopts(@options)
end

#load_balancer_profiles ⇒ Object



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

def load_balancer_profiles
  Morpheus::LoadBalancerProfilesInterface.new(common_interface_options).setopts(@options)
end

#load_balancer_types ⇒ Object



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

def load_balancer_types
  Morpheus::LoadBalancerTypesInterface.new(common_interface_options).setopts(@options)
end

#load_balancer_virtual_servers ⇒ Object



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

def load_balancer_virtual_servers
  Morpheus::LoadBalancerVirtualServersInterface.new(common_interface_options).setopts(@options)
end

#load_balancers ⇒ Object



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

def load_balancers
  Morpheus::LoadBalancersInterface.new(common_interface_options).setopts(@options)
end

#log_settings ⇒ Object



800
801
802
# File 'lib/morpheus/api/api_client.rb', line 800

def log_settings
  Morpheus::LogSettingsInterface.new(common_interface_options).setopts(@options)
end

#logged_in? ⇒ Boolean

Returns:

  • (Boolean)


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

def logged_in?
  !!@access_token
end

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



287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/morpheus/api/api_client.rb', line 287

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

#logout ⇒ Object



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

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

#logs ⇒ Object



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

def logs
  Morpheus::LogsInterface.new(common_interface_options).setopts(@options)
end

#monitoring ⇒ Object



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

def monitoring
  Morpheus::MonitoringInterface.new(common_interface_options).setopts(@options)
end

#network_dhcp_relays ⇒ Object



904
905
906
# File 'lib/morpheus/api/api_client.rb', line 904

def network_dhcp_relays
  Morpheus::NetworkDhcpRelaysInterface.new(common_interface_options).setopts(@options)
end

#network_dhcp_servers ⇒ Object



900
901
902
# File 'lib/morpheus/api/api_client.rb', line 900

def network_dhcp_servers
  Morpheus::NetworkDhcpServersInterface.new(common_interface_options).setopts(@options)
end

#network_domain_records ⇒ Object



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

def network_domain_records
  Morpheus::NetworkDomainRecordsInterface.new(common_interface_options).setopts(@options)
end

#network_domains ⇒ Object



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

def network_domains
  Morpheus::NetworkDomainsInterface.new(common_interface_options).setopts(@options)
end

#network_edge_clusters ⇒ Object



896
897
898
# File 'lib/morpheus/api/api_client.rb', line 896

def network_edge_clusters
  Morpheus::NetworkEdgeClustersInterface.new(common_interface_options).setopts(@options)
end

#network_groups ⇒ Object



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

def network_groups
  Morpheus::NetworkGroupsInterface.new(common_interface_options).setopts(@options)
end

#network_pool_ips ⇒ Object



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

def network_pool_ips
  Morpheus::NetworkPoolIpsInterface.new(common_interface_options).setopts(@options)
end

#network_pool_server_types ⇒ Object



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

def network_pool_server_types
  Morpheus::NetworkPoolServerTypesInterface.new(common_interface_options).setopts(@options)
end

#network_pool_servers ⇒ Object



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

def network_pool_servers
  Morpheus::NetworkPoolServersInterface.new(common_interface_options).setopts(@options)
end

#network_pools ⇒ Object



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

def network_pools
  Morpheus::NetworkPoolsInterface.new(common_interface_options).setopts(@options)
end

#network_proxies ⇒ Object



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

def network_proxies
  Morpheus::NetworkProxiesInterface.new(common_interface_options).setopts(@options)
end

#network_routers ⇒ Object



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

def network_routers
  Morpheus::NetworkRoutersInterface.new(common_interface_options).setopts(@options)
end

#network_security_servers ⇒ Object



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

def network_security_servers
  Morpheus::NetworkSecurityServersInterface.new(common_interface_options).setopts(@options)
end

#network_servers ⇒ Object



892
893
894
# File 'lib/morpheus/api/api_client.rb', line 892

def network_servers
  Morpheus::NetworkServersInterface.new(common_interface_options).setopts(@options)
end

#network_services ⇒ Object



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

def network_services
  Morpheus::NetworkServicesInterface.new(common_interface_options).setopts(@options)
end

#network_static_routes ⇒ Object



908
909
910
# File 'lib/morpheus/api/api_client.rb', line 908

def network_static_routes
  Morpheus::NetworkStaticRoutesInterface.new(common_interface_options).setopts(@options)
end

#network_types ⇒ Object



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

def network_types
  Morpheus::NetworkTypesInterface.new(common_interface_options).setopts(@options)
end

#networks ⇒ Object



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

def networks
  Morpheus::NetworksInterface.new(common_interface_options).setopts(@options)
end

#old_cypher ⇒ Object



772
773
774
# File 'lib/morpheus/api/api_client.rb', line 772

def old_cypher
  Morpheus::OldCypherInterface.new(common_interface_options).setopts(@options)
end

#option_type_lists ⇒ Object



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

def option_type_lists
  Morpheus::OptionTypeListsInterface.new(common_interface_options).setopts(@options)
end

#option_types ⇒ Object



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

def option_types
  Morpheus::OptionTypesInterface.new(common_interface_options).setopts(@options)
end

#options ⇒ Object



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

def options
  Morpheus::OptionsInterface.new(common_interface_options).setopts(@options)
end

#packages ⇒ Object



760
761
762
# File 'lib/morpheus/api/api_client.rb', line 760

def packages
  Morpheus::PackagesInterface.new(common_interface_options).setopts(@options)
end

#ping ⇒ Object



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

def ping
  Morpheus::PingInterface.new(common_interface_options).setopts(@options)
end

#plugins ⇒ Object



764
765
766
# File 'lib/morpheus/api/api_client.rb', line 764

def plugins
  Morpheus::PluginsInterface.new(common_interface_options).setopts(@options)
end

#policies ⇒ Object

def incidents

Morpheus::MonitoringIncidentsInterface.new(common_interface_options).setopts(@options)

monitoring.incidents end



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

def policies
  Morpheus::PoliciesInterface.new(common_interface_options).setopts(@options)
end

#power_schedules ⇒ Object



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

def power_schedules
  Morpheus::PowerSchedulesInterface.new(common_interface_options).setopts(@options)
end

#price_sets ⇒ Object



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

def price_sets
  Morpheus::PriceSetsInterface.new(common_interface_options).setopts(@options)
end

#prices ⇒ Object



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

def prices
  Morpheus::PricesInterface.new(common_interface_options).setopts(@options)
end

#processes ⇒ Object



784
785
786
# File 'lib/morpheus/api/api_client.rb', line 784

def processes
  Morpheus::ProcessesInterface.new(common_interface_options).setopts(@options)
end

#projects ⇒ Object



836
837
838
# File 'lib/morpheus/api/api_client.rb', line 836

def projects
  Morpheus::ProjectsInterface.new(common_interface_options).setopts(@options)
end

#provision_types ⇒ Object



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

def provision_types
  Morpheus::ProvisionTypesInterface.new(common_interface_options).setopts(@options)
end

#provisioning_license_types ⇒ Object



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

def provisioning_license_types
  Morpheus::ProvisioningLicenseTypesInterface.new(common_interface_options).setopts(@options)
end

#provisioning_licenses ⇒ Object



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

def provisioning_licenses
  Morpheus::ProvisioningLicensesInterface.new(common_interface_options).setopts(@options)
end

#provisioning_settings ⇒ Object



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

def provisioning_settings
  Morpheus::ProvisioningSettingsInterface.new(common_interface_options).setopts(@options)
end

#reports ⇒ Object



788
789
790
# File 'lib/morpheus/api/api_client.rb', line 788

def reports
  Morpheus::ReportsInterface.new(common_interface_options).setopts(@options)
end

#rest(endpoint) ⇒ Object



940
941
942
# File 'lib/morpheus/api/api_client.rb', line 940

def rest(endpoint)
  Morpheus::RestInterface.new(common_interface_options).setopts(@options.merge({base_path: "#{@base_url}/api/#{endpoint}"}))
end

#roles ⇒ Object



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

def roles
  Morpheus::RolesInterface.new(common_interface_options).setopts(@options)
end

#scale_thresholds ⇒ Object



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

def scale_thresholds
  Morpheus::ScaleThresholdsInterface.new(common_interface_options).setopts(@options)
end

#search ⇒ Object



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

def search
  Morpheus::SearchInterface.new(common_interface_options).setopts(@options)
end

#security_group_rules ⇒ Object



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

def security_group_rules
  Morpheus::SecurityGroupRulesInterface.new(common_interface_options).setopts(@options)
end

#security_groups ⇒ Object



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

def security_groups
  Morpheus::SecurityGroupsInterface.new(common_interface_options).setopts(@options)
end

#security_package_types ⇒ Object



932
933
934
# File 'lib/morpheus/api/api_client.rb', line 932

def security_package_types
  Morpheus::SecurityPackageTypesInterface.new(common_interface_options).setopts(@options)
end

#security_packages ⇒ Object



928
929
930
# File 'lib/morpheus/api/api_client.rb', line 928

def security_packages
  Morpheus::SecurityPackagesInterface.new(common_interface_options).setopts(@options)
end

#security_scans ⇒ Object



936
937
938
# File 'lib/morpheus/api/api_client.rb', line 936

def security_scans
  Morpheus::SecurityScansInterface.new(common_interface_options).setopts(@options)
end

#server_types ⇒ Object



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

def server_types
  Morpheus::ServerTypesInterface.new(common_interface_options).setopts(@options)
end

#servers ⇒ Object



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

def servers
  Morpheus::ServersInterface.new(common_interface_options).setopts(@options)
end

#service_plans ⇒ Object



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

def service_plans
  Morpheus::ServicePlansInterface.new(common_interface_options).setopts(@options)
end

#set_ssl_verification_enabled(val) ⇒ Object



75
76
77
# File 'lib/morpheus/api/api_client.rb', line 75

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



114
115
116
117
118
119
120
# File 'lib/morpheus/api/api_client.rb', line 114

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

#setup ⇒ Object



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

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

#snapshots ⇒ Object



912
913
914
# File 'lib/morpheus/api/api_client.rb', line 912

def snapshots
  Morpheus::SnapshotsInterface.new(common_interface_options).setopts(@options)
end

#ssl_verification_enabled? ⇒ Boolean

Returns:

  • (Boolean)


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

def ssl_verification_enabled?
  @verify_ssl
end

#storage_providers ⇒ Object



704
705
706
# File 'lib/morpheus/api/api_client.rb', line 704

def storage_providers
  Morpheus::StorageProvidersInterface.new(common_interface_options).setopts(@options)
end

#storage_server_types ⇒ Object



712
713
714
# File 'lib/morpheus/api/api_client.rb', line 712

def storage_server_types
  Morpheus::StorageServerTypesInterface.new(common_interface_options).setopts(@options)
end

#storage_servers ⇒ Object



708
709
710
# File 'lib/morpheus/api/api_client.rb', line 708

def storage_servers
  Morpheus::StorageServersInterface.new(common_interface_options).setopts(@options)
end

#storage_volume_types ⇒ Object



720
721
722
# File 'lib/morpheus/api/api_client.rb', line 720

def storage_volume_types
  Morpheus::StorageVolumeTypesInterface.new(common_interface_options).setopts(@options)
end

#storage_volumes ⇒ Object



716
717
718
# File 'lib/morpheus/api/api_client.rb', line 716

def storage_volumes
  Morpheus::StorageVolumesInterface.new(common_interface_options).setopts(@options)
end

#subnet_types ⇒ Object



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

def subnet_types
  Morpheus::SubnetTypesInterface.new(common_interface_options).setopts(@options)
end

#subnets ⇒ Object



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

def subnets
  Morpheus::SubnetsInterface.new(common_interface_options).setopts(@options)
end

#task_sets ⇒ Object



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

def task_sets
  Morpheus::TaskSetsInterface.new(common_interface_options).setopts(@options)
end

#tasks ⇒ Object



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

def tasks
  Morpheus::TasksInterface.new(common_interface_options).setopts(@options)
end

#to_s ⇒ Object



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

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

#url ⇒ Object



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

def url
  @base_url
end

#usage ⇒ Object



864
865
866
# File 'lib/morpheus/api/api_client.rb', line 864

def usage
  Morpheus::UsageInterface.new(common_interface_options).setopts(@options)
end

#use_refresh_token(t = nil) ⇒ Object



302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/morpheus/api/api_client.rb', line 302

def use_refresh_token(t=nil)
  if t.nil?
    t = @refresh_token
  end
  if t.nil?
    raise "#{self.class} does not currently have a refresh_token"
  end
  response = auth.use_refresh_token(t, 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

#user_groups ⇒ Object



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

def user_groups
  Morpheus::UserGroupsInterface.new(common_interface_options).setopts(@options)
end

#user_settings ⇒ Object



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

def 
  Morpheus::UserSettingsInterface.new(common_interface_options).setopts(@options)
end

#user_sources ⇒ Object



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

def user_sources
  Morpheus::UserSourcesInterface.new(common_interface_options).setopts(@options)
end

#users ⇒ Object



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

def users
  Morpheus::UsersInterface.new(common_interface_options).setopts(@options)
end

#vdi ⇒ Object



872
873
874
# File 'lib/morpheus/api/api_client.rb', line 872

def vdi
  Morpheus::VdiInterface.new(common_interface_options).setopts(@options)
end

#vdi_allocations ⇒ Object



880
881
882
# File 'lib/morpheus/api/api_client.rb', line 880

def vdi_allocations
  Morpheus::VdiAllocationsInterface.new(common_interface_options).setopts(@options)
end

#vdi_apps ⇒ Object



884
885
886
# File 'lib/morpheus/api/api_client.rb', line 884

def vdi_apps
  Morpheus::VdiAppsInterface.new(common_interface_options).setopts(@options)
end

#vdi_gateways ⇒ Object



888
889
890
# File 'lib/morpheus/api/api_client.rb', line 888

def vdi_gateways
  Morpheus::VdiGatewaysInterface.new(common_interface_options).setopts(@options)
end

#vdi_pools ⇒ Object



876
877
878
# File 'lib/morpheus/api/api_client.rb', line 876

def vdi_pools
  Morpheus::VdiPoolsInterface.new(common_interface_options).setopts(@options)
end

#virtual_images ⇒ Object



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

def virtual_images
  Morpheus::VirtualImagesInterface.new(common_interface_options).setopts(@options)
end

#whitelabel_settings ⇒ Object



804
805
806
# File 'lib/morpheus/api/api_client.rb', line 804

def whitelabel_settings
  Morpheus::WhitelabelSettingsInterface.new(common_interface_options).setopts(@options)
end

#whoami ⇒ Object



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

def whoami
  Morpheus::WhoamiInterface.new(common_interface_options).setopts(@options)
end

#wiki ⇒ Object



808
809
810
# File 'lib/morpheus/api/api_client.rb', line 808

def wiki
  Morpheus::WikiInterface.new(common_interface_options).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({})



126
127
128
129
130
131
132
133
134
135
# File 'lib/morpheus/api/api_client.rb', line 126

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