def create_instance(credentials, image_id, opts)
new_vapp = nil
vapp_opts = {}
terremark_hwp = hardware_profiles(credentials, {:name => 'default'}).first
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)
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)
end
end