Class: SoftLayer::Server
- Includes:
- DynamicAttribute
- 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.
Direct Known Subclasses
BareMetalServer, BareMetalServerOrder_Package, VirtualServer, VirtualServerOrder_Package
Instance Attribute Summary
Attributes inherited from ModelBase
Instance Method Summary collapse
-
#change_port_speed(new_speed, public = true) ⇒ Object
Change the current port speed of the server.
-
#datacenter ⇒ Object
:attr_reader: The data center where the server is located.
-
#domain ⇒ Object
:attr_reader: The domain name SoftLayer has stored for the server.
-
#firewall_port_speed ⇒ Object
Returns the max port speed of the public network interfaces of the server taking into account bound interface pairs (redundant network cards).
-
#fullyQualifiedDomainName ⇒ Object
:attr_reader: A convenience attribute that combines the hostname and domain name.
-
#hostname ⇒ Object
:attr_reader: The host name SoftLayer has stored for the server.
-
#initialize(softlayer_client, network_hash) ⇒ Server
constructor
Construct a server from the given client using the network data found in
network_hash. -
#notes ⇒ Object
:attr_reader: Notes about these server (for use by the customer).
-
#notes=(new_notes) ⇒ Object
Change the notes of the server raises ArgumentError if you pass nil as the notes.
-
#primary_private_ip ⇒ Object
:attr_reader: The IP address of the primary private interface for the server.
-
#primary_public_ip ⇒ Object
:attr_reader: The IP address of the primary public interface for the server.
-
#reboot!(reboot_technique = :default_reboot) ⇒ Object
Reboot the server.
-
#reload_os!(token = '', provisioning_script_uri = nil, ssh_keys = nil) ⇒ Object
Begins an OS reload on this server.
-
#set_domain!(new_domain) ⇒ Object
Change the domain of this server.
-
#set_hostname!(new_hostname) ⇒ Object
Change the hostname of this server Raises an ArgumentError if the new hostname is nil or empty.
-
#softlayer_properties(object_mask = nil) ⇒ Object
Make an API request to SoftLayer and return the latest properties hash for this object.
-
#software ⇒ Object
:attr_reader: All software installed on current server.
- #to_s ⇒ Object
-
#user_metadata=(new_metadata) ⇒ Object
Change the user metadata for the server.
Methods included from DynamicAttribute
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
88 89 90 91 92 93 94 |
# File 'lib/softlayer/Server.rb', line 88 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 private network interface.
206 207 208 209 210 211 212 213 214 215 |
# File 'lib/softlayer/Server.rb', line 206 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 |
#datacenter ⇒ Object
:attr_reader: The data center where the server is located
39 |
# File 'lib/softlayer/Server.rb', line 39 sl_attr :datacenter |
#domain ⇒ Object
:attr_reader: The domain name SoftLayer has stored for the server
29 |
# File 'lib/softlayer/Server.rb', line 29 sl_attr :domain |
#firewall_port_speed ⇒ Object
Returns the max port speed of the public network interfaces of the server taking into account bound interface pairs (redundant network cards).
190 191 192 193 194 195 |
# File 'lib/softlayer/Server.rb', line 190 def firewall_port_speed network_components = self.service.object_mask("mask[id,maxSpeed]").getFrontendNetworkComponents() max_speeds = network_components.collect { |component| component['maxSpeed'] } max_speeds.empty? ? 0 : max_speeds.max end |
#fullyQualifiedDomainName ⇒ Object
:attr_reader: A convenience attribute that combines the hostname and domain name
34 |
# File 'lib/softlayer/Server.rb', line 34 sl_attr :fullyQualifiedDomainName |
#hostname ⇒ Object
:attr_reader: The host name SoftLayer has stored for the server
24 |
# File 'lib/softlayer/Server.rb', line 24 sl_attr :hostname |
#notes ⇒ Object
:attr_reader: Notes about these server (for use by the customer)
54 |
# File 'lib/softlayer/Server.rb', line 54 sl_attr :notes |
#notes=(new_notes) ⇒ Object
Change the notes of the server raises ArgumentError if you pass nil as the notes
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/softlayer/Server.rb', line 133 def notes=(new_notes) raise ArgumentError, "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_ip ⇒ Object
:attr_reader: The IP address of the primary private interface for the server
49 |
# File 'lib/softlayer/Server.rb', line 49 sl_attr :primary_private_ip, "primaryBackendIpAddress" |
#primary_public_ip ⇒ Object
:attr_reader: The IP address of the primary public interface for the server
44 |
# File 'lib/softlayer/Server.rb', line 44 sl_attr :primary_public_ip, "primaryIpAddress" |
#reboot!(reboot_technique = :default_reboot) ⇒ Object
Reboot the server. This action is taken immediately. Servers can be rebooted in three different ways: :default_reboot - (Try soft, then hard) Attempts to reboot a server using the :os_reboot technique then, if that is not successful, tries the :power_cycle method :os_reboot - (aka. soft rebot) instructs the server’s host operating system to reboot :power_cycle - (aka. hard reboot) The actual (for hardware) or metaphorical (for virtual servers) equivalent to pulling the plug on the server then plugging it back in.
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/softlayer/Server.rb', line 102 def reboot!(reboot_technique = :default_reboot) case reboot_technique when :default_reboot self.service.rebootDefault when :os_reboot self.service.rebootSoft when :power_cycle self.service.rebootHard else raise ArgumentError, "Unrecognized reboot technique in SoftLayer::Server#reboot!}" end end |
#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.
231 232 233 234 235 236 237 238 |
# File 'lib/softlayer/Server.rb', line 231 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.(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
175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/softlayer/Server.rb', line 175 def set_domain!(new_domain) raise ArgumentError, "The new hostname cannot be nil" unless new_domain raise ArgumentError, "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
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/softlayer/Server.rb', line 157 def set_hostname!(new_hostname) raise ArgumentError, "The new hostname cannot be nil" unless new_hostname raise ArgumentError, "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.
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/softlayer/Server.rb', line 118 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 |
#software ⇒ Object
:attr_reader: All software installed on current server
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/softlayer/Server.rb', line 70 sl_dynamic_attr :software do |software| software.should_update? do @software == nil end software.to_update do software_data = self.service.object_mask(Software.default_object_mask).getSoftwareComponents software_data.collect { |sw| Software.new(self.softlayer_client, sw) unless sw.empty? }.compact end end |
#to_s ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/softlayer/Server.rb', line 240 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.
147 148 149 150 151 |
# File 'lib/softlayer/Server.rb', line 147 def () raise ArgumentError, "Cannot set user metadata to nil" unless self.service.setUserMetadata([]) self.refresh_details() end |