def create_instance(credentials, image_id, opts={})
user_data = opts[:user_data] ? Base64.decode64(opts[:user_data]) : nil
if user_data
config_server_address, vm_uuid, vm_otp = opts[:user_data].strip.split(';')
if vm_uuid.nil? and vm_otp.nil?
vm_uuid = config_server_address
config_server_address = nil
end
end
vm_uuid ||= UUIDTools::UUID.random_create.to_s
vm_otp ||= vm_uuid[0..7]
new_client(credentials) do |condor|
config_server_address ||= condor.ip_agent.address
image = images(credentials, :id => image_id).first
hardware_profile = hardware_profiles(credentials, :id => opts[:hwp_id] || 'small').first
instance = condor.launch_instance(image, hardware_profile, {
:name => opts[:name] || "i-#{Time.now.to_i}",
:config_server_address => config_server_address,
:uuid => vm_uuid,
:otp => vm_otp,
}).first
store(:uuid, vm_uuid, instance.id)
raise "Error: VM not launched" unless instance
instance(credentials, { :id => instance.id, :password => vm_otp })
end
end