Class: Morpheus::APIClient
- Inherits:
-
Object
- Object
- Morpheus::APIClient
- 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, 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
-
#client_id ⇒ Object
Returns the value of attribute client_id.
Instance Method Summary collapse
- #account_groups ⇒ Object
- #account_users ⇒ Object
- #accounts ⇒ Object
- #activity ⇒ Object
- #appliance_settings ⇒ Object
- #approvals ⇒ Object
- #apps ⇒ Object
- #archive_buckets ⇒ Object
- #archive_files ⇒ Object
- #audit ⇒ Object
- #auth ⇒ Object
-
#authorization_required? ⇒ Boolean
Authorization is required, except for a couple commands like Ping and Setup.
- #backup_jobs ⇒ Object
- #backup_settings ⇒ Object
- #backups ⇒ Object
- #billing ⇒ Object
- #blueprints ⇒ Object
- #budgets ⇒ Object
- #catalog ⇒ Object
- #catalog_item_types ⇒ Object
- #certificate_types ⇒ Object
- #certificates ⇒ Object
- #cloud_datastores ⇒ Object
- #cloud_folders ⇒ Object
- #cloud_policies ⇒ Object
- #cloud_resource_pools ⇒ Object
- #clouds ⇒ Object
- #clusters ⇒ Object
- #common_interface_options ⇒ Object
- #containers ⇒ Object
- #credential_types ⇒ Object
- #credentials ⇒ Object
- #cypher ⇒ Object
- #dashboard ⇒ Object
- #datastores ⇒ Object
-
#default_content_type ⇒ Object
set this in your interface, eg.
-
#default_timeout ⇒ Object
set default seconds for interface to timeout after or let it use system default? none, it should not timeout by default..
- #deploy ⇒ Object
- #deployments ⇒ Object
- #doc ⇒ Object
- #dry ⇒ Object
- #dry_run(val = true) ⇒ Object
- #environments ⇒ Object
-
#execute(opts, options = {}) ⇒ Object
Execute an HTTP request with this client.
- #execute_schedules ⇒ Object
- #execution_request ⇒ Object
- #file_copy_request ⇒ Object
- #forgot ⇒ Object
- #group_policies ⇒ Object
- #groups ⇒ Object
- #guidance ⇒ Object
- #health ⇒ Object
- #image_builder ⇒ Object
-
#initialize(access_token, refresh_token = nil, expires_in = nil, base_url = nil, verify_ssl = true, options = {}) ⇒ APIClient
constructor
Initialize a new APIClient client = APIClient.new(url:“morpheus.yourcompany.com”, verify_ssl:false) This old method signature is being deprecated: client = APIClient.new(access_token, refresh_token, expires_in, base_url, verify_ssl, options={}).
- #inspect ⇒ Object
- #instance_types ⇒ Object
- #instances ⇒ Object
- #integration_types ⇒ Object
- #integrations ⇒ Object
- #interface(type) ⇒ Object (also: #get_interface)
- #invoice_line_items ⇒ Object
- #invoices ⇒ Object
- #jobs ⇒ Object
- #key_pairs ⇒ Object
- #library_cluster_layouts ⇒ Object
- #library_container_scripts ⇒ Object
- #library_container_templates ⇒ Object
- #library_container_types ⇒ Object
- #library_container_upgrades ⇒ Object
- #library_instance_types ⇒ Object
- #library_layouts ⇒ Object
- #library_spec_template_types ⇒ Object
- #library_spec_templates ⇒ Object
- #license ⇒ Object
- #load_balancer_monitors ⇒ Object
- #load_balancer_pools ⇒ Object
- #load_balancer_profiles ⇒ Object
- #load_balancer_types ⇒ Object
- #load_balancer_virtual_servers ⇒ Object
- #load_balancers ⇒ Object
- #log_settings ⇒ Object
- #logged_in? ⇒ Boolean
- #login(username, password, use_client_id = nil) ⇒ Object
- #logout ⇒ Object
- #logs ⇒ Object
- #monitoring ⇒ Object
- #network_dhcp_relays ⇒ Object
- #network_dhcp_servers ⇒ Object
- #network_domain_records ⇒ Object
- #network_domains ⇒ Object
- #network_edge_clusters ⇒ Object
- #network_groups ⇒ Object
- #network_pool_ips ⇒ Object
- #network_pool_servers ⇒ Object
- #network_pools ⇒ Object
- #network_proxies ⇒ Object
- #network_routers ⇒ Object
- #network_security_servers ⇒ Object
- #network_servers ⇒ Object
- #network_services ⇒ Object
- #network_static_routes ⇒ Object
- #network_types ⇒ Object
- #networks ⇒ Object
- #old_cypher ⇒ Object
- #option_type_lists ⇒ Object
- #option_types ⇒ Object
- #options ⇒ Object
- #packages ⇒ Object
- #ping ⇒ Object
-
#policies ⇒ Object
def incidents # Morpheus::MonitoringIncidentsInterface.new(common_interface_options).setopts(@options) monitoring.incidents end.
- #power_schedules ⇒ Object
- #price_sets ⇒ Object
- #prices ⇒ Object
- #processes ⇒ Object
- #projects ⇒ Object
- #provision_types ⇒ Object
- #provisioning_license_types ⇒ Object
- #provisioning_licenses ⇒ Object
- #provisioning_settings ⇒ Object
- #reports ⇒ Object
- #rest(endpoint) ⇒ Object
- #roles ⇒ Object
- #search ⇒ Object
- #security_group_rules ⇒ Object
- #security_groups ⇒ Object
- #server_types ⇒ Object
- #servers ⇒ Object
- #service_plans ⇒ Object
- #set_ssl_verification_enabled(val) ⇒ Object
-
#setopts(new_options) ⇒ Object
(also: #set_options)
set common global @options for use with all requests meant for inline use just like dry(), set_options(dry_run:true) can be used in place of dry() Example: Prints curl -XGET …/whoami -H “Bearer” instead of actually request APIClient.new(token).whoami.setopts(curl:true).get({}).
- #setup ⇒ Object
- #snapshots ⇒ Object
- #ssl_verification_enabled? ⇒ Boolean
- #storage_providers ⇒ Object
- #storage_server_types ⇒ Object
- #storage_servers ⇒ Object
- #storage_volume_types ⇒ Object
- #storage_volumes ⇒ Object
- #subnet_types ⇒ Object
- #subnets ⇒ Object
- #task_sets ⇒ Object
- #tasks ⇒ Object
- #to_s ⇒ Object
- #url ⇒ Object
- #usage ⇒ Object
- #use_refresh_token(t = nil) ⇒ Object
- #user_groups ⇒ Object
- #user_settings ⇒ Object
- #user_sources ⇒ Object
- #users ⇒ Object
- #vdi ⇒ Object
- #vdi_allocations ⇒ Object
- #vdi_apps ⇒ Object
- #vdi_gateways ⇒ Object
- #vdi_pools ⇒ Object
- #virtual_images ⇒ Object
- #whitelabel_settings ⇒ Object
- #whoami ⇒ Object
- #wiki ⇒ Object
-
#withopts(tmp_options, &block) ⇒ Object
(also: #with_options)
with_options sets common global @options for the duration of the block only then returns the options to their prior values.
Constructor Details
#initialize(access_token, refresh_token = nil, expires_in = nil, base_url = nil, verify_ssl = true, options = {}) ⇒ APIClient
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 46 47 |
# File 'lib/morpheus/api/api_client.rb', line 18 def initialize(access_token, refresh_token=nil,expires_in = nil, base_url=nil, verify_ssl=true, ={}) 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 = 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() end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
11 12 13 |
# File 'lib/morpheus/api/api_client.rb', line 11 def client_id @client_id end |
Instance Method Details
#account_groups ⇒ Object
385 386 387 |
# File 'lib/morpheus/api/api_client.rb', line 385 def account_groups Morpheus::AccountGroupsInterface.new().setopts(@options) end |
#account_users ⇒ Object
549 550 551 |
# File 'lib/morpheus/api/api_client.rb', line 549 def account_users Morpheus::AccountUsersInterface.new().setopts(@options) end |
#accounts ⇒ Object
537 538 539 |
# File 'lib/morpheus/api/api_client.rb', line 537 def accounts Morpheus::AccountsInterface.new().setopts(@options) end |
#activity ⇒ Object
373 374 375 |
# File 'lib/morpheus/api/api_client.rb', line 373 def activity Morpheus::ActivityInterface.new().setopts(@options) end |
#appliance_settings ⇒ Object
417 418 419 |
# File 'lib/morpheus/api/api_client.rb', line 417 def appliance_settings Morpheus::ApplianceSettingsInterface.new().setopts(@options) end |
#approvals ⇒ Object
541 542 543 |
# File 'lib/morpheus/api/api_client.rb', line 541 def approvals Morpheus::ApprovalsInterface.new().setopts(@options) end |
#apps ⇒ Object
509 510 511 |
# File 'lib/morpheus/api/api_client.rb', line 509 def apps Morpheus::AppsInterface.new().setopts(@options) end |
#archive_buckets ⇒ Object
683 684 685 |
# File 'lib/morpheus/api/api_client.rb', line 683 def archive_buckets Morpheus::ArchiveBucketsInterface.new().setopts(@options) end |
#archive_files ⇒ Object
687 688 689 |
# File 'lib/morpheus/api/api_client.rb', line 687 def archive_files Morpheus::ArchiveFilesInterface.new().setopts(@options) end |
#audit ⇒ Object
803 804 805 |
# File 'lib/morpheus/api/api_client.rb', line 803 def audit Morpheus::AuditInterface.new().setopts(@options) end |
#auth ⇒ Object
349 350 351 |
# File 'lib/morpheus/api/api_client.rb', line 349 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
93 94 95 |
# File 'lib/morpheus/api/api_client.rb', line 93 def true end |
#backup_jobs ⇒ Object
831 832 833 |
# File 'lib/morpheus/api/api_client.rb', line 831 def backup_jobs Morpheus::BackupJobsInterface.new().setopts(@options) end |
#backup_settings ⇒ Object
783 784 785 |
# File 'lib/morpheus/api/api_client.rb', line 783 def backup_settings Morpheus::BackupSettingsInterface.new().setopts(@options) end |
#backups ⇒ Object
827 828 829 |
# File 'lib/morpheus/api/api_client.rb', line 827 def backups Morpheus::BackupsInterface.new().setopts(@options) end |
#billing ⇒ Object
847 848 849 |
# File 'lib/morpheus/api/api_client.rb', line 847 def billing Morpheus::BillingInterface.new().setopts(@options) end |
#blueprints ⇒ Object
513 514 515 |
# File 'lib/morpheus/api/api_client.rb', line 513 def blueprints Morpheus::BlueprintsInterface.new().setopts(@options) end |
#budgets ⇒ Object
807 808 809 |
# File 'lib/morpheus/api/api_client.rb', line 807 def budgets Morpheus::BudgetsInterface.new().setopts(@options) end |
#catalog ⇒ Object
839 840 841 |
# File 'lib/morpheus/api/api_client.rb', line 839 def catalog Morpheus::ServiceCatalogInterface.new().setopts(@options) end |
#catalog_item_types ⇒ Object
835 836 837 |
# File 'lib/morpheus/api/api_client.rb', line 835 def catalog_item_types Morpheus::CatalogItemTypesInterface.new().setopts(@options) end |
#certificate_types ⇒ Object
577 578 579 |
# File 'lib/morpheus/api/api_client.rb', line 577 def certificate_types Morpheus::CertificateTypesInterface.new().setopts(@options) end |
#certificates ⇒ Object
573 574 575 |
# File 'lib/morpheus/api/api_client.rb', line 573 def certificates Morpheus::CertificatesInterface.new().setopts(@options) end |
#cloud_datastores ⇒ Object
393 394 395 |
# File 'lib/morpheus/api/api_client.rb', line 393 def cloud_datastores Morpheus::CloudDatastoresInterface.new().setopts(@options) end |
#cloud_folders ⇒ Object
401 402 403 |
# File 'lib/morpheus/api/api_client.rb', line 401 def cloud_folders Morpheus::CloudFoldersInterface.new().setopts(@options) end |
#cloud_policies ⇒ Object
623 624 625 |
# File 'lib/morpheus/api/api_client.rb', line 623 def cloud_policies Morpheus::CloudPoliciesInterface.new().setopts(@options) end |
#cloud_resource_pools ⇒ Object
397 398 399 |
# File 'lib/morpheus/api/api_client.rb', line 397 def cloud_resource_pools Morpheus::CloudResourcePoolsInterface.new().setopts(@options) end |
#clouds ⇒ Object
389 390 391 |
# File 'lib/morpheus/api/api_client.rb', line 389 def clouds Morpheus::CloudsInterface.new().setopts(@options) end |
#clusters ⇒ Object
533 534 535 |
# File 'lib/morpheus/api/api_client.rb', line 533 def clusters Morpheus::ClustersInterface.new().setopts(@options) end |
#common_interface_options ⇒ Object
326 327 328 329 330 331 332 333 334 335 |
# File 'lib/morpheus/api/api_client.rb', line 326 def { 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
433 434 435 |
# File 'lib/morpheus/api/api_client.rb', line 433 def containers Morpheus::ContainersInterface.new().setopts(@options) end |
#credential_types ⇒ Object
899 900 901 |
# File 'lib/morpheus/api/api_client.rb', line 899 def credential_types Morpheus::CredentialTypesInterface.new().setopts(@options) end |
#credentials ⇒ Object
895 896 897 |
# File 'lib/morpheus/api/api_client.rb', line 895 def credentials Morpheus::CredentialsInterface.new().setopts(@options) end |
#cypher ⇒ Object
755 756 757 |
# File 'lib/morpheus/api/api_client.rb', line 755 def cypher Morpheus::CypherInterface.new().setopts(@options) end |
#dashboard ⇒ Object
369 370 371 |
# File 'lib/morpheus/api/api_client.rb', line 369 def dashboard Morpheus::DashboardInterface.new().setopts(@options) end |
#datastores ⇒ Object
405 406 407 |
# File 'lib/morpheus/api/api_client.rb', line 405 def datastores Morpheus::DatastoresInterface.new().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.
80 81 82 |
# File 'lib/morpheus/api/api_client.rb', line 80 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
88 89 90 |
# File 'lib/morpheus/api/api_client.rb', line 88 def default_timeout nil end |
#deploy ⇒ Object
517 518 519 |
# File 'lib/morpheus/api/api_client.rb', line 517 def deploy Morpheus::DeployInterface.new().setopts(@options) end |
#deployments ⇒ Object
521 522 523 |
# File 'lib/morpheus/api/api_client.rb', line 521 def deployments Morpheus::DeploymentsInterface.new().setopts(@options) end |
#doc ⇒ Object
337 338 339 |
# File 'lib/morpheus/api/api_client.rb', line 337 def doc Morpheus::DocInterface.new().setopts(@options) end |
#dry ⇒ Object
66 67 68 |
# File 'lib/morpheus/api/api_client.rb', line 66 def dry() dry_run(true) end |
#dry_run(val = true) ⇒ Object
61 62 63 64 |
# File 'lib/morpheus/api/api_client.rb', line 61 def dry_run(val=true) @dry_run = !!val self end |
#environments ⇒ Object
779 780 781 |
# File 'lib/morpheus/api/api_client.rb', line 779 def environments Morpheus::EnvironmentsInterface.new().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
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 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 |
# File 'lib/morpheus/api/api_client.rb', line 150 def execute(opts, ={}) # 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 = .merge(@options) else = .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 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 [:timeout] opts[:timeout] = [: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 [:headers] opts[:headers] = opts[:headers].merge([: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] = # 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 && [:parse_json] != false return JSON.parse(response.to_s) else return response end end |
#execute_schedules ⇒ Object
597 598 599 |
# File 'lib/morpheus/api/api_client.rb', line 597 def execute_schedules Morpheus::ExecuteSchedulesInterface.new().setopts(@options) end |
#execution_request ⇒ Object
763 764 765 |
# File 'lib/morpheus/api/api_client.rb', line 763 def execution_request Morpheus::ExecutionRequestInterface.new().setopts(@options) end |
#file_copy_request ⇒ Object
767 768 769 |
# File 'lib/morpheus/api/api_client.rb', line 767 def file_copy_request Morpheus::FileCopyRequestInterface.new().setopts(@options) end |
#forgot ⇒ Object
353 354 355 |
# File 'lib/morpheus/api/api_client.rb', line 353 def forgot Morpheus::ForgotPasswordInterface.new().setopts(@options) end |
#group_policies ⇒ Object
619 620 621 |
# File 'lib/morpheus/api/api_client.rb', line 619 def group_policies Morpheus::GroupPoliciesInterface.new().setopts(@options) end |
#groups ⇒ Object
381 382 383 |
# File 'lib/morpheus/api/api_client.rb', line 381 def groups Morpheus::GroupsInterface.new().setopts(@options) end |
#guidance ⇒ Object
819 820 821 |
# File 'lib/morpheus/api/api_client.rb', line 819 def guidance Morpheus::GuidanceInterface.new().setopts(@options) end |
#health ⇒ Object
799 800 801 |
# File 'lib/morpheus/api/api_client.rb', line 799 def health Morpheus::HealthInterface.new().setopts(@options) end |
#image_builder ⇒ Object
691 692 693 |
# File 'lib/morpheus/api/api_client.rb', line 691 def image_builder Morpheus::ImageBuilderInterface.new().setopts(@options) end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/morpheus/api/api_client.rb', line 57 def inspect to_s end |
#instance_types ⇒ Object
437 438 439 |
# File 'lib/morpheus/api/api_client.rb', line 437 def instance_types Morpheus::InstanceTypesInterface.new().setopts(@options) end |
#instances ⇒ Object
413 414 415 |
# File 'lib/morpheus/api/api_client.rb', line 413 def instances Morpheus::InstancesInterface.new().setopts(@options) end |
#integration_types ⇒ Object
445 446 447 |
# File 'lib/morpheus/api/api_client.rb', line 445 def integration_types Morpheus::IntegrationTypesInterface.new().setopts(@options) end |
#integrations ⇒ Object
441 442 443 |
# File 'lib/morpheus/api/api_client.rb', line 441 def integrations Morpheus::IntegrationsInterface.new().setopts(@options) end |
#interface(type) ⇒ Object Also known as: get_interface
907 908 909 910 911 912 913 914 |
# File 'lib/morpheus/api/api_client.rb', line 907 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
815 816 817 |
# File 'lib/morpheus/api/api_client.rb', line 815 def invoice_line_items Morpheus::InvoiceLineItemsInterface.new().setopts(@options) end |
#invoices ⇒ Object
811 812 813 |
# File 'lib/morpheus/api/api_client.rb', line 811 def invoices Morpheus::InvoicesInterface.new().setopts(@options) end |
#jobs ⇒ Object
449 450 451 |
# File 'lib/morpheus/api/api_client.rb', line 449 def jobs Morpheus::JobsInterface.new().setopts(@options) end |
#key_pairs ⇒ Object
569 570 571 |
# File 'lib/morpheus/api/api_client.rb', line 569 def key_pairs Morpheus::KeyPairsInterface.new().setopts(@options) end |
#library_cluster_layouts ⇒ Object
739 740 741 |
# File 'lib/morpheus/api/api_client.rb', line 739 def library_cluster_layouts Morpheus::LibraryClusterLayoutsInterface.new().setopts(@options) end |
#library_container_scripts ⇒ Object
731 732 733 |
# File 'lib/morpheus/api/api_client.rb', line 731 def library_container_scripts Morpheus::LibraryContainerScriptsInterface.new().setopts(@options) end |
#library_container_templates ⇒ Object
735 736 737 |
# File 'lib/morpheus/api/api_client.rb', line 735 def library_container_templates Morpheus::LibraryContainerTemplatesInterface.new().setopts(@options) end |
#library_container_types ⇒ Object
727 728 729 |
# File 'lib/morpheus/api/api_client.rb', line 727 def library_container_types Morpheus::LibraryContainerTypesInterface.new().setopts(@options) end |
#library_container_upgrades ⇒ Object
723 724 725 |
# File 'lib/morpheus/api/api_client.rb', line 723 def library_container_upgrades Morpheus::LibraryContainerUpgradesInterface.new().setopts(@options) end |
#library_instance_types ⇒ Object
715 716 717 |
# File 'lib/morpheus/api/api_client.rb', line 715 def library_instance_types Morpheus::LibraryInstanceTypesInterface.new().setopts(@options) end |
#library_layouts ⇒ Object
719 720 721 |
# File 'lib/morpheus/api/api_client.rb', line 719 def library_layouts Morpheus::LibraryLayoutsInterface.new().setopts(@options) end |
#library_spec_template_types ⇒ Object
747 748 749 |
# File 'lib/morpheus/api/api_client.rb', line 747 def library_spec_template_types Morpheus::LibrarySpecTemplateTypesInterface.new().setopts(@options) end |
#library_spec_templates ⇒ Object
743 744 745 |
# File 'lib/morpheus/api/api_client.rb', line 743 def library_spec_templates Morpheus::LibrarySpecTemplatesInterface.new().setopts(@options) end |
#license ⇒ Object
581 582 583 |
# File 'lib/morpheus/api/api_client.rb', line 581 def license Morpheus::LicenseInterface.new().setopts(@options) end |
#load_balancer_monitors ⇒ Object
493 494 495 |
# File 'lib/morpheus/api/api_client.rb', line 493 def load_balancer_monitors Morpheus::LoadBalancerMonitorsInterface.new().setopts(@options) end |
#load_balancer_pools ⇒ Object
485 486 487 |
# File 'lib/morpheus/api/api_client.rb', line 485 def load_balancer_pools Morpheus::LoadBalancerPoolsInterface.new().setopts(@options) end |
#load_balancer_profiles ⇒ Object
489 490 491 |
# File 'lib/morpheus/api/api_client.rb', line 489 def load_balancer_profiles Morpheus::LoadBalancerProfilesInterface.new().setopts(@options) end |
#load_balancer_types ⇒ Object
477 478 479 |
# File 'lib/morpheus/api/api_client.rb', line 477 def load_balancer_types Morpheus::LoadBalancerTypesInterface.new().setopts(@options) end |
#load_balancer_virtual_servers ⇒ Object
481 482 483 |
# File 'lib/morpheus/api/api_client.rb', line 481 def load_balancer_virtual_servers Morpheus::LoadBalancerVirtualServersInterface.new().setopts(@options) end |
#load_balancers ⇒ Object
473 474 475 |
# File 'lib/morpheus/api/api_client.rb', line 473 def load_balancers Morpheus::LoadBalancersInterface.new().setopts(@options) end |
#log_settings ⇒ Object
787 788 789 |
# File 'lib/morpheus/api/api_client.rb', line 787 def log_settings Morpheus::LogSettingsInterface.new().setopts(@options) end |
#logged_in? ⇒ Boolean
274 275 276 |
# File 'lib/morpheus/api/api_client.rb', line 274 def logged_in? !!@access_token end |
#login(username, password, use_client_id = nil) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/morpheus/api/api_client.rb', line 286 def login(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.login(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
319 320 321 322 323 324 |
# File 'lib/morpheus/api/api_client.rb', line 319 def logout @access_token = nil @refresh_token = nil @expires_at = nil return self end |
#logs ⇒ Object
561 562 563 |
# File 'lib/morpheus/api/api_client.rb', line 561 def logs Morpheus::LogsInterface.new().setopts(@options) end |
#monitoring ⇒ Object
601 602 603 |
# File 'lib/morpheus/api/api_client.rb', line 601 def monitoring Morpheus::MonitoringInterface.new().setopts(@options) end |
#network_dhcp_relays ⇒ Object
883 884 885 |
# File 'lib/morpheus/api/api_client.rb', line 883 def network_dhcp_relays Morpheus::NetworkDhcpRelaysInterface.new().setopts(@options) end |
#network_dhcp_servers ⇒ Object
879 880 881 |
# File 'lib/morpheus/api/api_client.rb', line 879 def network_dhcp_servers Morpheus::NetworkDhcpServersInterface.new().setopts(@options) end |
#network_domain_records ⇒ Object
675 676 677 |
# File 'lib/morpheus/api/api_client.rb', line 675 def network_domain_records Morpheus::NetworkDomainRecordsInterface.new().setopts(@options) end |
#network_domains ⇒ Object
671 672 673 |
# File 'lib/morpheus/api/api_client.rb', line 671 def network_domains Morpheus::NetworkDomainsInterface.new().setopts(@options) end |
#network_edge_clusters ⇒ Object
875 876 877 |
# File 'lib/morpheus/api/api_client.rb', line 875 def network_edge_clusters Morpheus::NetworkEdgeClustersInterface.new().setopts(@options) end |
#network_groups ⇒ Object
643 644 645 |
# File 'lib/morpheus/api/api_client.rb', line 643 def network_groups Morpheus::NetworkGroupsInterface.new().setopts(@options) end |
#network_pool_ips ⇒ Object
651 652 653 |
# File 'lib/morpheus/api/api_client.rb', line 651 def network_pool_ips Morpheus::NetworkPoolIpsInterface.new().setopts(@options) end |
#network_pool_servers ⇒ Object
667 668 669 |
# File 'lib/morpheus/api/api_client.rb', line 667 def network_pool_servers Morpheus::NetworkPoolServersInterface.new().setopts(@options) end |
#network_pools ⇒ Object
647 648 649 |
# File 'lib/morpheus/api/api_client.rb', line 647 def network_pools Morpheus::NetworkPoolsInterface.new().setopts(@options) end |
#network_proxies ⇒ Object
679 680 681 |
# File 'lib/morpheus/api/api_client.rb', line 679 def network_proxies Morpheus::NetworkProxiesInterface.new().setopts(@options) end |
#network_routers ⇒ Object
655 656 657 |
# File 'lib/morpheus/api/api_client.rb', line 655 def network_routers Morpheus::NetworkRoutersInterface.new().setopts(@options) end |
#network_security_servers ⇒ Object
663 664 665 |
# File 'lib/morpheus/api/api_client.rb', line 663 def network_security_servers Morpheus::NetworkSecurityServersInterface.new().setopts(@options) end |
#network_servers ⇒ Object
871 872 873 |
# File 'lib/morpheus/api/api_client.rb', line 871 def network_servers Morpheus::NetworkServersInterface.new().setopts(@options) end |
#network_services ⇒ Object
659 660 661 |
# File 'lib/morpheus/api/api_client.rb', line 659 def network_services Morpheus::NetworkServicesInterface.new().setopts(@options) end |
#network_static_routes ⇒ Object
887 888 889 |
# File 'lib/morpheus/api/api_client.rb', line 887 def network_static_routes Morpheus::NetworkStaticRoutesInterface.new().setopts(@options) end |
#network_types ⇒ Object
631 632 633 |
# File 'lib/morpheus/api/api_client.rb', line 631 def network_types Morpheus::NetworkTypesInterface.new().setopts(@options) end |
#networks ⇒ Object
627 628 629 |
# File 'lib/morpheus/api/api_client.rb', line 627 def networks Morpheus::NetworksInterface.new().setopts(@options) end |
#old_cypher ⇒ Object
759 760 761 |
# File 'lib/morpheus/api/api_client.rb', line 759 def old_cypher Morpheus::OldCypherInterface.new().setopts(@options) end |
#option_type_lists ⇒ Object
589 590 591 |
# File 'lib/morpheus/api/api_client.rb', line 589 def option_type_lists Morpheus::OptionTypeListsInterface.new().setopts(@options) end |
#option_types ⇒ Object
585 586 587 |
# File 'lib/morpheus/api/api_client.rb', line 585 def option_types Morpheus::OptionTypesInterface.new().setopts(@options) end |
#options ⇒ Object
377 378 379 |
# File 'lib/morpheus/api/api_client.rb', line 377 def Morpheus::OptionsInterface.new().setopts(@options) end |
#packages ⇒ Object
751 752 753 |
# File 'lib/morpheus/api/api_client.rb', line 751 def packages Morpheus::PackagesInterface.new().setopts(@options) end |
#ping ⇒ Object
341 342 343 |
# File 'lib/morpheus/api/api_client.rb', line 341 def ping Morpheus::PingInterface.new().setopts(@options) end |
#policies ⇒ Object
def incidents
# Morpheus::MonitoringIncidentsInterface.new(common_interface_options).setopts(@options)
monitoring.incidents
end
615 616 617 |
# File 'lib/morpheus/api/api_client.rb', line 615 def policies Morpheus::PoliciesInterface.new().setopts(@options) end |
#power_schedules ⇒ Object
593 594 595 |
# File 'lib/morpheus/api/api_client.rb', line 593 def power_schedules Morpheus::PowerSchedulesInterface.new().setopts(@options) end |
#price_sets ⇒ Object
465 466 467 |
# File 'lib/morpheus/api/api_client.rb', line 465 def price_sets Morpheus::PriceSetsInterface.new().setopts(@options) end |
#prices ⇒ Object
469 470 471 |
# File 'lib/morpheus/api/api_client.rb', line 469 def prices Morpheus::PricesInterface.new().setopts(@options) end |
#processes ⇒ Object
771 772 773 |
# File 'lib/morpheus/api/api_client.rb', line 771 def processes Morpheus::ProcessesInterface.new().setopts(@options) end |
#projects ⇒ Object
823 824 825 |
# File 'lib/morpheus/api/api_client.rb', line 823 def projects Morpheus::ProjectsInterface.new().setopts(@options) end |
#provision_types ⇒ Object
457 458 459 |
# File 'lib/morpheus/api/api_client.rb', line 457 def provision_types Morpheus::ProvisionTypesInterface.new().setopts(@options) end |
#provisioning_license_types ⇒ Object
429 430 431 |
# File 'lib/morpheus/api/api_client.rb', line 429 def provisioning_license_types Morpheus::ProvisioningLicenseTypesInterface.new().setopts(@options) end |
#provisioning_licenses ⇒ Object
425 426 427 |
# File 'lib/morpheus/api/api_client.rb', line 425 def provisioning_licenses Morpheus::ProvisioningLicensesInterface.new().setopts(@options) end |
#provisioning_settings ⇒ Object
421 422 423 |
# File 'lib/morpheus/api/api_client.rb', line 421 def provisioning_settings Morpheus::ProvisioningSettingsInterface.new().setopts(@options) end |
#reports ⇒ Object
775 776 777 |
# File 'lib/morpheus/api/api_client.rb', line 775 def reports Morpheus::ReportsInterface.new().setopts(@options) end |
#rest(endpoint) ⇒ Object
903 904 905 |
# File 'lib/morpheus/api/api_client.rb', line 903 def rest(endpoint) Morpheus::RestInterface.new().setopts(@options.merge({base_path: "#{@base_url}/api/#{endpoint}"})) end |
#roles ⇒ Object
565 566 567 |
# File 'lib/morpheus/api/api_client.rb', line 565 def roles Morpheus::RolesInterface.new().setopts(@options) end |
#search ⇒ Object
361 362 363 |
# File 'lib/morpheus/api/api_client.rb', line 361 def search Morpheus::SearchInterface.new().setopts(@options) end |
#security_group_rules ⇒ Object
529 530 531 |
# File 'lib/morpheus/api/api_client.rb', line 529 def security_group_rules Morpheus::SecurityGroupRulesInterface.new().setopts(@options) end |
#security_groups ⇒ Object
525 526 527 |
# File 'lib/morpheus/api/api_client.rb', line 525 def security_groups Morpheus::SecurityGroupsInterface.new().setopts(@options) end |
#server_types ⇒ Object
453 454 455 |
# File 'lib/morpheus/api/api_client.rb', line 453 def server_types Morpheus::ServerTypesInterface.new().setopts(@options) end |
#servers ⇒ Object
409 410 411 |
# File 'lib/morpheus/api/api_client.rb', line 409 def servers Morpheus::ServersInterface.new().setopts(@options) end |
#service_plans ⇒ Object
461 462 463 |
# File 'lib/morpheus/api/api_client.rb', line 461 def service_plans Morpheus::ServicePlansInterface.new().setopts(@options) end |
#set_ssl_verification_enabled(val) ⇒ Object
74 75 76 |
# File 'lib/morpheus/api/api_client.rb', line 74 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({})
113 114 115 116 117 118 119 |
# File 'lib/morpheus/api/api_client.rb', line 113 def setopts() @options = if @options[:dry_run] dry_run(true) end self end |
#setup ⇒ Object
345 346 347 |
# File 'lib/morpheus/api/api_client.rb', line 345 def setup Morpheus::SetupInterface.new().setopts(@options) end |
#snapshots ⇒ Object
891 892 893 |
# File 'lib/morpheus/api/api_client.rb', line 891 def snapshots Morpheus::SnapshotsInterface.new().setopts(@options) end |
#ssl_verification_enabled? ⇒ Boolean
70 71 72 |
# File 'lib/morpheus/api/api_client.rb', line 70 def ssl_verification_enabled? @verify_ssl end |
#storage_providers ⇒ Object
695 696 697 |
# File 'lib/morpheus/api/api_client.rb', line 695 def storage_providers Morpheus::StorageProvidersInterface.new().setopts(@options) end |
#storage_server_types ⇒ Object
703 704 705 |
# File 'lib/morpheus/api/api_client.rb', line 703 def storage_server_types Morpheus::StorageServerTypesInterface.new().setopts(@options) end |
#storage_servers ⇒ Object
699 700 701 |
# File 'lib/morpheus/api/api_client.rb', line 699 def storage_servers Morpheus::StorageServersInterface.new().setopts(@options) end |
#storage_volume_types ⇒ Object
711 712 713 |
# File 'lib/morpheus/api/api_client.rb', line 711 def storage_volume_types Morpheus::StorageVolumeTypesInterface.new().setopts(@options) end |
#storage_volumes ⇒ Object
707 708 709 |
# File 'lib/morpheus/api/api_client.rb', line 707 def storage_volumes Morpheus::StorageVolumesInterface.new().setopts(@options) end |
#subnet_types ⇒ Object
639 640 641 |
# File 'lib/morpheus/api/api_client.rb', line 639 def subnet_types Morpheus::SubnetTypesInterface.new().setopts(@options) end |
#subnets ⇒ Object
635 636 637 |
# File 'lib/morpheus/api/api_client.rb', line 635 def subnets Morpheus::SubnetsInterface.new().setopts(@options) end |
#task_sets ⇒ Object
501 502 503 |
# File 'lib/morpheus/api/api_client.rb', line 501 def task_sets Morpheus::TaskSetsInterface.new().setopts(@options) end |
#tasks ⇒ Object
497 498 499 |
# File 'lib/morpheus/api/api_client.rb', line 497 def tasks Morpheus::TasksInterface.new().setopts(@options) end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/morpheus/api/api_client.rb', line 53 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
49 50 51 |
# File 'lib/morpheus/api/api_client.rb', line 49 def url @base_url end |
#usage ⇒ Object
843 844 845 |
# File 'lib/morpheus/api/api_client.rb', line 843 def usage Morpheus::UsageInterface.new().setopts(@options) end |
#use_refresh_token(t = nil) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/morpheus/api/api_client.rb', line 301 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
553 554 555 |
# File 'lib/morpheus/api/api_client.rb', line 553 def user_groups Morpheus::UserGroupsInterface.new().setopts(@options) end |
#user_settings ⇒ Object
365 366 367 |
# File 'lib/morpheus/api/api_client.rb', line 365 def user_settings Morpheus::UserSettingsInterface.new().setopts(@options) end |
#user_sources ⇒ Object
557 558 559 |
# File 'lib/morpheus/api/api_client.rb', line 557 def user_sources Morpheus::UserSourcesInterface.new().setopts(@options) end |
#users ⇒ Object
545 546 547 |
# File 'lib/morpheus/api/api_client.rb', line 545 def users Morpheus::UsersInterface.new().setopts(@options) end |
#vdi ⇒ Object
851 852 853 |
# File 'lib/morpheus/api/api_client.rb', line 851 def vdi Morpheus::VdiInterface.new().setopts(@options) end |
#vdi_allocations ⇒ Object
859 860 861 |
# File 'lib/morpheus/api/api_client.rb', line 859 def vdi_allocations Morpheus::VdiAllocationsInterface.new().setopts(@options) end |
#vdi_apps ⇒ Object
863 864 865 |
# File 'lib/morpheus/api/api_client.rb', line 863 def vdi_apps Morpheus::VdiAppsInterface.new().setopts(@options) end |
#vdi_gateways ⇒ Object
867 868 869 |
# File 'lib/morpheus/api/api_client.rb', line 867 def vdi_gateways Morpheus::VdiGatewaysInterface.new().setopts(@options) end |
#vdi_pools ⇒ Object
855 856 857 |
# File 'lib/morpheus/api/api_client.rb', line 855 def vdi_pools Morpheus::VdiPoolsInterface.new().setopts(@options) end |
#virtual_images ⇒ Object
505 506 507 |
# File 'lib/morpheus/api/api_client.rb', line 505 def virtual_images Morpheus::VirtualImagesInterface.new().setopts(@options) end |
#whitelabel_settings ⇒ Object
791 792 793 |
# File 'lib/morpheus/api/api_client.rb', line 791 def whitelabel_settings Morpheus::WhitelabelSettingsInterface.new().setopts(@options) end |
#whoami ⇒ Object
357 358 359 |
# File 'lib/morpheus/api/api_client.rb', line 357 def whoami Morpheus::WhoamiInterface.new().setopts(@options) end |
#wiki ⇒ Object
795 796 797 |
# File 'lib/morpheus/api/api_client.rb', line 795 def wiki Morpheus::WikiInterface.new().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
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/morpheus/api/api_client.rb', line 125 def withopts(, &block) @_old_options = @options begin @options = result = block.call() ensure @options = @_old_options end return result end |