From 132228afe4669a4b4fc2b40ebc44ebfb1e48397f Mon Sep 17 00:00:00 2001 From: Fred Sadaghiani Date: Wed, 31 Oct 2012 12:51:38 -0700 Subject: [PATCH 1/2] Add support for specifying an EC2 placement group when spinning up a new machine --- lib/chef/knife/ec2_server_create.rb | 7 +++++++ spec/unit/ec2_server_create_spec.rb | 1 + 2 files changed, 8 insertions(+) diff --git a/lib/chef/knife/ec2_server_create.rb b/lib/chef/knife/ec2_server_create.rb index e37c89fb..563662fc 100644 --- a/lib/chef/knife/ec2_server_create.rb +++ b/lib/chef/knife/ec2_server_create.rb @@ -67,6 +67,11 @@ class Ec2ServerCreate < Knife :long => "--associate-eip IP_ADDRESS", :description => "Associate existing elastic IP address with instance after launch" + option :placement_group, + :long => "--placement-group PLACEMENT_GROUP", + :description => "The placement group to place a cluster compute instance", + :proc => Proc.new { |pg| Chef::Config[:knife][:placement_group] = pg } + option :tags, :short => "-T T=V[,T=V,...]", :long => "--tags Tag=Value[,Tag=Value...]", @@ -418,6 +423,7 @@ def run puts "\n" msg_pair("Instance ID", @server.id) msg_pair("Flavor", @server.flavor_id) + msg_pair("Placement Group", @server.placement_group) unless @server.placement_group.nil? msg_pair("Image", @server.image_id) msg_pair("Region", connection.instance_variable_get(:@region)) msg_pair("Availability Zone", @server.availability_zone) @@ -595,6 +601,7 @@ def create_server_def } server_def[:subnet_id] = locate_config_value(:subnet_id) if vpc_mode? server_def[:private_ip_address] = locate_config_value(:private_ip_address) if vpc_mode? + server_def[:placement_group] = locate_config_value(:placement_group) if Chef::Config[:knife][:aws_user_data] begin diff --git a/spec/unit/ec2_server_create_spec.rb b/spec/unit/ec2_server_create_spec.rb index 14eb5bf9..6d9f254f 100644 --- a/spec/unit/ec2_server_create_spec.rb +++ b/spec/unit/ec2_server_create_spec.rb @@ -54,6 +54,7 @@ @ec2_server_attribs = { :id => 'i-39382318', :flavor_id => 'm1.small', :image_id => 'ami-47241231', + :placement_group => 'some_placement_group', :availability_zone => 'us-west-1', :key_name => 'my_ssh_key', :groups => ['group1', 'group2'], From 07a39b528c94e61e6c9c231f8683a4c14fb0b99f Mon Sep 17 00:00:00 2001 From: Fred Sadaghiani Date: Wed, 30 Jan 2013 20:54:27 -0800 Subject: [PATCH 2/2] Add tests and update Gemfile to include dependencies --- Rakefile | 3 ++- spec/unit/ec2_server_create_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 4a1b21b4..9c491aaa 100644 --- a/Rakefile +++ b/Rakefile @@ -27,8 +27,9 @@ require 'rdoc/task' begin require 'sdoc' + require 'rdoc/task' - Rake::RDocTask.new do |rdoc| + RDoc::Task.new do |rdoc| rdoc.title = "Chef Ruby API Documentation" rdoc.main = "README.rdoc" rdoc.options << '--fmt' << 'shtml' # explictly set shtml generator diff --git a/spec/unit/ec2_server_create_spec.rb b/spec/unit/ec2_server_create_spec.rb index 6d9f254f..b728cdbf 100644 --- a/spec/unit/ec2_server_create_spec.rb +++ b/spec/unit/ec2_server_create_spec.rb @@ -190,6 +190,7 @@ @knife_ec2_create.run end end + describe "when setting tags" do before do Fog::Compute::AWS.should_receive(:new).and_return(@ec2_connection) @@ -399,6 +400,13 @@ Fog::Compute::AWS.stub(:new).and_return(@ec2_connection) end + it "sets the specified placement_group" do + @knife_ec2_create.config[:placement_group] = ['some_placement_group'] + server_def = @knife_ec2_create.create_server_def + + server_def[:placement_group].should == ['some_placement_group'] + end + it "sets the specified security group names" do @knife_ec2_create.config[:security_groups] = ['groupname'] server_def = @knife_ec2_create.create_server_def