# File lib/deltacloud/drivers/terremark/terremark_driver.rb, line 131
  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::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