lib/dcloud/instance.rb in deltacloud-client-0.0.3 vs lib/dcloud/instance.rb in deltacloud-client-0.0.4

- old
+ new

@@ -17,10 +17,37 @@ require 'dcloud/base_model' module DCloud + + class InstanceProfile + attr_reader :hardware_profile, :id + + def initialize(client, xml) + @hardware_profile = HardwareProfile.new(client, xml.attributes['href']) + @properties = {} + @id = xml.text("id") + xml.get_elements('property').each do |prop| + @properties[prop.attributes['name'].to_sym] = { + :value => prop.attributes['value'], + :unit => prop.attributes['unit'], + :kind => prop.attributes['kind'].to_sym + } + end + end + + def [](prop) + p = @properties[prop] + p ? p[:value] : nil + end + + def property(prop) + @properties[prop] + end + end + class Instance < BaseModel xml_tag_name :instance attribute :name @@ -28,13 +55,13 @@ attribute :public_addresses attribute :private_addresses attribute :state attribute :actions attribute :image - attribute :flavor attribute :realm attribute :action_urls + attribute :instance_profile def initialize(client, uri, xml=nil) @action_urls = {} super( client, uri, xml ) end @@ -69,10 +96,17 @@ throw Exception.new( "Unable to stop" ) unless url client.post_instance( url ) unload end + def destroy!() + url = action_urls['destroy'] + throw Exception.new( "Unable to destroy" ) unless url + client.post_instance( url ) + unload + end + def load_payload(xml=nil) super(xml) unless xml.nil? @owner_id = xml.text('owner_id') @name = xml.text('name') @@ -84,16 +118,16 @@ xml.get_elements( 'private-addresses/address' ).each do |address| @private_addresses << address.text end image_uri = xml.get_elements( 'image' )[0].attributes['href'] @image = Image.new( @client, image_uri ) - flavor_uri = xml.get_elements( 'flavor' )[0].attributes['href'] - @flavor = Flavor.new( @client, flavor_uri ) # Only use realms if they are there if (!xml.get_elements( 'realm' ).empty?) realm_uri = xml.get_elements( 'realm' )[0].attributes['href'] @realm = Realm.new( @client, realm_uri ) end + instance_profile = xml.get_elements( 'hardware-profile' ).first + @instance_profile = InstanceProfile.new( @client, instance_profile ) @state = xml.text( 'state' ) @actions = [] xml.get_elements( 'actions/link' ).each do |link| action_name = link.attributes['rel'] if ( action_name )