Class: SoftLayer::Server

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

Overview

Server is the base class for VirtualServer and BareMetalServer. It implements some functionality common to both those classes.

Server is an abstract class and you should not create them directly.

While VirtualServer and BareMetalServer each have analogs in the SoftLayer API, those analogs do not share a direct ancestry. As a result there is no SoftLayer API analog to this class.

Instance Attribute Summary

Attributes inherited from ModelBase

#softlayer_client

Instance Method Summary collapse

Methods inherited from ModelBase

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

Constructor Details

#initialize(softlayer_client, network_hash) ⇒ Server

Construct a server from the given client using the network data found in network_hash

Most users should not have to call this method directly. Instead you should access the servers property of an Account object, or use methods like BareMetalServer#find_servers or VirtualServer#find_servers



78
79
80
81
82
83
84
# File 'lib/softlayer/Server.rb', line 78

def initialize(softlayer_client, network_hash)
  if self.class == Server
    raise RuntimeError, "The Server class is an abstract base class and should not be instantiated directly"
  else
    super
  end
end

Instance Method Details

#change_port_speed(new_speed, public = true) ⇒ Object

Change the current port speed of the server

new_speed is expressed Mbps and should be 0, 10, 100, or 1000. Ports have a maximum speed that will limit the actual speed set on the port.

Set public to false in order to change the speed of the primary private network interface.



168
169
170
171
172
173
174
175
176
177
# File 'lib/softlayer/Server.rb', line 168

def change_port_speed(new_speed, public = true)
  if public
    self.service.setPublicNetworkInterfaceSpeed(new_speed)
  else
    self.service.setPrivateNetworkInterfaceSpeed(new_speed)
  end

  self.refresh_details()
  self
end

#datacenterObject

:attr_reader: The data center where the server is located



54
# File 'lib/softlayer/Server.rb', line 54

sl_attr :datacenter

#domainObject

:attr_reader: The domain name SoftLayer has stored for the server



44
# File 'lib/softlayer/Server.rb', line 44

sl_attr :domain

#fullyQualifiedDomainNameObject

:attr_reader: A convenience attribute that combines the hostname and domain name



49
# File 'lib/softlayer/Server.rb', line 49

sl_attr :fullyQualifiedDomainName

#hostnameObject

:attr_reader: The host name SoftLayer has stored for the server



39
# File 'lib/softlayer/Server.rb', line 39

sl_attr :hostname

#notesObject

:attr_reader: Notes about these server (for use by the customer)



69
# File 'lib/softlayer/Server.rb', line 69

sl_attr :notes

#notes=(new_notes) ⇒ Object

Change the notes of the server raises ArgumentError if you pass nil as the notes

Raises:

  • (ArgumentError)


104
105
106
107
108
109
110
111
112
113
# File 'lib/softlayer/Server.rb', line 104

def notes=(new_notes)
  raise ArgumentError.new("The new notes cannot be nil") unless new_notes

  edit_template = {
    "notes" => new_notes
  }

  self.service.editObject(edit_template)
  self.refresh_details()
end

#primary_private_ipObject

:attr_reader: The IP address of the primary private interface for the server



64
# File 'lib/softlayer/Server.rb', line 64

sl_attr :primary_private_ip, "primaryBackendIpAddress"

#primary_public_ipObject

:attr_reader: The IP address of the primary public interface for the server



59
# File 'lib/softlayer/Server.rb', line 59

sl_attr :primary_public_ip, "primaryIpAddress"

#reload_os!(token = '', provisioning_script_uri = nil, ssh_keys = nil) ⇒ Object

Begins an OS reload on this server.

The OS reload can wipe out the data on your server so this method uses a confirmation mechanism built into the underlying SoftLayer API. If you call this method once without a token, it will not actually start the reload. Instead it will return a token to you. That token is good for 10 minutes. If you call this method again and pass that token then the OS reload will actually begin.

If you wish to force the OS Reload and bypass the token safety mechanism pass the token ‘FORCE’ as the first parameter. If you do so the reload will proceed immediately.



193
194
195
196
197
198
199
200
# File 'lib/softlayer/Server.rb', line 193

def reload_os!(token = '', provisioning_script_uri = nil, ssh_keys = nil)
  configuration = {}

  configuration['customProvisionScriptUri'] = provisioning_script_uri if provisioning_script_uri
  configuration['sshKeyIds'] = ssh_keys if ssh_keys

  self.service.reloadOperatingSystem(token, configuration)
end

#set_domain!(new_domain) ⇒ Object

Change the domain of this server

Raises an ArgumentError if the new domain is nil or empty no further validation is done on the domain name

Raises:

  • (ArgumentError)


146
147
148
149
150
151
152
153
154
155
156
# File 'lib/softlayer/Server.rb', line 146

def set_domain!(new_domain)
  raise ArgumentError.new("The new hostname cannot be nil") unless new_domain
  raise ArgumentError.new("The new hostname cannot be empty") if new_domain.empty?

  edit_template = {
    "domain" => new_domain
  }

  self.service.editObject(edit_template)
  self.refresh_details()
end

#set_hostname!(new_hostname) ⇒ Object

Change the hostname of this server Raises an ArgumentError if the new hostname is nil or empty

Raises:

  • (ArgumentError)


128
129
130
131
132
133
134
135
136
137
138
# File 'lib/softlayer/Server.rb', line 128

def set_hostname!(new_hostname)
  raise ArgumentError.new("The new hostname cannot be nil") unless new_hostname
  raise ArgumentError.new("The new hostname cannot be empty") if new_hostname.empty?

  edit_template = {
    "hostname" => new_hostname
  }

  self.service.editObject(edit_template)
  self.refresh_details()
end

#softlayer_properties(object_mask = nil) ⇒ Object

Make an API request to SoftLayer and return the latest properties hash for this object.



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/softlayer/Server.rb', line 89

def softlayer_properties(object_mask = nil)
  my_service = self.service

  if(object_mask)
    my_service = my_service.object_mask(object_mask)
  else
    my_service = my_service.object_mask(self.class.default_object_mask.to_sl_object_mask)
  end

  my_service.getObject()
end

#to_sObject



202
203
204
205
206
207
208
# File 'lib/softlayer/Server.rb', line 202

def to_s
  result = super
  if respond_to?(:hostname) then
    result.sub!('>', ", #{hostname}>")
  end
  result
end

#user_metadata=(new_metadata) ⇒ Object

Change the user metadata for the server.

Raises:

  • (ArgumentError)


118
119
120
121
122
# File 'lib/softlayer/Server.rb', line 118

def user_metadata=()
  raise ArgumentError.new("Cannot set user metadata to nil") unless 
  self.service.([])
  self.refresh_details()
end