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 roughly 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, #fqdn, #fullyQualifiedDomainName, #hostname, #initialize, #network_monitor_levels, #network_monitors, #notes, #notes=, #notified_network_monitor_users, #primary_network_component, #primary_private_ip, #primary_public_ip, #reboot!, #reload_os!, #set_domain!, #set_hostname!, #softlayer_properties, #software, #to_s, #user_metadata=

Methods included from DynamicAttribute

included

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.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/softlayer/BareMetalServer.rb', line 103

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.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/softlayer/BareMetalServer.rb', line 76

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

  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 (string/array) - an array of strings representing tags to search for on the instances

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

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

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

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

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

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

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

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

Additionally you may provide options related to the request itself:

  • :object_filter (ObjectFilter) - Include hardware servers for servers that matche the

    criteria of this object filter
    
  • :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.



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

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]
    raise "Expected an instance of SoftLayer::ObjectFilter" unless object_filter.kind_of?(SoftLayer::ObjectFilter)
  else
    object_filter = ObjectFilter.new()
  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",
    :tags       => "hardware.tagReferences.tag.name"
  }

  # 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.modify { |filter| filter.accept(filter_path).when_it is(options_hash[option])} if options_hash[option]
  end

   = softlayer_client[:Account]
   = .object_filter(object_filter) unless object_filter.empty?
   = .object_mask(default_object_mask.to_sl_object_mask)
   = .object_mask(options_hash[:object_mask]) if options_hash[:object_mask]

  if options_hash[:result_limit] && options_hash[:result_limit][:offset] && options_hash[:result_limit][:limit]
     = .result_limit(options_hash[:result_limit][:offset], options_hash[:result_limit][: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

Retrieve 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.

Additionally you may provide options related to the request itself:

  • :object_mask (string) - The object mask of properties you wish to receive for the items returned.

    If not provided, the result will use the default object mask
    


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/softlayer/BareMetalServer.rb', line 162

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_Server]
  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 distinction in rare cases, like cancelling the server.

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/softlayer/BareMetalServer.rb', line 28

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.



46
47
48
49
50
51
52
53
54
55
# File 'lib/softlayer/BareMetalServer.rb', line 46

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.service.object_mask("mask[id]").getBillingItem['id'].to_i).cancelService()
  end
end

#firewall_port_speedObject

Returns the max port speed of the public network interfaces of the server taking into account bound interface pairs (redundant network cards).



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/softlayer/BareMetalServer.rb', line 121

def firewall_port_speed
  network_components = self.service.object_mask("mask[id,maxSpeed,networkComponentGroup.networkComponents]").getFrontendNetworkComponents()

  # Split the interfaces into grouped and ungrouped interfaces. The max speed of a group will be the sum
  # of the individual speeds in that group.  The max speed of ungrouped interfaces is simply the max speed
  # of that interface.
  grouped_interfaces, ungrouped_interfaces = network_components.partition{ |interface| interface.has_key?("networkComponentGroup") }

  if !grouped_interfaces.empty?
    group_speeds = grouped_interfaces.collect do |interface|
      interface['networkComponentGroup']['networkComponents'].inject(0) {|total_speed, component| total_speed += component['maxSpeed']}
    end

    max_group_speed = group_speeds.max
  else
    max_group_speed = 0
  end

  if !ungrouped_interfaces.empty?
    max_ungrouped_speed = ungrouped_interfaces.collect { |interface| interface['maxSpeed']}.max
  else
    max_ungrouped_speed = 0
  end

  return [max_group_speed, max_ungrouped_speed].max
end

#remote_management_accountsObject

Returns the username/password combinations for remote management accounts



60
61
62
# File 'lib/softlayer/BareMetalServer.rb', line 60

def remote_management_accounts
  self['remoteManagementAccounts']
end

#serviceObject

Returns the typical 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. That service object is available through the hardware_server_service method



69
70
71
# File 'lib/softlayer/BareMetalServer.rb', line 69

def service
  return softlayer_client[:Hardware_Server].object_with_id(self.id)
end