Class: DCloud::Instance
Instance Attribute Summary
Attributes inherited from BaseModel
Instance Method Summary collapse
- #destroy! ⇒ Object
-
#initialize(client, uri, xml = nil) ⇒ Instance
constructor
A new instance of Instance.
- #load_payload(xml = nil) ⇒ Object
- #reboot! ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #to_plain ⇒ Object
Methods inherited from BaseModel
attribute, build_reader, #id, xml_tag_name
Constructor Details
#initialize(client, uri, xml = nil) ⇒ Instance
Returns a new instance of Instance.
64 65 66 67 |
# File 'lib/dcloud/instance.rb', line 64 def initialize(client, uri, xml=nil) @action_urls = {} super( client, uri, xml ) end |
Instance Method Details
#destroy! ⇒ Object
101 102 103 104 105 106 |
# File 'lib/dcloud/instance.rb', line 101 def destroy!() url = action_urls['destroy'] throw Exception.new( "Unable to destroy" ) unless url client.post_instance( url ) unload end |
#load_payload(xml = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/dcloud/instance.rb', line 108 def load_payload(xml=nil) super(xml) unless xml.nil? @owner_id = xml.text('owner_id') @name = xml.text('name') @public_addresses = [] xml.get_elements( 'public-addresses/address' ).each do |address| @public_addresses << address.text end @private_addresses = [] 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 ) # 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 ) @actions << link.attributes['rel'] @action_urls[ link.attributes['rel'] ] = link.attributes['href'] end end end end |
#reboot! ⇒ Object
87 88 89 90 91 92 |
# File 'lib/dcloud/instance.rb', line 87 def reboot!() url = action_urls['reboot'] throw Exception.new( "Unable to reboot" ) unless url client.post_instance( url ) unload end |
#start! ⇒ Object
80 81 82 83 84 85 |
# File 'lib/dcloud/instance.rb', line 80 def start!() url = action_urls['start'] throw Exception.new( "Unable to start" ) unless url client.post_instance( url ) unload end |
#stop! ⇒ Object
94 95 96 97 98 99 |
# File 'lib/dcloud/instance.rb', line 94 def stop!() url = action_urls['stop'] throw Exception.new( "Unable to stop" ) unless url client.post_instance( url ) unload end |
#to_plain ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dcloud/instance.rb', line 69 def to_plain sprintf("%-15s | %-15s | %-15s | %10s | %32s | %32s", self.id ? self.id[0,15] : '-', self.name ? self.name[0,15] : 'unknown', self.image.name ? self.image.name[0,15] : 'unknown', self.state ? self.state.to_s[0,10] : 'unknown', self.public_addresses.join(',')[0,32], self.private_addresses.join(',')[0,32] ) end |