Class: SoftLayer::BareMetalServer

Inherits:
Server show all
Defined in:
lib/softlayer/BareMetalServer.rb

Overview

This class represents a Bare Metal Server, a hardware server in contrast to a virtual machine, in the SoftLayer Environment. It corresponds rougly to the SoftLayer_Hardware and SoftLayer_Hardware_Server services in the SoftLayer API

sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware sldn.softlayer.com/reference/datatypes/SoftLayer_Hardware_Server

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Server

#change_port_speed, #datacenter, #domain, #fullyQualifiedDomainName, #hostname, #initialize, #notes, #notes=, #primary_private_ip, #primary_public_ip, #reload_os!, #set_domain!, #set_hostname!, #softlayer_properties, #to_s, #user_metadata=

Methods inherited from ModelBase

#[], #has_sl_property?, #initialize, #refresh_details, sl_attr, #to_ary

Constructor Details

This class inherits a constructor from SoftLayer::Server

Class Method Details

.cancellation_reasonsObject

Returns a list of the cancellation reasons to use when cancelling a server.

When cancelling a server with the cancel! method, the first parameter is the reason and should be one of the keys in the hash returned by this method. This, in turn will be translated into a string which is, for all intents and purposes, a literal string constant with special meaning to the SoftLayer API.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/softlayer/BareMetalServer.rb', line 107

def self.cancellation_reasons
  {
    :unneeded => 'No longer needed',
    :closing => 'Business closing down',
    :cost => 'Server / Upgrade Costs',
    :migrate_larger => 'Migrating to larger server',
    :migrate_smaller => 'Migrating to smaller server',
    :datacenter => 'Migrating to a different SoftLayer datacenter',
    :performance => 'Network performance / latency',
    :support => 'Support response / timing',
    :sales => 'Sales process / upgrades',
    :moving => 'Moving to competitor',
  }
end

.default_object_maskObject

Returns the default object mask used when fetching servers from the API when an explicit object mask is not provided.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/softlayer/BareMetalServer.rb', line 81

def self.default_object_mask
  sub_mask = {
    "mask(SoftLayer_Hardware_Server)" => [
      'bareMetalInstanceFlag',
      'provisionDate',
      'hardwareStatus',
      'memoryCapacity',
      'processorPhysicalCoreAmount',
      'networkManagementIpAddress',
      'networkComponents[id, status, speed, maxSpeed, name, ipmiMacAddress, ipmiIpAddress, macAddress, primaryIpAddress, port, primarySubnet]',
      'activeTransaction[id, transactionStatus[friendlyName,name]]',
      'hardwareChassis[id, name]'
      ]
    }

  super.merge(sub_mask)
end

.find_servers(options_hash = {}) ⇒ Object

Retrieve a list of Bare Metal servers from the account

The options parameter should contain:

:client - The client used to connect to the API

If no client is given, then the routine will try to use Client.default_client If no client can be found the routine will raise an error.

You may filter the list returned by adding options:

  • :tags (array) - an array of strings representing tags to search for on the instances

  • :cpus (int) - return servers with the given number of (virtual) CPUs

  • :memory (int) - return servers with at least the given amount of memory (in Gigabytes)

  • :hostname (string) - return servers whose hostnames match the query string given (see ObjectFilter::query_to_filter_operation)

  • :domain (string) - filter servers to those whose domain matches the query string given (see ObjectFilter::query_to_filter_operation)

  • :datacenter (string) - find servers whose data center name matches the query string given (see ObjectFilter::query_to_filter_operation)

  • :nic_speed (int) - include servers with the given nic speed (in Mbps)

  • :public_ip (string) - return servers whose public IP address matches the query string given (see ObjectFilter::query_to_filter_operation)

  • :private_ip (string) - same as :public_ip, but for private IP addresses

Additionally you may provide options related to the request itself:

  • :object_mask (string, hash, or array) - The object mask of properties you wish to receive for the items returned If not provided, the result will use the default object mask

  • :result_limit (hash with :limit, and :offset keys) - Limit the scope of results returned.



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
# File 'lib/softlayer/BareMetalServer.rb', line 175

