Class: Fog::Compute::RackspaceV2::Image

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/rackspace/models/compute_v2/image.rb

Constant Summary collapse

UNKNOWN =
'UNKNOWN'
ACTIVE =
'ACTIVE'
SAVING =
'SAVING'
ERROR =
'ERROR'
DELETED =
'DELETED'

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ Image

Returns a new instance of Image.



29
30
31
32
# File 'lib/fog/rackspace/models/compute_v2/image.rb', line 29

def initialize(attributes={})
  @connection = attributes[:connection]
  super
end

Instance Method Details

#destroyObject



58
59
60
61
# File 'lib/fog/rackspace/models/compute_v2/image.rb', line 58

def destroy
  requires :identity
  service.delete_image(identity)
end

#metadataObject



34
35
36
37
38
39
40
41
42
# File 'lib/fog/rackspace/models/compute_v2/image.rb', line 34

def 
  raise "Please save image before accessing metadata" unless identity          
  @metadata ||= begin
    Fog::Compute::RackspaceV2::Metadata.new({
      :connection => connection,
      :parent => self
    })
  end
end

#metadata=(hash = {}) ⇒ Object



44
45
46
47
# File 'lib/fog/rackspace/models/compute_v2/image.rb', line 44

def metadata=(hash={})
  raise "Please save image before accessing metadata" unless identity
  .from_hash(hash)
end

#ready?(ready_state = ACTIVE, error_states = [ERROR]) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'lib/fog/rackspace/models/compute_v2/image.rb', line 49

def ready?(ready_state = ACTIVE, error_states=[ERROR])
  if error_states
    error_states = Array(error_states)
    raise "Image should have transitioned to '#{ready_state}' not '#{state}'" if error_states.include?(state)
  end
  state == ready_state
end