Skip to content

Commit

Permalink
Merge pull request #109 from opscode/ameya-metadata-option
Browse files Browse the repository at this point in the history
[knife-cloud] KNIFE-368 Ability to specify metadata during OpenStack server create
  • Loading branch information
kaustubh-d committed Jun 2, 2014
2 parents 4b63cbd + bc15169 commit 86e0a29
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/chef/knife/cloud/openstack_server_create_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ class Chef
class Knife
class Cloud
module OpenstackServerCreateOptions

def self.included(includer)
def self.included(includer)
includer.class_eval do
include ServerCreateOptions

Expand Down Expand Up @@ -63,6 +62,11 @@ def self.included(includer)
:description => "The availability zone for this server",
:proc => Proc.new { |z| Chef::Config[:knife][:availability_zone] = z }

option :metadata,
:short => "-M X=1",
:long => "--metadata X=1",
:description => "Metadata information for this server (may pass multiple times)",
:proc => Proc.new { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!({data.split('=')[0]=>data.split('=')[1]})}
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/chef/knife/openstack_server_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def before_exec_command
:flavor_ref => locate_config_value(:flavor),
:security_groups => locate_config_value(:openstack_security_groups),
:availability_zone => locate_config_value(:availability_zone),
:metadata => locate_config_value(:metadata),
:key_name => locate_config_value(:openstack_ssh_key_id)
},
:server_create_timeout => locate_config_value(:server_create_timeout)
Expand Down
8 changes: 8 additions & 0 deletions spec/unit/openstack_server_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key"
Chef::Config[:knife][:network_ids] = "test_network_id"
Chef::Config[:knife][:network_ids].stub(:map).and_return(Chef::Config[:knife][:network_ids])
Chef::Config[:knife][:metadata] = "foo=bar"
end

after(:all) do
Expand All @@ -73,6 +74,7 @@
Chef::Config[:knife].delete(:openstack_ssh_key_id)
Chef::Config[:knife].delete(:openstack_security_groups)
Chef::Config[:knife].delete(:server_create_timeout)
Chef::Config[:knife].delete(:metadata)
end

it "set create_options" do
Expand All @@ -84,6 +86,7 @@
@instance.create_options[:server_def][:security_groups].should == Chef::Config[:knife][:openstack_security_groups]
@instance.create_options[:server_def][:flavor_ref].should == Chef::Config[:knife][:flavor]
@instance.create_options[:server_def][:nics].should == Chef::Config[:knife][:network_ids]
@instance.create_options[:server_def][:metadata].should == Chef::Config[:knife][:metadata]
@instance.create_options[:server_create_timeout].should == Chef::Config[:knife][:server_create_timeout]
end

Expand Down Expand Up @@ -114,6 +117,11 @@
@instance.create_options[:server_def][:nics].should == ["test_network_id1", "test_network_id2"]
end
end

it "ensures default value for metadata" do
options = @instance.options
options[:metadata][:default].should == nil
end
end

describe "#after_exec_command" do
Expand Down

0 comments on commit 86e0a29

Please sign in to comment.