Class: OpenStack::Nova::Compute::Image

Inherits:
BaseDetail show all
Defined in:
lib/open_stack/nova/compute/image.rb

Overview

An OpenStack Image

Attributes

  • name - Name of this image

  • tenant_id - Tenant id to which this image belongs to (if applicable)

  • server_id - Server id to which this image belongs to (if applicable)

  • user_id - User id to which this image belongs to (if applicable)

  • status - Status of image (e.g. ACTIVE)

  • progress - Progress of image

  • min_disk - Minimal amount of storage needed by this image (GBytes)

  • min_ram - Minimal amount of RAM needed by this image (MBytes)

  • updated_at - Modification date

  • created_at - Creation date

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDetail

collection_path, collection_path_create, #collection_path_create

Methods inherited from Base

site, site=

Methods inherited from Common

collection_path, custom_method_collection_url, element_path

Methods inherited from Base

headers

Methods inherited from ActiveResource::Base

#load

Constructor Details

#initialize(attributes = {}, persisted = false) ⇒ Image

:notnew:



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/open_stack/nova/compute/image.rb', line 49

def initialize(attributes = {}, persisted = false) # :notnew:
  attributes = attributes.with_indifferent_access
  new_attributes = {
      :id => attributes[:id],
      :name => attributes[:name],
      :min_ram => attributes[:minRam],
      :min_disk => attributes[:minDisk],
      :progress => attributes[:progress],
      :status => attributes[:status],
      :metadata => attributes[:metadata],
      :user_id => attributes[:user_id],
      :tenant_id => attributes[:tenant_id],
      :server_id => attributes[:server].present? ? attributes[:server][:id] : nil,
      :updated_at => attributes[:updated].present? ? DateTime.strptime(attributes[:updated], OpenStack::DATETIME_FORMAT) : nil,
      :created_at => attributes[:created].present? ? DateTime.strptime(attributes[:created], OpenStack::DATETIME_FORMAT) : nil
  }

  super(new_attributes, persisted)
end

Class Method Details

.find_all_by_name(name) ⇒ Object

Returns the list of Image instances with the specified name

Attributes

  • name : A string



73
74
75
# File 'lib/open_stack/nova/compute/image.rb', line 73

def self.find_all_by_name(name)
  all.reject! { |image| image.name != name }
end

.find_by_name(name) ⇒ Object

Returns the first Image instance with the specified name

Attributes

  • name : A string



81
82
83
# File 'lib/open_stack/nova/compute/image.rb', line 81

def self.find_by_name(name)
  all.detect { |image| image.name == name }
end

Instance Method Details

#image_typeObject

Returns the type of image: image or snapshot



91
92
93
94
95
# File 'lib/open_stack/nova/compute/image.rb', line 91

def image_type
  .image_type
rescue NoMethodError
  'image'
end

#serverObject

Returns the Server instance to which this image belongs to (if applicable)



86
87
88
# File 'lib/open_stack/nova/compute/image.rb', line 86

def server
  Server.find(server_id) if server_id.present?
end

#snapshot?Boolean

True if this image is a snapshot

Returns:

  • (Boolean)


98
99
100
# File 'lib/open_stack/nova/compute/image.rb', line 98

def snapshot?
  image_type != 'image'
end