From d505801243fdbaef0562ee4efaec126983944221 Mon Sep 17 00:00:00 2001 From: ameyavarade Date: Tue, 27 May 2014 17:57:24 +0530 Subject: [PATCH 1/2] Implemented changes for metadata option for openstack knife cloud --- .../knife/cloud/openstack_server_create_options.rb | 11 ++++++++--- lib/chef/knife/openstack_server_create.rb | 1 + spec/unit/openstack_server_create_spec.rb | 8 ++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/chef/knife/cloud/openstack_server_create_options.rb b/lib/chef/knife/cloud/openstack_server_create_options.rb index b3fcb796..4a7971b6 100644 --- a/lib/chef/knife/cloud/openstack_server_create_options.rb +++ b/lib/chef/knife/cloud/openstack_server_create_options.rb @@ -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 @@ -51,7 +50,13 @@ def self.included(includer) :boolean => true, :default => true, :description => "Use first available network for bootstrapping if 'public' and 'private' are unavailable." - + + md = {} + option :metadata, + :short => "-M X=1", + :long => "--metadata X=1", + :description => "Metadata information for this server (may pass multiple times)", + :proc => Proc.new { |data| md.merge!({data.split('=')[0]=>data.split('=')[1]}) } end end end diff --git a/lib/chef/knife/openstack_server_create.rb b/lib/chef/knife/openstack_server_create.rb index 41d6688e..afd08984 100644 --- a/lib/chef/knife/openstack_server_create.rb +++ b/lib/chef/knife/openstack_server_create.rb @@ -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), + :metadata => locate_config_value(:metadata), :key_name => locate_config_value(:openstack_ssh_key_id) }, :server_create_timeout => locate_config_value(:server_create_timeout) diff --git a/spec/unit/openstack_server_create_spec.rb b/spec/unit/openstack_server_create_spec.rb index 603deb28..09fa1327 100644 --- a/spec/unit/openstack_server_create_spec.rb +++ b/spec/unit/openstack_server_create_spec.rb @@ -63,6 +63,7 @@ Chef::Config[:knife][:openstack_security_groups] = "openstack_security_groups" Chef::Config[:knife][:server_create_timeout] = "server_create_timeout" Chef::Config[:knife][:openstack_ssh_key_id] = "openstack_ssh_key" + Chef::Config[:knife][:metadata] = "foo=bar" end after(:all) do @@ -71,6 +72,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 @@ -81,6 +83,7 @@ @instance.create_options[:server_def][:image_ref].should == Chef::Config[:knife][:image] @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][:metadata].should == Chef::Config[:knife][:metadata] @instance.create_options[:server_create_timeout].should == Chef::Config[:knife][:server_create_timeout] end @@ -97,6 +100,11 @@ @instance.before_exec_command @instance.create_options[:server_def][:user_data].should == user_data end + + it "ensures default value for metadata" do + options = @instance.options + options[:metadata][:default].should == nil + end end describe "#after_exec_command" do From 10b40822171ed34d7f37014d177beff1fd727a54 Mon Sep 17 00:00:00 2001 From: ameyavarade Date: Thu, 29 May 2014 18:42:14 +0530 Subject: [PATCH 2/2] Implemented review comments related to metadata option --- lib/chef/knife/cloud/openstack_server_create_options.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/chef/knife/cloud/openstack_server_create_options.rb b/lib/chef/knife/cloud/openstack_server_create_options.rb index 4a7971b6..d3384ce5 100644 --- a/lib/chef/knife/cloud/openstack_server_create_options.rb +++ b/lib/chef/knife/cloud/openstack_server_create_options.rb @@ -51,12 +51,11 @@ def self.included(includer) :default => true, :description => "Use first available network for bootstrapping if 'public' and 'private' are unavailable." - md = {} option :metadata, :short => "-M X=1", :long => "--metadata X=1", :description => "Metadata information for this server (may pass multiple times)", - :proc => Proc.new { |data| md.merge!({data.split('=')[0]=>data.split('=')[1]}) } + :proc => Proc.new { |data| Chef::Config[:knife][:metadata] ||= {}; Chef::Config[:knife][:metadata].merge!({data.split('=')[0]=>data.split('=')[1]})} end end end