From 7aea64f2a662f4929cabe42ec0c3c155bc51e2b3 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Fri, 5 Oct 2012 13:12:20 +0200 Subject: [PATCH] feature #1508: Add --keypair option to econe-run-instances (cherry picked from commit 8a0dbcd9965def8f4ff19e533b03f13f048729f5) --- src/cloud/ec2/bin/econe-run-instances | 22 ++++++++++++++++------ src/cloud/ec2/lib/EC2QueryClient.rb | 15 ++++++--------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/cloud/ec2/bin/econe-run-instances b/src/cloud/ec2/bin/econe-run-instances index 598bc1df70..71e9eb7e1e 100755 --- a/src/cloud/ec2/bin/econe-run-instances +++ b/src/cloud/ec2/bin/econe-run-instances @@ -51,6 +51,14 @@ TYPE = { :format => String } +KEYNAME = { + :name => "keypair", + :short => "-k keypair", + :large => "--keypair keypair", + :description => "The name of the key pair.", + :format => String +} + INSTANCE_COUNT = { :name => "instance_count", :large => "--instance-count count", @@ -110,7 +118,8 @@ EOT EC2QueryClient::URL, USER_DATA, INSTANCE_COUNT, - TYPE + TYPE, + KEYNAME ] main :image_id do @@ -129,11 +138,12 @@ EOT options[:max_count] ||= options[:min_count] rc = ec2_client.run_instances( - args[0], - options[:type], - options[:user_data], - options[:min_count], - options[:max_count]) + :image_id => args[0], + :instance_type => options[:type], + :user_data => options[:user_data], + :min_count => options[:min_count], + :max_count => options[:max_count], + :key_name => options[:keypair]) if CloudClient::is_error?(rc) exit_with_code -1, "#{cmd_name}: #{rc.message}" diff --git a/src/cloud/ec2/lib/EC2QueryClient.rb b/src/cloud/ec2/lib/EC2QueryClient.rb index 28a3cc33a5..15cba23aef 100644 --- a/src/cloud/ec2/lib/EC2QueryClient.rb +++ b/src/cloud/ec2/lib/EC2QueryClient.rb @@ -133,16 +133,13 @@ module EC2QueryClient # :image_id # :instance_type ###################################################################### - def run_instances(ami_id, type, user_data=nil, min_count=1, max_count=1) + def run_instances(opts) begin - response = @ec2_connection.run_instances( - :image_id => ami_id, - :instance_type => type, - :user_data => user_data, - :base64_encoded => true, - :min_count => min_count, - :max_count => max_count - ) + response = @ec2_connection.run_instances({ + :base64_encoded => true, + :min_count => 1, + :max_count => 1 + }.merge(opts)) rescue Exception => e error = CloudClient::Error.new(e.message) return error