Class: OpenStack::Compute::Server
- Defined in:
- lib/openstack/compute/server.rb
Instance Attribute Summary collapse
-
#accessipv4 ⇒ Object
readonly
Returns the value of attribute accessipv4.
-
#accessipv6 ⇒ Object
readonly
Returns the value of attribute accessipv6.
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#adminPass ⇒ Object
Returns the value of attribute adminPass.
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#fault ⇒ Object
readonly
Returns the value of attribute fault.
-
#flavor ⇒ Object
readonly
Returns the value of attribute flavor.
-
#hostId ⇒ Object
readonly
Returns the value of attribute hostId.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#key_name ⇒ Object
readonly
Returns the value of attribute key_name.
-
#libvirt_id ⇒ Object
readonly
Returns the value of attribute libvirt_id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#security_groups ⇒ Object
readonly
Returns the value of attribute security_groups.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#add_fixed_ip(network_id) ⇒ Object
Add a fixed ip from a specific network to the instance.
-
#add_security_group(security_group) ⇒ Object
Adds a specific security group to the server.
-
#change_password!(password) ⇒ Object
Changes the admin password.
-
#confirm_resize! ⇒ Object
After a server resize is complete, calling this method will confirm the resize with the OpenStack API, and discard the fallback/original image.
-
#create_image(options) ⇒ Object
Takes a snapshot of the server and creates a server image from it.
-
#delete! ⇒ Object
Deletes the server from OpenStack Compute.
-
#delete_security_group(security_group) ⇒ Object
Removes a specific security group from the server.
- #get_addresses(address_info) ⇒ Object
-
#get_console ⇒ Object
Get novnc console URL Return Hash with type and URL.
-
#get_console_output(length = 50) ⇒ Object
Get console output Return output string object.
-
#get_volume_attachments ⇒ Object
List volume attachments for an instance.
-
#initialize(compute, id) ⇒ Server
constructor
This class is the representation of a single Server object.
-
#interface_create(options) ⇒ Object
Creates a new interface on this server.
-
#interface_delete(id) ⇒ Object
Deleted a specific interface from this server.
-
#interface_details(id) ⇒ Object
Returns all details about the interface on this server.
-
#interface_list ⇒ Object
Lists all interfaces from this server.
-
#pause ⇒ Object
Sends an API request to pause this server.
-
#populate(data = nil) ⇒ Object
(also: #refresh)
Makes the actual API call to get information about the given server object.
-
#reboot(type = "SOFT") ⇒ Object
Sends an API request to reboot this server.
-
#reboot! ⇒ Object
Sends an API request to hard-reboot (power cycle) the server.
-
#rebuild!(options) ⇒ Object
The rebuild function removes all data on the server and replaces it with the specified image.
-
#remove_fixed_ip(ip) ⇒ Object
Remove a specific fixed ip from the instance.
-
#rescue(options = nil) ⇒ Object
Sends an API request to rescue this server.
-
#resize!(flavorRef) ⇒ Object
Resizes the server to the size contained in the server flavor found at ID flavorRef.
-
#resume ⇒ Object
Sends an API request to resume this server.
-
#revert_resize! ⇒ Object
After a server resize is complete, calling this method will reject the resized server with the OpenStack API, destroying the new image and replacing it with the pre-resize fallback image.
-
#start ⇒ Object
Sends an API request to start (resume) the server.
-
#stop ⇒ Object
Sends an API request to stop (suspend) the server.
-
#suspend ⇒ Object
Sends an API request to suspend this server.
-
#unpause ⇒ Object
Sends an API request to unpause this server.
-
#unrescue ⇒ Object
Sends an API request to unrescue this server.
-
#update(options) ⇒ Object
Updates various parameters about the server.
Constructor Details
#initialize(compute, id) ⇒ Server
This class is the representation of a single Server object. The constructor finds the server identified by the specified ID number, accesses the API via the populate method to get information about that server, and returns the object.
Will be called via the get_server or create_server methods on the OpenStack::Compute::Connection object, and will likely not be called directly.
>> server = cs.get_server(110917)
=> #<OpenStack::Compute::Server:0x1014e5438 ....>
>> server.name
=> "RenamedRubyTest"
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/openstack/compute/server.rb', line 35 def initialize(compute,id) @compute = compute @id = id @svrmgmthost = @compute.connection.service_host @svrmgmtpath = @compute.connection.service_path @svrmgmtport = @compute.connection.service_port @svrmgmtscheme = @compute.connection.service_scheme populate return self end |
Instance Attribute Details
#accessipv4 ⇒ Object (readonly)
Returns the value of attribute accessipv4.
14 15 16 |
# File 'lib/openstack/compute/server.rb', line 14 def accessipv4 @accessipv4 end |
#accessipv6 ⇒ Object (readonly)
Returns the value of attribute accessipv6.
15 16 17 |
# File 'lib/openstack/compute/server.rb', line 15 def accessipv6 @accessipv6 end |
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
16 17 18 |
# File 'lib/openstack/compute/server.rb', line 16 def addresses @addresses end |
#adminPass ⇒ Object
Returns the value of attribute adminPass.
21 22 23 |
# File 'lib/openstack/compute/server.rb', line 21 def adminPass @adminPass end |
#created ⇒ Object (readonly)
Returns the value of attribute created.
23 24 25 |
# File 'lib/openstack/compute/server.rb', line 23 def created @created end |
#fault ⇒ Object (readonly)
Returns the value of attribute fault.
10 11 12 |
# File 'lib/openstack/compute/server.rb', line 10 def fault @fault end |
#flavor ⇒ Object (readonly)
Returns the value of attribute flavor.
19 20 21 |
# File 'lib/openstack/compute/server.rb', line 19 def flavor @flavor end |
#hostId ⇒ Object (readonly)
Returns the value of attribute hostId.
17 18 19 |
# File 'lib/openstack/compute/server.rb', line 17 def hostId @hostId end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/openstack/compute/server.rb', line 7 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
18 19 20 |
# File 'lib/openstack/compute/server.rb', line 18 def image @image end |
#key_name ⇒ Object (readonly)
Returns the value of attribute key_name.
22 23 24 |
# File 'lib/openstack/compute/server.rb', line 22 def key_name @key_name end |
#libvirt_id ⇒ Object (readonly)
Returns the value of attribute libvirt_id.
9 10 11 |
# File 'lib/openstack/compute/server.rb', line 9 def libvirt_id @libvirt_id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
20 21 22 |
# File 'lib/openstack/compute/server.rb', line 20 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/openstack/compute/server.rb', line 8 def name @name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
13 14 15 |
# File 'lib/openstack/compute/server.rb', line 13 def progress @progress end |
#security_groups ⇒ Object (readonly)
Returns the value of attribute security_groups.
24 25 26 |
# File 'lib/openstack/compute/server.rb', line 24 def security_groups @security_groups end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
12 13 14 |
# File 'lib/openstack/compute/server.rb', line 12 def state @state end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
11 12 13 |
# File 'lib/openstack/compute/server.rb', line 11 def status @status end |
Instance Method Details
#add_fixed_ip(network_id) ⇒ Object
Add a fixed ip from a specific network to the instance
Returns true if the API call succeeds.
>> server.add_fixed_ip
=> true
388 389 390 391 392 393 394 395 |
# File 'lib/openstack/compute/server.rb', line 388 def add_fixed_ip(network_id) data = JSON.generate(:addFixedIp => { :networkId => network_id }) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#add_security_group(security_group) ⇒ Object
Adds a specific security group to the server.
>> server.add_security_group('default')
=> true
467 468 469 470 471 472 473 |
# File 'lib/openstack/compute/server.rb', line 467 def add_security_group(security_group) data = JSON.generate(:addSecurityGroup => {:name => security_group}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) self.populate true end |
#change_password!(password) ⇒ Object
Changes the admin password. Returns the password if it succeeds.
266 267 268 269 270 |
# File 'lib/openstack/compute/server.rb', line 266 def change_password!(password) json = JSON.generate(:changePassword => { :adminPass => password }) @compute.connection.req('POST', "/servers/#{@id}/action", :data => json) @adminPass = password end |
#confirm_resize! ⇒ Object
After a server resize is complete, calling this method will confirm the resize with the OpenStack API, and discard the fallback/original image.
Returns true if the API call succeeds.
>> server.confirm_resize!
=> true
239 240 241 242 243 244 245 246 |
# File 'lib/openstack/compute/server.rb', line 239 def confirm_resize! # If the resize bug gets figured out, should put a check here to make sure that it's in the proper state for this. data = JSON.generate(:confirmResize => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) self.populate true end |
#create_image(options) ⇒ Object
Takes a snapshot of the server and creates a server image from it. That image can then be used to build new servers. The snapshot is saved asynchronously. Check the image status to make sure that it is ACTIVE before attempting to perform operations on it.
A name string for the saved image must be provided. A new OpenStack::Compute::Image object for the saved image is returned.
The image is saved as a backup, of which there are only three available slots. If there are no backup slots available, A OpenStack::Exception::OpenStackComputeFault will be raised.
>> image = server.create_image(:name => "My Rails Server")
=>
210 211 212 213 214 215 216 |
# File 'lib/openstack/compute/server.rb', line 210 def create_image() data = JSON.generate(:createImage => ) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) image_id = response["Location"].split("/images/").last OpenStack::Compute::Image.new(@compute, image_id) end |
#delete! ⇒ Object
Deletes the server from OpenStack Compute. The server will be shut down, data deleted, and billing stopped.
Returns true if the API call succeeds.
>> server.delete!
=> true
155 156 157 158 159 |
# File 'lib/openstack/compute/server.rb', line 155 def delete! response = @compute.connection.csreq("DELETE",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}",@svrmgmtport,@svrmgmtscheme) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#delete_security_group(security_group) ⇒ Object
Removes a specific security group from the server.
>> server.delete_security_group('default')
=> true
479 480 481 482 483 484 485 |
# File 'lib/openstack/compute/server.rb', line 479 def delete_security_group(security_group) data = JSON.generate(:removeSecurityGroup => {:name => security_group}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) self.populate true end |
#get_addresses(address_info) ⇒ Object
272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/openstack/compute/server.rb', line 272 def get_addresses(address_info) address_info = OpenStack::Compute::Address.fix_labels(address_info) address_list = OpenStack::Compute::AddressList.new address_info.each do |label, addr| addr.each do |address| address_list << OpenStack::Compute::Address.new(label,address) if address_list.last.version == 4 && (!@accessipv4 || accessipv4 == "") then @accessipv4 = address_list.last.address end end end address_list end |
#get_console ⇒ Object
Get novnc console URL Return Hash with type and URL
288 289 290 291 292 293 |
# File 'lib/openstack/compute/server.rb', line 288 def get_console data = JSON.generate("os-getVNCConsole" => {:type => "novnc"}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON::parse(response.body)["console"] end |
#get_console_output(length = 50) ⇒ Object
Get console output Return output string object
297 298 299 300 301 302 |
# File 'lib/openstack/compute/server.rb', line 297 def get_console_output(length=50) data = JSON.generate("os-getConsoleOutput" => {:length => length}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON::parse(response.body)["output"] end |
#get_volume_attachments ⇒ Object
List volume attachments for an instance
>> server.get_volume_attachments
=> array
457 458 459 460 461 |
# File 'lib/openstack/compute/server.rb', line 457 def response = @compute.connection.req('GET', "/servers/#{@id}/os-volume_attachments") OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON.parse(response.body)['volumeAttachments'] end |
#interface_create(options) ⇒ Object
Creates a new interface on this server.
>> server.interface_create
=> array
436 437 438 439 440 441 |
# File 'lib/openstack/compute/server.rb', line 436 def interface_create() data = JSON.generate(:interfaceAttachment => ) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/os-interface",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON::parse(response.body)["interfaceAttachment"] end |
#interface_delete(id) ⇒ Object
Deleted a specific interface from this server.
>> server.interface_delete
=> true
447 448 449 450 451 |
# File 'lib/openstack/compute/server.rb', line 447 def interface_delete(id) response = @compute.connection.csreq("DELETE",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/os-interface/#{id}",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'}) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#interface_details(id) ⇒ Object
Returns all details about the interface on this server.
>> server.interface_details
=> array
426 427 428 429 430 |
# File 'lib/openstack/compute/server.rb', line 426 def interface_details(id) response = @compute.connection.csreq("GET",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/os-interface/#{id}",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'}) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON::parse(response.body)["interfaceAttachment"] end |
#interface_list ⇒ Object
Lists all interfaces from this server.
>> server.interface_list
=> array
416 417 418 419 420 |
# File 'lib/openstack/compute/server.rb', line 416 def interface_list response = @compute.connection.csreq("GET",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/os-interface",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'}) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) JSON::parse(response.body)["interfaceAttachments"] end |
#pause ⇒ Object
Sends an API request to pause this server.
Returns true if the API call succeeds.
>> server.pause
=> true
310 311 312 313 314 315 |
# File 'lib/openstack/compute/server.rb', line 310 def pause data = JSON.generate(:pause => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#populate(data = nil) ⇒ Object Also known as: refresh
Makes the actual API call to get information about the given server object. If you are attempting to track the status or project of a server object (for example, when rebuilding, creating, or resizing a server), you will likely call this method within a loop until the status becomes “ACTIVE” or other conditions are met.
Returns true if the API call succeeds.
>> server.refresh
=> true
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/openstack/compute/server.rb', line 54 def populate(data=nil) path = "/servers/#{URI.encode(@id.to_s)}" if data.nil? then response = @compute.connection.req("GET", path) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) data = JSON.parse(response.body)["server"] end @id = data["id"] || data["uuid"] @name = data["name"] @libvirt_id = data["OS-EXT-SRV-ATTR:instance_name"] @fault = data["fault"] @status = data["status"] @state = data["OS-EXT-STS:task_state"] @progress = data["progress"] @addresses = get_addresses(data["addresses"]) @metadata = OpenStack::Compute::Metadata.new(@compute, path, data["metadata"]) @hostId = data["hostId"] @image = data["image"] || data["imageId"] @flavor = data["flavor"] || data["flavorId"] @key_name = data["key_name"] # if provider uses the keys API extension for accessing servers @created = data["created"] @security_groups = (data["security_groups"] || []) true end |
#reboot(type = "SOFT") ⇒ Object
Sends an API request to reboot this server. Takes an optional argument for the type of reboot, which can be “SOFT” (graceful shutdown) or “HARD” (power cycle). The hard reboot is also triggered by server.reboot!, so that may be a better way to call it.
Returns true if the API call succeeds.
>> server.reboot
=> true
87 88 89 90 91 92 |
# File 'lib/openstack/compute/server.rb', line 87 def reboot(type="SOFT") data = JSON.generate(:reboot => {:type => type}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#reboot! ⇒ Object
Sends an API request to hard-reboot (power cycle) the server. See the reboot method for more information.
Returns true if the API call succeeds.
>> server.reboot!
=> true
100 101 102 |
# File 'lib/openstack/compute/server.rb', line 100 def reboot! self.reboot("HARD") end |
#rebuild!(options) ⇒ Object
The rebuild function removes all data on the server and replaces it with the specified image. The serverRef and all IP addresses will remain the same. If name and metadata are specified, they will replace existing values, otherwise they will not change. A rebuild operation always removes data injected into the file system via server personality. You may reinsert data into the filesystem during the rebuild.
This method expects a hash of the form: {
:imageRef => "https://foo.com/v1.1/images/2",
:name => "newName",
:metadata => { :values => { :foo : "bar" } },
:personality => [
{
:path => "/etc/banner.txt",
:contents => : "ICAgpY2hhcmQgQmFjaA=="
}
]
}
This will wipe and rebuild the server, but keep the server ID number, name, and IP addresses the same.
Returns true if the API call succeeds.
>> server.rebuild!
=> true
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/openstack/compute/server.rb', line 188 def rebuild!() [:personality] = Personalities.get_personality([:personality]) json = JSON.generate(:rebuild => ) response = @compute.connection.req('POST', "/servers/#{@id}/action", :data => json) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) data = JSON.parse(response.body)['server'] self.populate(data) self.adminPass = data['adminPass'] if data['adminPass'] true end |
#remove_fixed_ip(ip) ⇒ Object
Remove a specific fixed ip from the instance
Returns true if the API call succeeds.
>> server.remove_fixed_ip
=> true
403 404 405 406 407 408 409 410 |
# File 'lib/openstack/compute/server.rb', line 403 def remove_fixed_ip(ip) data = JSON.generate(:removeFixedIp => { :address => ip }) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#rescue(options = nil) ⇒ Object
Sends an API request to rescue this server.
Returns true if the API call succeeds.
>> server.rescue
=> true
362 363 364 365 366 367 |
# File 'lib/openstack/compute/server.rb', line 362 def rescue( = nil) data = JSON.generate(:rescue => ) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#resize!(flavorRef) ⇒ Object
Resizes the server to the size contained in the server flavor found at ID flavorRef. The server name, ID number, and IP addresses will remain the same. After the resize is done, the server.status will be set to “VERIFY_RESIZE” until the resize is confirmed or reverted.
Refreshes the OpenStack::Compute::Server object, and returns true if the API call succeeds.
>> server.resize!(1)
=> true
225 226 227 228 229 230 231 |
# File 'lib/openstack/compute/server.rb', line 225 def resize!(flavorRef) data = JSON.generate(:resize => {:flavorRef => flavorRef}) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) self.populate true end |
#resume ⇒ Object
Sends an API request to resume this server.
Returns true if the API call succeeds.
>> server.resume
=> true
349 350 351 352 353 354 |
# File 'lib/openstack/compute/server.rb', line 349 def resume data = JSON.generate(:resume => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#revert_resize! ⇒ Object
After a server resize is complete, calling this method will reject the resized server with the OpenStack API, destroying the new image and replacing it with the pre-resize fallback image.
Returns true if the API call succeeds.
>> server.confirm_resize!
=> true
255 256 257 258 259 260 261 262 |
# File 'lib/openstack/compute/server.rb', line 255 def revert_resize! # If the resize bug gets figured out, should put a check here to make sure that it's in the proper state for this. data = JSON.generate(:revertResize => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) self.populate true end |
#start ⇒ Object
Sends an API request to start (resume) the server.
Returns true if the API call succeeds.
>> server.start()
=> true
123 124 125 126 127 128 |
# File 'lib/openstack/compute/server.rb', line 123 def start data = JSON.generate('os-start' => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#stop ⇒ Object
Sends an API request to stop (suspend) the server.
Returns true if the API call succeeds.
>> server.stop()
=> true
110 111 112 113 114 115 |
# File 'lib/openstack/compute/server.rb', line 110 def stop() data = JSON.generate('os-stop' => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#suspend ⇒ Object
Sends an API request to suspend this server.
Returns true if the API call succeeds.
>> server.suspend
=> true
336 337 338 339 340 341 |
# File 'lib/openstack/compute/server.rb', line 336 def suspend data = JSON.generate(:suspend => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#unpause ⇒ Object
Sends an API request to unpause this server.
Returns true if the API call succeeds.
>> server.unpause
=> true
323 324 325 326 327 328 |
# File 'lib/openstack/compute/server.rb', line 323 def unpause data = JSON.generate(:unpause => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#unrescue ⇒ Object
Sends an API request to unrescue this server.
Returns true if the API call succeeds.
>> server.unrescue
=> true
375 376 377 378 379 380 |
# File 'lib/openstack/compute/server.rb', line 375 def unrescue data = JSON.generate(:unrescue => nil) response = @compute.connection.csreq("POST",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}/action",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#update(options) ⇒ Object
Updates various parameters about the server. Currently, the only operations supported are changing the server name (not the actual hostname on the server, but simply the label in the Servers API) and the administrator password (note: changing the admin password will trigger a reboot of the server). Other options are ignored. One or both key/value pairs may be provided. Keys are case-sensitive.
Input hash key values are :name and :adminPass. Returns true if the API call succeeds.
>> server.update(:name => "MyServer", :adminPass => "12345")
=> true
>> server.name
=> "MyServer"
140 141 142 143 144 145 146 147 |
# File 'lib/openstack/compute/server.rb', line 140 def update() data = JSON.generate(:server => ) response = @compute.connection.csreq("PUT",@svrmgmthost,"#{@svrmgmtpath}/servers/#{URI.encode(self.id.to_s)}",@svrmgmtport,@svrmgmtscheme,{'content-type' => 'application/json'},data) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) # If we rename the instance, repopulate the object self.populate if [:name] true end |