Class: OpenStack::Compute::Image
- Inherits:
-
Object
- Object
- OpenStack::Compute::Image
- Defined in:
- lib/openstack/compute/image.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#serverId ⇒ Object
readonly
Returns the value of attribute serverId.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
-
#delete! ⇒ Object
Delete an image.
-
#initialize(connection, id) ⇒ Image
constructor
This class provides an object for the “Image” of a server.
-
#populate ⇒ Object
(also: #refresh)
Makes the HTTP call to load information about the provided image.
Constructor Details
#initialize(connection, id) ⇒ Image
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 OpenStack::Compute::Connection, it will likely not be called directly from user code.
>> cs = OpenStack::Compute::Connection.new(USERNAME,API_KEY)
>> image = cs.get_image(2)
=> #<OpenStack::Compute::Image:0x1015371c0 ...>
>> image.name
=> "CentOS 5.2"
23 24 25 26 27 |
# File 'lib/openstack/compute/image.rb', line 23 def initialize(connection,id) @id = id @connection = connection populate end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
9 10 11 |
# File 'lib/openstack/compute/image.rb', line 9 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/openstack/compute/image.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/openstack/compute/image.rb', line 6 def name @name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
11 12 13 |
# File 'lib/openstack/compute/image.rb', line 11 def progress @progress end |
#serverId ⇒ Object (readonly)
Returns the value of attribute serverId.
7 8 9 |
# File 'lib/openstack/compute/image.rb', line 7 def serverId @serverId end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
10 11 12 |
# File 'lib/openstack/compute/image.rb', line 10 def status @status end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
8 9 10 |
# File 'lib/openstack/compute/image.rb', line 8 def updated @updated end |
Instance Method Details
#delete! ⇒ Object
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
54 55 56 57 58 |
# File 'lib/openstack/compute/image.rb', line 54 def delete! response = @connection.csreq("DELETE",@connection.svrmgmthost,"#{@connection.svrmgmtpath}/images/#{URI.escape(self.id.to_s)}",@connection.svrmgmtport,@connection.svrmgmtscheme) OpenStack::Compute::Exception.raise_exception(response) unless response.code.match(/^20.$/) true end |
#populate ⇒ Object Also known as: refresh
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
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/openstack/compute/image.rb', line 34 def populate response = @connection.csreq("GET",@connection.svrmgmthost,"#{@connection.svrmgmtpath}/images/#{URI.escape(self.id.to_s)}",@connection.svrmgmtport,@connection.svrmgmtscheme) OpenStack::Compute::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 |