def self.find_servers(options_hash = {})
  softlayer_client = options_hash[:client] || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  if(options_hash.has_key? :object_filter)
    object_filter = options_hash[:object_filter]
  else
    object_filter = {}
  end

  option_to_filter_path = {
    :cpus => "hardware.processorPhysicalCoreAmount",
    :memory => "hardware.memoryCapacity",
    :hostname => "hardware.hostname",
    :domain => "hardware.domain",
    :datacenter => "hardware.datacenter.name",
    :nic_speed => "hardware.networkComponents.maxSpeed",
    :public_ip => "hardware.primaryIpAddress",
    :private_ip => "hardware.primaryBackendIpAddress"
  }

  # For each of the options in the option_to_filter_path map, if the options hash includes
  # that particular option, add a clause to the object filter that filters for the matching
  # value
  option_to_filter_path.each do |option, filter_path|
    object_filter.merge!(SoftLayer::ObjectFilter.build(filter_path, options_hash[option])) if options_hash.has_key?(option)
  end

  # Tags get a much more complex object filter operation so we handle them separately
  if options_hash.has_key?(:tags)
    object_filter.merge!(SoftLayer::ObjectFilter.build("hardware.tagReferences.tag.name", {
      'operation' => 'in',
      'options' => [{
        'name' => 'data',
        'value' => options_hash[:tags]
        }]
      } ));
  end

   = softlayer_client['Account']
   = .object_filter(object_filter) unless object_filter.empty?
   = .object_mask(default_object_mask.to_sl_object_mask)

  if(options_hash.has_key? :object_mask)
     = .object_mask(options_hash[:object_mask])
  end

  if options_hash.has_key?(:result_limit)
    offset = options[:result_limit][:offset]
    limit = options[:result_limit][:limit]

     = .result_limit(offset, limit)
  end

  bare_metal_data = .getHardware()
  bare_metal_data.collect { |server_data| BareMetalServer.new(softlayer_client, server_data) }
end

.server_with_id(server_id, options = {}) ⇒ Object

Retrive the bare metal server with the given server ID from the SoftLayer API

The options parameter should contain:

:client - The client used to connect to the API

If no client is given, then the routine will try to use Client.default_client If no client can be found the routine will raise an error.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/softlayer/BareMetalServer.rb', line 132

def self.server_with_id(server_id, options = {})
  softlayer_client = options[:client] || Client.default_client
  raise "#{__method__} requires a client but none was given and Client::default_client is not set" if !softlayer_client

  hardware_service = softlayer_client["Hardware"]
  hardware_service = hardware_service.object_mask(default_object_mask.to_sl_object_mask)

  if options.has_key?(:object_mask)
    object_mask = hardware_service.object_mask(options[:object_mask])
  end

  server_data = hardware_service.object_with_id(server_id).getObject()

  return BareMetalServer.new(softlayer_client, server_data)
end

Instance Method Details

#bare_metal_instance?Boolean

Returns true if this BareMetalServer is actually a Bare Metal Instance a Bare Metal Instance is physical, hardware server that is is provisioned to match a profile with characteristics similar to a Virtual Server

This is an important distincition in rare cases, like cancelling the server.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/softlayer/BareMetalServer.rb', line 41

def bare_metal_instance?
  if has_sl_property?(:bareMetalInstanceFlag)
    self["bareMetalInstanceFlag"] != 0
  else
    false
  end
end

#cancel!(reason = :unneeded, comment = '') ⇒ Object

Sends a ticket asking that a server be cancelled (i.e. shutdown and removed from the account).

The cancellation_reason parameter should be a key from the hash returned by BareMetalServer::cancellation_reasons.

You may add your own, more specific reasons for cancelling a server in the comments parameter.



59
60
61
62
63
64
65
66
67
68
# File 'lib/softlayer/BareMetalServer.rb', line 59

def cancel!(reason = :unneeded, comment = '')
  if !bare_metal_instance? then
    cancellation_reasons = self.class.cancellation_reasons()
    cancel_reason = cancellation_reasons[reason] || cancellation_reasons[:unneeded]
    softlayer_client["Ticket"].createCancelServerTicket(self.id, cancel_reason, comment, true, 'HARDWARE')
  else
    # Note that reason and comment are ignored in this case, unfortunately
    softlayer_client['Billing_Item'].object_with_id(self.billingItem['id'].to_i).cancelService()
  end
end

#serviceObject

Returns the SoftLayer Service used to work with this Server For Bare Metal Servers that is SoftLayer_Hardware though in some special cases you may have to use SoftLayer_Hardware_Server as a type or service.



74
75
76
# File 'lib/softlayer/BareMetalServer.rb', line 74

def service
  return softlayer_client["Hardware"].object_with_id(self.id)
end