diff --git a/src/cloud/ec2/bin/econe-run-instances b/src/cloud/ec2/bin/econe-run-instances index e2d33ecf2c..5976650a6f 100755 --- a/src/cloud/ec2/bin/econe-run-instances +++ b/src/cloud/ec2/bin/econe-run-instances @@ -68,6 +68,7 @@ opts = GetoptLong.new( ['--secret-key', '-S',GetoptLong::REQUIRED_ARGUMENT], ['--url', '-U',GetoptLong::REQUIRED_ARGUMENT], ['--type', '-t',GetoptLong::REQUIRED_ARGUMENT], + ['--user-data', '-d',GetoptLong::REQUIRED_ARGUMENT], ['--headers', '-H',GetoptLong::NO_ARGUMENT] ) @@ -77,6 +78,7 @@ access = nil secret = nil auth = nil type = nil +user_data = nil begin opts.each do |opt, arg| @@ -93,6 +95,8 @@ begin type = arg when '--headers' headers = true + when '--user-data' + user_data = arg end end rescue Exception => e @@ -119,7 +123,7 @@ rescue Exception => e exit -1 end -rc = ec2_client.run_instances(image_id,type) +rc = ec2_client.run_instances(image_id,type, user_data) if CloudClient::is_error?(rc) puts "#{cmd_name}: #{rc.message}" diff --git a/src/cloud/ec2/lib/EC2QueryClient.rb b/src/cloud/ec2/lib/EC2QueryClient.rb index 0f0e56ae92..aa08866075 100644 --- a/src/cloud/ec2/lib/EC2QueryClient.rb +++ b/src/cloud/ec2/lib/EC2QueryClient.rb @@ -97,13 +97,15 @@ module EC2QueryClient # :image_id # :instance_type ###################################################################### - def run_instances(ami_id, type) + def run_instances(ami_id, type, user_data=nil) begin response = @ec2_connection.run_instances( - :image_id => ami_id, - :min_count => 1, - :max_count => 1, - :instance_type => type + :image_id => ami_id, + :min_count => 1, + :max_count => 1, + :instance_type => type, + :user_data => user_data, + :base64_encoded => true ) rescue Exception => e error = CloudClient::Error.new(e.message) diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb index 234610548e..c07e766a0b 100644 --- a/src/cloud/ec2/lib/EC2QueryServer.rb +++ b/src/cloud/ec2/lib/EC2QueryServer.rb @@ -211,11 +211,14 @@ class EC2QueryServer < CloudServer # Build the VM erb_vm_info=Hash.new + erb_vm_info[:img_path] = image.path erb_vm_info[:img_id] = params['ImageId'] erb_vm_info[:instance_type] = instance_type_name erb_vm_info[:template] = @config[:template_location] + "/#{instance_type['TEMPLATE']}" + erb_vm_info[:user_data] = params['UserData'] + template = ERB.new(File.read(erb_vm_info[:template])) template_text = template.result(binding) diff --git a/src/cloud/ec2/lib/econe-server.rb b/src/cloud/ec2/lib/econe-server.rb index 58f8f668a5..9fbc06f46e 100644 --- a/src/cloud/ec2/lib/econe-server.rb +++ b/src/cloud/ec2/lib/econe-server.rb @@ -75,6 +75,8 @@ helpers do message = 'Specified AMI ID does not exist' when 'Unsupported' message = 'The instance type or feature is not supported in your requested Availability Zone.' + else + message = code end xml = ""+