Skip to content

Commit

Permalink
Merge pull request #135 from opscode/adamed-KNIFE-160-placement-group…
Browse files Browse the repository at this point in the history
…-option

KNIFE-160: Add support for EC2 Placement Groups when creating new instances
  • Loading branch information
Adam Edwards committed Jul 25, 2013
2 parents 169350a + 07a39b5 commit 9f20ce4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/chef/knife/ec2_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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...]",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/unit/ec2_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -189,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)
Expand Down Expand Up @@ -398,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
Expand Down

0 comments on commit 9f20ce4

Please sign in to comment.