Object
The Mock Service allows you to run a fake instance of the Service which makes no real connections.
# File lib/fog/softlayer/compute.rb, line 87 def _request raise Fog::Errors::MockNotImplemented end
Launch a SoftLayer BMC server.
@param [Array<Hash>] opts @option opts [Array<Hash>] :body
HTTP request body parameters
@option opts [String] “hostname”
VM hostname, should be unique within the domain.
@option opts [String] “domain”
VM domain.
@option opts [Integer] “processorCoreAmount”
Number of CPU cores provisioned for the VM.
@option opts [Integer] “memoryCapacity”
Available RAM for the server in GB. Valid arguments are 1, 2, 4, 6, 8, 12, 16, 32, 48, 64
@option opts [Boolean] “hourlyBillingFlag”
Should the VM be billed hourly or monthly (monthly is less expensive, minimum charge of 1 month).
@option opts [Boolean] “localDiskFlag”
Should the root volume be on the machine or on the SAN
@option opts [String] “operatingSystemReferenceCode”
A valid SoftLayer operatingSystemReferenceCode string
@option opts [Boolean] “dedicatedAccountHostOnlyFlag”
Defaults to false, pass true for a single-tenant VM.
@return [Excon::Response]
# File lib/fog/softlayer/requests/compute/create_bare_metal_server.rb, line 35 def create_bare_metal_server(opts) raise ArgumentError, "Fog::Compute::Softlayer#create_bare_metal_server expects argument of type Hash" unless opts.kind_of?(Hash) response = Excon::Response.new required = %{hostname domain processorCoreAmount memoryCapacity hourlyBillingFlag operatingSystemReferenceCode} begin Fog::Softlayer.valid_request?(required, opts) or raise MissingRequiredParameter response.status = 201 # a real response comes back with lots of nil values like this too, it takes 1 - 2 hours for a real BMC server to provision response.body = { 'accountId' => Fog::Softlayer.mock_account_id, 'createDate' => Time.now.iso8601, 'dedicatedAccountHostOnlyFlag' => false, 'domain' => nil, 'fullyQualifiedDomainName' => nil, 'hostname' => nil, 'id' => Fog::Softlayer.mock_vm_id, 'lastPowerStateId' => nil, 'lastVerifiedDate' => nil, 'maxCpu' => nil, 'maxCpuUnits' => "CORE", 'maxMemory' => nil, 'metricPollDate' => nil, 'modifyDate' => nil, 'startCpus' => nil, 'statusId' => 1001, 'globalIdentifier' => Fog::Softlayer.mock_global_identifier } rescue MissingRequiredParameter response.status = 500 response.body = { "code" => "SoftLayer_Exception_MissingCreationProperty", "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Hardware'." } end @bare_metal_servers.push(response.body).flatten! response end
# File lib/fog/softlayer/requests/compute/create_key_pair.rb, line 13 def create_key_pair(opts) response = Excon::Response.new response.status = 200 response.body = [] response.body = { "createDate" => Time.now.iso8601, "fingerprint" => "1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a:1a", "id" => Fog::Mock.random_numbers(5).to_i, "key" => opts[:key], "label" => opts[:label], "modifyDate" => nil } @key_pairs.push(response.body) response end
Launch a single SoftLayer VM.
@param [<Hash>] opts @option opts [<Hash>] :body
HTTP request body parameters
@option opts [String] “hostname”
VM hostname, should be unique within the domain.
@option opts [String] “domain”
VM domain.
@option opts [Integer] “startCpus”
Number of CPU cores provisioned for the VM.
@option opts [Integer] “maxMemory”
Available RAM for the VM in MB. Valid arguments are 1024, 2048, 4096, 6144, 8192, 12288, 16384, 32768, 49152, 65536
@option opts [Boolean] “hourlyBillingFlag”
Should the VM be billed hourly or monthly (monthly is less expensive, minimum charge of 1 month).
@option opts [Boolean] “localDiskFlag”
Should the root volume be on the machine or on the SAN
@option opts [String] “operatingSystemReferenceCode”
A valid SoftLayer operatingSystemReferenceCode string
@option opts [Boolean] “dedicatedAccountHostOnlyFlag”
Defaults to false, pass true for a single-tenant VM.
@return [Excon::Response]
# File lib/fog/softlayer/requests/compute/create_vm.rb, line 35 def create_vm(opts) raise ArgumentError, "Fog::Compute::Softlayer#create_vm expects argument of type Hash" unless opts.kind_of?(Hash) opts = [opts] self.create_vms(opts) end
Launch one or more SoftLayer VMs.
@param [Array<Hash>] opts @option opts [Array<Hash>] :body
HTTP request body parameters
@option opts [String] “hostname”
VM hostname, should be unique within the domain.
@option opts [String] “domain”
VM domain.
@option opts [Integer] “startCpus”
Number of CPU cores provisioned for the VM.
@option opts [Integer] “maxMemory”
Available RAM for the VM in MB. Valid arguments are 1024, 2048, 4096, 6144, 8192, 12288, 16384, 32768, 49152, 65536
@option opts [Boolean] “hourlyBillingFlag”
Should the VM be billed hourly or monthly (monthly is less expensive, minimum charge of 1 month).
@option opts [Boolean] “localDiskFlag”
Should the root volume be on the machine or on the SAN
@option opts [String] “operatingSystemReferenceCode”
A valid SoftLayer operatingSystemReferenceCode string
@option opts [Boolean] “dedicatedAccountHostOnlyFlag”
Defaults to false, pass true for a single-tenant VM.
@return [Excon::Response]
# File lib/fog/softlayer/requests/compute/create_vms.rb, line 35 def create_vms(opts) raise ArgumentError, "Fog::Compute::Softlayer#create_vms expects argument of type Array" unless opts.kind_of?(Array) response = Excon::Response.new required = %{hostname domain startCpus maxMemory hourlyBillingFlag localDiskFlag} begin opts.each {|vm| Fog::Softlayer.valid_request?(required, vm) or raise MissingRequiredParameter} response.status = 200 response.body = [] ## stub some responses fields = { 'accountId' => Fog::Softlayer.mock_account_id, 'createDate' => Time.now.iso8601, 'datacenter' => nil, 'dedicatedAccountHostOnlyFlag' => false, 'domain' => nil, 'fullyQualifiedDomainName' => nil, 'hostname' => nil, 'id' => Fog::Softlayer.mock_vm_id, 'lastPowerStateId' => nil, 'lastVerifiedDate' => nil, 'maxCpu' => nil, 'maxCpuUnits' => "CORE", 'maxMemory' => nil, 'metricPollDate' => nil, 'modifyDate' => nil, 'startCpus' => nil, 'statusId' => 1001, 'globalIdentifier' => Fog::Softlayer.mock_global_identifier, 'operatingSystem' => {}, 'tagReferences' => [] } # clobber stubbed values where applicable response.body = opts.map do |vm| fields.deep_merge(Fog::Softlayer.stringify_keys(opts.first)) # stringify in case :symbols were passed. end rescue MissingRequiredParameter response.status = 500 response.body = { "code" => "SoftLayer_Exception_MissingCreationProperty", "error" => "Properties #{required.join(', ')} ALL must be set to create an instance of 'SoftLayer_Virtual_Guest'." } end @virtual_guests.push(response.body).flatten! response end
Delete a BMC server @param [Integer] id @return [Excon::Response]
# File lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb, line 16 def delete_bare_metal_server(id) response = Excon::Response.new # Found it and deleted it. response.status = 200 response.body = self.get_bare_metal_servers.body.map{|server| server['id']}.include?(id) # Didn't find it, give the error that the API would give. unless response.body response.body = Fog::JSON.encode({:error => "A billing item is required to process a cancellation.", :code => "SoftLayer_Exception_NotFound"}) response.status = 500 end response end
# File lib/fog/softlayer/requests/compute/delete_key_pair.rb, line 13 def delete_key_pair(id) response = Excon::Response.new response.status = 200 if @key_pairs.reject! { |kp| kp['id'] == id }.nil? response.status = 404 response.body = { "error" => "Unable to find object with id of '#{id}'.", "code" => "SoftLayer_Exception_ObjectNotFound" } else response.body = true end response end
Delete a VM @param [Integer] id @return [Excon::Response]
# File lib/fog/softlayer/requests/compute/delete_vm.rb, line 16 def delete_vm(id) response = Excon::Response.new # Found it and deleted it. response.status = 200 response.body = self.get_vms.body.map{|server| server['id']}.include?(id) # Didn't find it, give the error that the API would give. unless response.body response.body = Fog::JSON.encode({:error => "A billing item is required to process a cancellation.", :code => "SoftLayer_Exception_NotFound"}) response.status = 500 end response end
# File lib/fog/softlayer/requests/compute/get_bare_metal_server.rb, line 12 def get_bare_metal_server(identifier) response = Excon::Response.new response.body = @bare_metal_servers.map {|vm| vm if vm['id'] == identifier.to_s }.compact.first || {} response.status = response.body.empty? ? 404 : 200 if response.status == 404 response.body = { "error"=>"Unable to find object with id of '#{identifier}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } end response end
# File lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb, line 12 def get_bare_metal_servers response = Excon::Response.new response.body = @bare_metal_servers response.status = 200 response end
# File lib/fog/softlayer/requests/compute/get_key_pair.rb, line 12 def get_key_pair(id) response = Excon::Response.new response.status = 200 response.body = key_pair = @key_pairs.select { |kp| kp['id'] == id }.first if key_pair.nil? response.body = { "error"=>"Unable to find object with id of '#{id}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } response.status = 404 end response end
# File lib/fog/softlayer/requests/compute/get_key_pairs.rb, line 13 def get_key_pairs response = Excon::Response.new response.body = @key_pairs response.status = 200 response end
# File lib/fog/softlayer/requests/compute/get_references_by_tag_name.rb, line 14 def get_references_by_tag_name(tag_list) response = Excon::Response.new response.status = 200 response.body = tag_list.split(',').map do |tag| refs = @tags.select { |ref| ref['tag']['name'] == tag } unless refs.empty? { 'accountId' => Fog::Softlayer.mock_account_id, 'id'=>Fog::Mock.random_numbers(7), 'internal' => 0, 'name' => tag, 'references' => refs } end end.compact response end
# File lib/fog/softlayer/requests/compute/get_tag.rb, line 14 def get_tag(id) # TODO: Implement end
# File lib/fog/softlayer/requests/compute/get_vm.rb, line 12 def get_vm(identifier) response = Excon::Response.new response.body = @virtual_guests.map {|vm| vm if vm['id'] == identifier.to_s }.compact.first || {} response.status = response.body.empty? ? 404 : 200 if response.status == 404 response.body = { "error"=>"Unable to find object with id of '#{identifier}'.", "code"=>"SoftLayer_Exception_ObjectNotFound" } end response end
# File lib/fog/softlayer/requests/compute/get_vms.rb, line 12 def get_vms response = Excon::Response.new response.body = @virtual_guests response.status = 200 response end
# File lib/fog/softlayer/compute.rb, line 91 def list_servers vms = self.get_vms.body bare_metals = self.get_bare_metal_servers.body vms.map! { |server| server['bare_metal'] = false } bare_metals.map! { |server| server['bare_metal'] = true } (vms << bare_metals).flatten end
# File lib/fog/softlayer/compute.rb, line 79 def request(method, path, options = {}) _request end
# File lib/fog/softlayer/compute.rb, line 83 def request_access_token(connection, credentials) _request end
# File lib/fog/softlayer/requests/compute/update_key_pair.rb, line 13 def update_key_pair(id, opts) response = Excon::Response.new response.status = 200 key_pair, index = @key_pairs.each_with_index.map { |kp, i| [kp, i] if kp['id'] == id }.compact.flatten if key_pair.nil? response.status = 404 response.body = { "error" => "Unable to find object with id of '#{id}'.", "code" => "SoftLayer_Exception_ObjectNotFound" } else @key_pairs[index] = key_pair.merge(opts) response.body = true end response end
Generated with the Darkfish Rdoc Generator 2.