Class: Deltacloud::Drivers::Terremark::TerremarkDriver
- Inherits:
-
BaseDriver
- Object
- BaseDriver
- Deltacloud::Drivers::Terremark::TerremarkDriver
- Defined in:
- lib/deltacloud/drivers/terremark/terremark_driver.rb
Constant Summary collapse
- USER_NAME_MAX =
constraints(:collection => :instances, :feature => :user_name)[:max_length]
- VAPP_STATE_MAP =
– Vapp State Map… for use with convert_instance (get an integer back from terremark) –
{ "0" => "PENDING", "1" => "PENDING", "2" => "STOPPED", "4" => "RUNNING" }
Constants inherited from BaseDriver
BaseDriver::MEMBER_SHOW_METHODS, BaseDriver::STATE_MACHINE_OPTS
Instance Method Summary collapse
-
#create_instance(credentials, image_id, opts) ⇒ Object
– CREATE INSTANCE – launch a vapp template.
-
#destroy_instance(credentials, id) ⇒ Object
– DESTROY INSTANCE – shuts down…
-
#images(credentials, opts = nil) ⇒ Object
– IMAGES – aka “vapp_templates”.
-
#instances(credentials, opts = nil) ⇒ Object
– INSTANCES – aka vApps.
-
#realms(credentials, opts = nil) ⇒ Object
– REALMS – only one realm…
-
#reboot_instance(credentials, id) ⇒ Object
– REBOOT INSTANCE –.
-
#start_instance(credentials, id) ⇒ Object
– START INSTANCE –.
-
#stop_instance(credentials, id) ⇒ Object
– STOP INSTANCE –.
- #valid_credentials?(credentials) ⇒ Boolean
Methods inherited from BaseDriver
#address, #api_provider, #blob, #bucket, #catched_exceptions_list, #configured_providers, constraints, define_hardware_profile, define_instance_states, driver_name, feature, features, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #firewall, #hardware_profile, #hardware_profiles, hardware_profiles, #has_capability?, #has_feature?, has_feature?, #image, #instance, #instance_actions_for, #instance_state_machine, instance_state_machine, #key, #name, #realm, #storage_snapshot, #storage_volume, #supported_collections
Methods included from Exceptions
exception_from_status, exceptions, included, logger, #safely
Instance Method Details
#create_instance(credentials, image_id, opts) ⇒ Object
– CREATE INSTANCE – launch a vapp template. Needs a name, ram, no. cpus, id of vapp_template
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 129 def create_instance(credentials, image_id, opts) new_vapp = nil vapp_opts = {} #assemble options to pass to Fog::Terremark::Real.instantiate_vapp_template terremark_hwp = hardware_profiles(credentials, {:name => 'default'}).first #sanity check values against default name = opts[:name] if not name name = "inst#{Time.now.to_i}" end if name.length > USER_NAME_MAX raise "Parameter name must be #{USER_NAME_MAX} characters or less" end unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) && (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then raise Deltacloud::Exceptions::ValidationFailure.new( StandardError.new("Error with cpu and/or memory values. you said cpu->#{opts[:hwp_cpu]} and mem->#{opts[:hwp_memory]}") ) end vapp_opts['cpus'] = opts[:hwp_cpu] vapp_opts['memory'] = opts[:hwp_memory] safely do terremark_client = new_client(credentials) ####### #FIXME# what happens if there is an issue getting the new vapp id? (eg even though created succesfully) ####### vapp_id = terremark_client.instantiate_vapp_template(name, image_id, vapp_opts).body['href'].split('/').last new_vapp = terremark_client.get_vapp(vapp_id) return convert_instance(new_vapp, terremark_client, credentials.user) #return an Instance object end end |
#destroy_instance(credentials, id) ⇒ Object
– DESTROY INSTANCE – shuts down… in terremark need to do a futher delete to get rid of a vapp entirely
193 194 195 196 197 198 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 193 def destroy_instance(credentials, id) safely do terremark_client = new_client(credentials) return terremark_client.delete_vapp(id) end end |
#images(credentials, opts = nil) ⇒ Object
– IMAGES – aka “vapp_templates”
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 57 def images(credentials, opts=nil) image_list = [] terremark_client = new_client(credentials) safely do vdc_id = terremark_client.default_vdc_id catalogItems = terremark_client.get_catalog(vdc_id).body['CatalogItems'] catalogItems.each{ |catalog_item| current_item_id = catalog_item['href'].split('/').last current_item = terremark_client.get_catalog_item(current_item_id).body['Entity'] if(current_item['type'] == 'application/vnd.vmware.vcloud.vAppTemplate+xml') image_list << convert_image(current_item, credentials.user) end } #end of catalogItems.each end image_list = filter_on( image_list, :id, opts ) image_list = filter_on( image_list, :architecture, opts ) image_list = filter_on( image_list, :owner_id, opts ) image_list end |
#instances(credentials, opts = nil) ⇒ Object
– INSTANCES – aka vApps
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 93 def instances(credentials, opts=nil) instances = [] terremark_client = new_client(credentials) safely do vdc_items = terremark_client.get_vdc(terremark_client.default_vdc_id()).body['ResourceEntities'] vdc_items.each{|current_item| if(current_item['type'] == 'application/vnd.vmware.vcloud.vApp+xml') vapp_id = current_item['href'].split('/').last vapp = terremark_client.get_vapp(vapp_id) instances << convert_instance(vapp, terremark_client, credentials.user) end }#end vdc_items.each end instances = filter_on( instances, :id, opts ) instances end |
#realms(credentials, opts = nil) ⇒ Object
– REALMS – only one realm… everything in US?
81 82 83 84 85 86 87 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 81 def realms(credentials, opts=nil) [Realm.new( { :id=>"US-Miami", :name=>"United States - Miami", :state=> "AVAILABLE" } )] end |
#reboot_instance(credentials, id) ⇒ Object
– REBOOT INSTANCE –
162 163 164 165 166 167 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 162 def reboot_instance(credentials, id) safely do terremark_client = new_client(credentials) return terremark_client.power_reset(id) end end |
#start_instance(credentials, id) ⇒ Object
– START INSTANCE –
172 173 174 175 176 177 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 172 def start_instance(credentials, id) safely do terremark_client = new_client(credentials) return terremark_client.power_on(id) end end |
#stop_instance(credentials, id) ⇒ Object
– STOP INSTANCE –
182 183 184 185 186 187 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 182 def stop_instance(credentials, id) safely do terremark_client = new_client(credentials) return terremark_client.power_shutdown(id) end end |
#valid_credentials?(credentials) ⇒ Boolean
200 201 202 203 204 205 206 207 |
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 200 def valid_credentials?(credentials) begin new_client(credentials) rescue return false end true end |