Skip to content

Commit

Permalink
Merge pull request #108 from opscode/sid-availability-zone-support
Browse files Browse the repository at this point in the history
[knife-cloud] KNIFE-428 Basic availability zones support
  • Loading branch information
kaustubh-d committed May 29, 2014
2 parents 1a8d4a9 + a9fd8be commit 8aaa622
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lib/chef/knife/cloud/openstack_server_create_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def self.included(includer)
:default => true,
:description => "Use first available network for bootstrapping if 'public' and 'private' are unavailable."

option :availability_zone,
:short => "-Z ZONE_NAME",
:long => "--availability-zone ZONE_NAME",
:description => "The availability zone for this server",
:proc => Proc.new { |z| Chef::Config[:knife][:availability_zone] = z }

end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def before_exec_command
:image_ref => locate_config_value(:image),
:flavor_ref => locate_config_value(:flavor),
:security_groups => locate_config_value(:openstack_security_groups),
:availability_zone => locate_config_value(:availability_zone),
:key_name => locate_config_value(:openstack_ssh_key_id)
},
:server_create_timeout => locate_config_value(:server_create_timeout)
Expand All @@ -62,7 +63,8 @@ def before_exec_command
{:label => 'Flavor', :key => 'flavor', :value_callback => method(:get_id)},
{:label => 'Image', :key => 'image', :value_callback => method(:get_id)},
{:label => 'Keypair', :key => 'key_name'},
{:label => 'State', :key => 'state'}
{:label => 'State', :key => 'state'},
{:label => 'Availability Zone', :key => 'availability_zone'}
]
super
end
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/knife/openstack_server_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def before_exec_command
{:label => 'Flavor', :key => 'flavor', :value_callback => method(:get_id)},
{:label => 'Image', :key => 'image', :value_callback => method(:get_id)},
{:label => 'Keypair', :key => 'key_name'},
{:label => 'State', :key => 'state'}
{:label => 'State', :key => 'state'},
{:label => 'Availability Zone', :key => 'availability_zone'}
]
super
end
Expand Down
3 changes: 2 additions & 1 deletion lib/chef/knife/openstack_server_show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def before_exec_command
{:label => 'Flavor', :key => 'flavor', :value_callback => method(:get_id)},
{:label => 'Image', :key => 'image', :value_callback => method(:get_id)},
{:label => 'Keypair', :key => 'key_name'},
{:label => 'State', :key => 'state'}
{:label => 'State', :key => 'state'},
{:label => 'Availability Zone', :key => 'availability_zone'}
]
super
end
Expand Down
24 changes: 12 additions & 12 deletions spec/functional/server_list_func_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

context "functionality" do
before do
@resources = [ TestResource.new({:id => "resource-1", :name => "ubuntu01", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}),
TestResource.new({:id => "resource-2", :name => "windows2008", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}]}, :flavor => {"id" => "id2"}, :image => {"id" => "image2"}, :key_name => "keypair", :state => "ACTIVE"}),
TestResource.new({:id => "resource-3-err", :name => "windows2008", :addresses => {"public"=>[], "private"=>[]}, :flavor => {"id" => "id2"}, :image => {"id" => "image2"}, :key_name => "keypair", :state => "ERROR"})
@resources = [ TestResource.new({:id => "resource-1", :name => "ubuntu01", :availability_zone => "test zone", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}),
TestResource.new({:id => "resource-2", :name => "windows2008",:availability_zone => "test zone", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}]}, :flavor => {"id" => "id2"}, :image => {"id" => "image2"}, :key_name => "keypair", :state => "ACTIVE"}),
TestResource.new({:id => "resource-3-err", :name => "windows2008", :availability_zone => "test zone", :addresses => {"public"=>[], "private"=>[]}, :flavor => {"id" => "id2"}, :image => {"id" => "image2"}, :key_name => "keypair", :state => "ERROR"})
]
instance.stub(:query_resource).and_return(@resources)
instance.stub(:puts)
Expand All @@ -21,30 +21,30 @@
end

it "lists formatted list of resources" do
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State",
"resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1","keypair", "ACTIVE",
"resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE",
"resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR"], :uneven_columns_across, 8)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Availability Zone",
"resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1","keypair", "ACTIVE", "test zone",
"resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "test zone",
"resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "test zone"], :uneven_columns_across, 9)
instance.run
end

context "when chef-data and chef-node-attribute set" do
before(:each) do
@resources.push(TestResource.new({:id => "server-4", :name => "server-4", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}))
@resources.push(TestResource.new({:id => "server-4", :name => "server-4", :availability_zone => "test zone", :addresses => {"public"=>[{"version"=>4, "addr"=>"172.31.6.132"}], "private"=>[{"version"=>4, "addr"=>"172.31.6.133"}]}, :flavor => {"id" => "1"}, :image => {"id" => "image1"}, :key_name => "keypair", :state => "ACTIVE"}))
@node = TestResource.new({:id => "server-4", :name => "server-4", :chef_environment => "_default", :fqdn => "testfqdnnode.us", :run_list => [], :tags => [], :platform => "ubuntu", :platform_family => "debian"})
Chef::Node.stub(:list).and_return({"server-4" => @node})
instance.config[:chef_data] = true
end

it "lists formatted list of resources on chef data option set" do
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "", "", "", "", "", "","server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 14)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 15)
instance.run
end

it "lists formatted list of resources on chef-data and chef-node-attribute option set" do
instance.config[:chef_node_attribute] = "platform_family"
@node.should_receive(:attribute?).with("platform_family").and_return(true)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "platform_family", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "", "", "","","","","","server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", "debian"], :uneven_columns_across, 15)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "platform_family", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu", "debian"], :uneven_columns_across, 16)
instance.run
end

Expand All @@ -59,8 +59,8 @@
it "not display chef-data on chef-node-attribute set but chef-data option missing" do
instance.config[:chef_data] = false
instance.config[:chef_node_attribute] = "platform_family"
instance.ui.should_not_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "", "", "", "", "", "","server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 14)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR","server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE"], :uneven_columns_across, 8)
instance.ui.should_not_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Availability Zone", "Chef Node Name", "Environment", "FQDN", "Runlist", "Tags", "Platform", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "test zone", "", "", "", "", "", "", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "test zone", "", "", "", "", "", "", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "server-4", "_default", "testfqdnnode.us", "[]", "[]", "ubuntu"], :uneven_columns_across, 15)
instance.ui.should_receive(:list).with(["Instance ID", "Name", "Public IP", "Private IP", "Flavor", "Image", "Keypair", "State", "Availability Zone", "resource-1", "ubuntu01", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone", "resource-2", "windows2008", "172.31.6.132", nil, "id2", "image2", "keypair", "ACTIVE", "test zone", "resource-3-err", "windows2008", nil, nil, "id2", "image2", "keypair", "ERROR", "test zone", "server-4", "server-4", "172.31.6.132", "172.31.6.133", "1", "image1", "keypair", "ACTIVE", "test zone"], :uneven_columns_across, 9)
instance.run
end
end
Expand Down

0 comments on commit 8aaa622

Please sign in to comment.