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.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#minDisk ⇒ Object
readonly
Returns the value of attribute minDisk.
-
#minRam ⇒ Object
readonly
Returns the value of attribute minRam.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#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(compute, 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(compute, 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"
28 29 30 31 32 |
# File 'lib/openstack/compute/image.rb', line 28 def initialize(compute,id) @id = id @compute = compute populate end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
11 12 13 |
# File 'lib/openstack/compute/image.rb', line 11 def created @created end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/openstack/compute/image.rb', line 7 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
16 17 18 |
# File 'lib/openstack/compute/image.rb', line 16 def @metadata end |
#minDisk ⇒ Object (readonly)
Returns the value of attribute minDisk.
13 14 15 |
# File 'lib/openstack/compute/image.rb', line 13 def minDisk @minDisk end |
#minRam ⇒ Object (readonly)
Returns the value of attribute minRam.
14 15 16 |
# File 'lib/openstack/compute/image.rb', line 14 def minRam @minRam end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/openstack/compute/image.rb', line 8 def name @name end |
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
15 16 17 |
# File 'lib/openstack/compute/image.rb', line 15 def progress @progress end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
9 10 11 |
# File 'lib/openstack/compute/image.rb', line 9 def server @server end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/openstack/compute/image.rb', line 12 def status @status end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
10 11 12 |
# File 'lib/openstack/compute/image.rb', line 10 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
65 66 67 68 69 |
# File 'lib/openstack/compute/image.rb', line 65 def delete! response = @compute.connection.csreq("DELETE",@compute.connection.service_host,"#{@compute.connection.service_path}/images/#{URI.escape(self.id.to_s)}",@compute.connection.service_port,@compute.connection.service_scheme) OpenStack::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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/openstack/compute/image.rb', line 39 def populate path = "/images/#{URI.escape(self.id.to_s)}" response = @compute.connection.req("GET", path) OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/) data = JSON.parse(response.body)['image'] @id = data['id'] @name = data['name'] @server = data['server'] if data['updated'] then @updated = DateTime.parse(data['updated']) end @created = DateTime.parse(data['created']) @metadata = OpenStack::Compute::Metadata.new(@compute, path, data['metadata']) @status = data['status'] @minDisk = data['minDisk'] @minRam = data['minRam'] @progress = data['progress'] return true end |