Class: DeltacloudVM::Client::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/deltacloud_vm/client/models/image.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#description, #name, #obj_id, #url

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#client, #connection, convert, #entrypoint, from_collection, #id, #initialize, #original_body, #to_s, #update_instance_variables!, validate_attrs!

Methods included from Helpers::XmlHelper

#extract_xml_body

Methods included from Methods::Api

#api_uri, #current_driver, #current_provider, #feature?, #features, #must_support!, #path, #support?, #supported_collections, #version

Methods included from Helpers::Model

#error, #from_collection, #from_resource, #model

Constructor Details

This class inherits a constructor from DeltacloudVM::Client::Base

Instance Attribute Details

#architectureObject (readonly)

Returns the value of attribute architecture.



19
20
21
# File 'lib/deltacloud_vm/client/models/image.rb', line 19

def architecture
  @architecture
end

#creation_timeObject (readonly)

Returns the value of attribute creation_time.



20
21
22
# File 'lib/deltacloud_vm/client/models/image.rb', line 20

def creation_time
  @creation_time
end

#hardware_profile_idsObject (readonly)

Returns the value of attribute hardware_profile_ids.



20
21
22
# File 'lib/deltacloud_vm/client/models/image.rb', line 20

def hardware_profile_ids
  @hardware_profile_ids
end

#owner_idObject (readonly)

Returns the value of attribute owner_id.



19
20
21
# File 'lib/deltacloud_vm/client/models/image.rb', line 19

def owner_id
  @owner_id
end

#root_typeObject (readonly)

Returns the value of attribute root_type.



20
21
22
# File 'lib/deltacloud_vm/client/models/image.rb', line 20

def root_type
  @root_type
end

#stateObject (readonly)

Returns the value of attribute state.



19
20
21
# File 'lib/deltacloud_vm/client/models/image.rb', line 19

def state
  @state
end

Class Method Details

.parse(xml_body) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/deltacloud_vm/client/models/image.rb', line 47

def self.parse(xml_body)
  {
    :owner_id =>        xml_body.text_at(:owner_id),
    :architecture =>    xml_body.text_at(:architecture),
    :state =>           xml_body.text_at(:state),
    :creation_time =>   xml_body.text_at('creation_time'),
    :root_type =>       xml_body.text_at('root_type'),
    :hardware_profile_ids => xml_body.xpath('hardware_profiles/hardware_profile').map { |h|
      h['id']
    }
  }
end

Instance Method Details

#hardware_profilesObject



22
23
24
# File 'lib/deltacloud_vm/client/models/image.rb', line 22

def hardware_profiles
  @client.hardware_profiles.select { |hwp| @hardware_profile_ids.include?(hwp._id) }
end

#is_compatible?(hardware_profile_id) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/deltacloud_vm/client/models/image.rb', line 26

def is_compatible?(hardware_profile_id)
  hardware_profile_ids.include? hardware_profile_id
end

#launch(create_instance_opts = {}) ⇒ Object

Launch the image using Instance#create_instance method. This method is more strict in checking HardwareProfile and in case you use incompatible HWP it raise an error.

  • create_instance_opts -> create_instance options



36
37
38
39
40
41
42
43
44
45
# File 'lib/deltacloud_vm/client/models/image.rb', line 36

def launch(create_instance_opts={})

  if hwp_id = create_instance_opts[:hwp_id]
    raise error(:incompatible_hardware_profile).new(
      "Profile '#{hwp_id}' is not compatible with this image."
    ) unless is_compatible?(hwp_id)
  end

  @client.create_instance(self._id, create_instance_opts)
end