class CloudServers::Image

Attributes

created[R]
id[R]
name[R]
progress[R]
serverId[R]
status[R]
updated[R]

Public Class Methods

new(connection,id) click to toggle source

This class provides an object for the “Image” of a server. The Image refers to the Operating System type and version.

Returns the Image object identifed by the supplied ID number. Called from the get_image instance method of CloudServers::Connection, it will likely not be called directly from user code.

>> cs = CloudServers::Connection.new(USERNAME,API_KEY)
>> image = cs.get_image(2)
=> #<CloudServers::Image:0x1015371c0 ...>
>> image.name
=> "CentOS 5.2"
# File lib/cloudservers/image.rb, line 22
def initialize(connection,id)
  @id = id
  @connection = connection
  populate
end

Public Instance Methods

delete!() click to toggle source

Delete an image. This should be returning invalid permissions when attempting to delete system images, but it's not. Returns true if the deletion succeeds.

>> image.delete!
=> true
# File lib/cloudservers/image.rb, line 53
def delete!
  response = @connection.csreq("DELETE",@connection.svrmgmthost,"#{@connection.svrmgmtpath}/images/#{URI.escape(self.id.to_s)}",@connection.svrmgmtport,@connection.svrmgmtscheme)
  CloudServers::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  true
end
populate() click to toggle source

Makes the HTTP call to load information about the provided image. Can also be called directly on the Image object to refresh data. Returns true if the refresh call succeeds.

>> image.populate
=> true
# File lib/cloudservers/image.rb, line 33
def populate
  response = @connection.csreq("GET",@connection.svrmgmthost,"#{@connection.svrmgmtpath}/images/#{URI.escape(self.id.to_s)}",@connection.svrmgmtport,@connection.svrmgmtscheme)
  CloudServers::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  data = JSON.parse(response.body)['image']
  @id = data['id']
  @name = data['name']
  @serverId = data['serverId']
  @updated = DateTime.parse(data['updated'])
  @created = DateTime.parse(data['created'])
  @status = data['status']
  @progress = data['progress']
  return true
end
Also aliased as: refresh
refresh()
Alias for: populate