Class: Deltacloud::Drivers::Terremark::TerremarkDriver

Inherits:
BaseDriver
  • Object
show all
Defined in:
lib/deltacloud/drivers/terremark/terremark_driver.rb

Constant Summary collapse

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

Instance Method Summary collapse

Methods inherited from BaseDriver

#blob, #bucket, #catched_exceptions_list, declare_feature, define_hardware_profile, define_instance_states, feature, feature_decl_for, feature_decls, #features, features, #features_for_operation, #filter_hardware_profiles, #filter_on, #find_hardware_profile, #hardware_profile, #hardware_profiles, hardware_profiles, #has_capability?, #has_collection?, #image, #instance, #instance_actions_for, #instance_state_machine, instance_state_machine, #key, #realm, #storage_snapshot, #storage_volume, #supported_collections

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
# 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'] #name could be nil or length 0 or too long
  name = "inst#{Time.now.to_i}" if (name.nil? || (name.length == 0))
  name = name.slice(0..13) #name < 15 chars (says terremark)
  unless ( (terremark_hwp.include?(:cpu, opts[:hwp_cpu].to_i)) &&
            (terremark_hwp.include?(:memory, opts[:hwp_memory].to_i)) ) then
     raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["cpu"]), "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



187
188
189
190
191
192
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 187

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 –



156
157
158
159
160
161
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 156

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 –



166
167
168
169
170
171
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 166

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 –



176
177
178
179
180
181
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 176

def stop_instance(credentials, id)
  safely do
    terremark_client = new_client(credentials)
    return terremark_client.power_shutdown(id)
  end
end

#valid_credentials?(credentials) ⇒ Boolean

Returns:

  • (Boolean)


194
195
196
197
198
199
200
201
# File 'lib/deltacloud/drivers/terremark/terremark_driver.rb', line 194

def valid_credentials?(credentials)
  begin
    new_client(credentials)
  rescue Deltacloud::AuthException
    return false
  end
  true
end