Class: Fog::Compute::Softlayer::Real

Inherits:
Object
  • Object
show all
Includes:
Softlayer::Compute::Shared
Defined in:
lib/fog/softlayer/compute.rb,
lib/fog/softlayer/requests/compute/get_vm.rb,
lib/fog/softlayer/requests/compute/get_vms.rb,
lib/fog/softlayer/requests/compute/create_vm.rb,
lib/fog/softlayer/requests/compute/delete_vm.rb,
lib/fog/softlayer/requests/compute/create_vms.rb,
lib/fog/softlayer/requests/compute/get_bare_metal_server.rb,
lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb,
lib/fog/softlayer/requests/compute/create_bare_metal_server.rb,
lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb

Overview

Makes real connections to Softlayer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Softlayer::Compute::Shared

#initialize, valid_request?

Instance Attribute Details

#default_domainObject

Returns the value of attribute default_domain.



80
81
82
# File 'lib/fog/softlayer/compute.rb', line 80

def default_domain
  @default_domain
end

Instance Method Details

#create_bare_metal_server(opts) ⇒ Object

Raises:

  • (ArgumentError)


77
78
79
80
# File 'lib/fog/softlayer/requests/compute/create_bare_metal_server.rb', line 77

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)
  request(:hardware_server, :create_object, :body => opts, :http_method => :POST)
end

#create_vm(opts) ⇒ Object

Raises:

  • (ArgumentError)


44
45
46
47
48
# File 'lib/fog/softlayer/requests/compute/create_vm.rb', line 44

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

#create_vms(opts) ⇒ Object

Raises:

  • (ArgumentError)


87
88
89
90
# File 'lib/fog/softlayer/requests/compute/create_vms.rb', line 87

def create_vms(opts)
  raise ArgumentError, "Fog::Compute::Softlayer#create_vms expects argument of type Array" unless opts.kind_of?(Array)
  request(:virtual_guest, :create_objects, :body => opts, :http_method => :POST)
end

#delete_bare_metal_server(id) ⇒ Object



35
36
37
# File 'lib/fog/softlayer/requests/compute/delete_bare_metal_server.rb', line 35

def delete_bare_metal_server(id)
  request(:hardware_server, id.to_s, :http_method => :DELETE)
end

#delete_vm(id) ⇒ Object



35
36
37
# File 'lib/fog/softlayer/requests/compute/delete_vm.rb', line 35

def delete_vm(id)
  request(:virtual_guest, id.to_s, :http_method => :DELETE)
end

#get_bare_metal_server(identifier) ⇒ Object



22
23
24
# File 'lib/fog/softlayer/requests/compute/get_bare_metal_server.rb', line 22

def get_bare_metal_server(identifier)
  request(:hardware_server, identifier, :expected => [200, 404], :query => 'objectMask=mask[memory,provisionDate,processorCoreAmount,hardDrives,datacenter,hourlyBillingFlag,operatingSystem.passwords.password]')
end

#get_bare_metal_serversObject



22
23
24
# File 'lib/fog/softlayer/requests/compute/get_bare_metal_servers.rb', line 22

def get_bare_metal_servers
  request(:account, :get_hardware)
end

#get_vm(identifier) ⇒ Object



22
23
24
# File 'lib/fog/softlayer/requests/compute/get_vm.rb', line 22

def get_vm(identifier)
  request(:virtual_guest, identifier, :expected => [200, 404], :query => 'objectMask=mask[blockDevices,blockDeviceTemplateGroup.globalIdentifier,operatingSystem.passwords.password]')
end

#get_vmsObject



22
23
24
# File 'lib/fog/softlayer/requests/compute/get_vms.rb', line 22

def get_vms
  request(:account, :get_virtual_guests)
end

#list_serversObject



132
133
134
# File 'lib/fog/softlayer/compute.rb', line 132

def list_servers
  (self.get_vms.body << self.get_bare_metal_servers.body).flatten
end

#request(service, path, options = {}) ⇒ Excon::Response

Sends the real request to the real SoftLayer service.

Parameters:

  • service (String)

    …ayer.com/rest/v3/Softlayer_Service_Name…

  • path (String)

    …ayer.com/rest/v3/Softlayer_Service_Name/path.json

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :body (Array<Hash>)

    HTTP request body parameters

  • :softlayer_api_url (String)

    Override the default (or configured) API endpoint

  • :softlayer_username (String)

    Email or user identifier for user based authentication

  • :softlayer_api_key (String)

    Password for user based authentication

Returns:

  • (Excon::Response)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/fog/softlayer/compute.rb', line 99

def request(service, path, options={})

  # default HTTP method to get if not passed
  http_method = options[:http_method] || :get
  # set the target base url
  @request_url = options[:softlayer_api_url] || Fog::Softlayer::SL_API_URL
  # tack on the username and password
  credentialize_url(@credentials[:username], @credentials[:api_key])
  # set the SoftLayer Service name
  set_sl_service(service)
  # set the request path (known as the "method" in SL docs)
  set_sl_path(path)
  # set the query params if any


  # build request params
  params = { :headers => user_agent_header }
  params[:headers]['Content-Type'] = 'application/json'
  params[:expects] = options[:expected] || [200,201]
  params[:body] = Fog::JSON.encode({:parameters => [ options[:body] ]}) unless options[:body].nil?
  params[:query] = options[:query] unless options[:query].nil?

  # initialize connection object
  @connection = Fog::Core::Connection.new(@request_url, false, params)

  # send it
  response = @connection.request(:method => http_method)

  # decode it
  response.body = Fog::JSON.decode(response.body)
  response
end