From 8e0a51ba321c4ebd3d0cd98bebc60732cb890398 Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Fri, 22 Nov 2013 18:40:02 +0530 Subject: [PATCH 01/10] Initial implementation for custom_arguments passed to Fog. --- lib/chef/knife/cloud/fog/service.rb | 5 +++++ lib/chef/knife/cloud/server/create_options.rb | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 6f3d6df..1a687e6 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -30,6 +30,7 @@ def load_fog_gem def connection add_api_endpoint + add_custom_arguments @connection ||= begin connection = Fog::Compute.new(@auth_params) rescue Excon::Errors::Unauthorized => e @@ -121,6 +122,10 @@ def delete_server_on_failure(server = nil) def add_api_endpoint raise Chef::Exceptions::Override, "You must override add_api_endpoint in #{self.to_s} to add endpoint in auth_params for connection" end + + def add_custom_arguments + Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? + end end end end diff --git a/lib/chef/knife/cloud/server/create_options.rb b/lib/chef/knife/cloud/server/create_options.rb index def1681..3d831b3 100644 --- a/lib/chef/knife/cloud/server/create_options.rb +++ b/lib/chef/knife/cloud/server/create_options.rb @@ -70,6 +70,11 @@ def self.included(includer) :default => includer.snake_case_name.split('_').first, :proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name_prefix] = key } + option :custom_arguments, + :long => "--custom-arguments CUSTOM_ARGUMENTS", + :description => "Custom arguments to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} + end end From ea8d08c393dd4a0eb6afaa1e74b1696cf4fa5f07 Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Mon, 25 Nov 2013 15:30:37 +0530 Subject: [PATCH 02/10] Moved the custom-arguments to options.rb and passing the args to create_server, instead of connection. --- lib/chef/knife/cloud/fog/options.rb | 5 +++++ lib/chef/knife/cloud/fog/service.rb | 7 ++++--- lib/chef/knife/cloud/server/create_options.rb | 5 ----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index f11493b..c1968b8 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -20,6 +20,11 @@ def self.included(includer) :long => "--api-endpoint ENDPOINT", :description => "Your API endpoint. Eg, for Eucalyptus it can be 'http://ecc.eucalyptus.com:8773/services/Eucalyptus'", :proc => Proc.new { |endpoint| Chef::Config[:knife][:api_endpoint] = endpoint } + + option :custom_arguments, + :long => "--custom-arguments CUSTOM_ARGUMENTS", + :description => "Custom arguments to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 1a687e6..8a63d8f 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -1,5 +1,6 @@ # # Author:: Kaustubh Deorukhkar () +# Author:: Prabhu Das () # Copyright:: Copyright (c) 2013 Opscode, Inc. # @@ -30,7 +31,6 @@ def load_fog_gem def connection add_api_endpoint - add_custom_arguments @connection ||= begin connection = Fog::Compute.new(@auth_params) rescue Excon::Errors::Unauthorized => e @@ -47,6 +47,7 @@ def connection # cloud server specific implementation methods for commands. def create_server(options = {}) begin + add_custom_arguments(options[:server_def]) server = connection.servers.create(options[:server_def]) rescue Excon::Errors::BadRequest => e response = Chef::JSONCompat.from_json(e.response.body) @@ -123,8 +124,8 @@ def add_api_endpoint raise Chef::Exceptions::Override, "You must override add_api_endpoint in #{self.to_s} to add endpoint in auth_params for connection" end - def add_custom_arguments - Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? + def add_custom_arguments(server_def) + Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? end end end diff --git a/lib/chef/knife/cloud/server/create_options.rb b/lib/chef/knife/cloud/server/create_options.rb index 3d831b3..def1681 100644 --- a/lib/chef/knife/cloud/server/create_options.rb +++ b/lib/chef/knife/cloud/server/create_options.rb @@ -70,11 +70,6 @@ def self.included(includer) :default => includer.snake_case_name.split('_').first, :proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name_prefix] = key } - option :custom_arguments, - :long => "--custom-arguments CUSTOM_ARGUMENTS", - :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} - end end From 2520ba21cb2bfe21e0f79e2e9dc2f7106d1c0c57 Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Wed, 27 Nov 2013 18:18:55 +0530 Subject: [PATCH 03/10] Made the custom arguments separable using semi-colon. --- lib/chef/knife/cloud/fog/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index c1968b8..4b8436a 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -24,7 +24,7 @@ def self.included(includer) option :custom_arguments, :long => "--custom-arguments CUSTOM_ARGUMENTS", :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end From 2d4ca484caecfeadf84ab0d6ea74f899147fa8fb Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Wed, 27 Nov 2013 18:19:45 +0530 Subject: [PATCH 04/10] Added unit tests for custom_arguments. --- spec/unit/fog_service_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/unit/fog_service_spec.rb b/spec/unit/fog_service_spec.rb index 6c47e52..2e836d3 100644 --- a/spec/unit/fog_service_spec.rb +++ b/spec/unit/fog_service_spec.rb @@ -2,7 +2,6 @@ # Copyright:: Copyright (c) 2013 Opscode, Inc. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'chef/knife/cloud/fog/service' - require 'support/shared_examples_for_service' describe Chef::Knife::Cloud::FogService do @@ -23,4 +22,20 @@ end end + + context "add_custom_arguments" do + before(:each) do + Chef::Config[:knife][:custom_arguments] = [{"state"=>"Inactive"}] + @server_def = {:name=>"vm-1", :image_ref=>"123",:flavor_ref=>"2", :key_name=>"key"} + instance.add_custom_arguments(@server_def) + end + + it "adds the custom arguments provided to server_def" do + expect(@server_def.include?(:state)).to be true + end + + it "sets the provided arguments with supplied values" do + expect(@server_def[:state] == "Inactive").to be true + end + end end From 7a301928d18644da35a99057f825725bf1f9ba01 Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Mon, 9 Dec 2013 13:24:36 +0530 Subject: [PATCH 05/10] Generalized the --custom-attributes option to be an attribute of CloudService, not just FogService. --- lib/chef/knife/cloud/fog/options.rb | 5 ----- lib/chef/knife/cloud/fog/service.rb | 5 +---- lib/chef/knife/cloud/server/options.rb | 5 +++++ lib/chef/knife/cloud/service.rb | 4 ++++ spec/unit/fog_service_spec.rb | 10 +++++----- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index 4b8436a..1209c29 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -21,13 +21,8 @@ def self.included(includer) :description => "Your API endpoint. Eg, for Eucalyptus it can be 'http://ecc.eucalyptus.com:8773/services/Eucalyptus'", :proc => Proc.new { |endpoint| Chef::Config[:knife][:api_endpoint] = endpoint } - option :custom_arguments, - :long => "--custom-arguments CUSTOM_ARGUMENTS", - :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end - end end end diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 8a63d8f..e97aa46 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -47,7 +47,7 @@ def connection # cloud server specific implementation methods for commands. def create_server(options = {}) begin - add_custom_arguments(options[:server_def]) + add_custom_attributes(options[:server_def]) server = connection.servers.create(options[:server_def]) rescue Excon::Errors::BadRequest => e response = Chef::JSONCompat.from_json(e.response.body) @@ -124,9 +124,6 @@ def add_api_endpoint raise Chef::Exceptions::Override, "You must override add_api_endpoint in #{self.to_s} to add endpoint in auth_params for connection" end - def add_custom_arguments(server_def) - Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? - end end end end diff --git a/lib/chef/knife/cloud/server/options.rb b/lib/chef/knife/cloud/server/options.rb index c2a66c6..aeec73c 100644 --- a/lib/chef/knife/cloud/server/options.rb +++ b/lib/chef/knife/cloud/server/options.rb @@ -26,6 +26,11 @@ def self.included(includer) :short => "-N NAME", :long => "--node-name NAME", :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option." + + option :custom_attributes, + :long => "--custom-attributes CUSTOM_ATTRIBUTES", + :description => "Custom attributes to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_attributes] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end end diff --git a/lib/chef/knife/cloud/service.rb b/lib/chef/knife/cloud/service.rb index 1a8eca4..ba0e2ae 100644 --- a/lib/chef/knife/cloud/service.rb +++ b/lib/chef/knife/cloud/service.rb @@ -68,6 +68,10 @@ def list_images(image_filters) raise Chef::Exceptions::Override, "You must override list_images in #{self.to_s}" end + def add_custom_attributes(server_def) + Chef::Config[:knife][:custom_attributes].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_attributes].nil? + end + end # class service end end diff --git a/spec/unit/fog_service_spec.rb b/spec/unit/fog_service_spec.rb index 2e836d3..13c4fbd 100644 --- a/spec/unit/fog_service_spec.rb +++ b/spec/unit/fog_service_spec.rb @@ -23,18 +23,18 @@ end - context "add_custom_arguments" do + context "add_custom_attributes" do before(:each) do - Chef::Config[:knife][:custom_arguments] = [{"state"=>"Inactive"}] + Chef::Config[:knife][:custom_attributes] = [{"state"=>"Inactive"}] @server_def = {:name=>"vm-1", :image_ref=>"123",:flavor_ref=>"2", :key_name=>"key"} - instance.add_custom_arguments(@server_def) + instance.add_custom_attributes(@server_def) end - it "adds the custom arguments provided to server_def" do + it "adds the custom attributes provided to server_def" do expect(@server_def.include?(:state)).to be true end - it "sets the provided arguments with supplied values" do + it "sets the provided attributes with supplied values" do expect(@server_def[:state] == "Inactive").to be true end end From b2ef3f970b414d19fb58349ed9ddb9e5d7d9e1bb Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Fri, 22 Nov 2013 18:40:02 +0530 Subject: [PATCH 06/10] Initial implementation for custom_arguments passed to Fog. --- lib/chef/knife/cloud/fog/service.rb | 7 ++++++- lib/chef/knife/cloud/server/create_options.rb | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 7a1621f..5c42371 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -31,6 +31,7 @@ def load_fog_gem def connection add_api_endpoint + add_custom_arguments @connection ||= begin connection = Fog::Compute.new(@auth_params) rescue Excon::Errors::Unauthorized => e @@ -127,7 +128,7 @@ def list_resource_configurations raise CloudExceptions::CloudAPIException, error_message end end - + def delete_server_on_failure(server = nil) server.destroy if ! server.nil? end @@ -172,6 +173,10 @@ def is_image_windows?(image) image_info = connection.images.get(image) !image_info.nil? ? image_info.platform == 'windows' : false end + + def add_custom_arguments + Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? + end end end end diff --git a/lib/chef/knife/cloud/server/create_options.rb b/lib/chef/knife/cloud/server/create_options.rb index def1681..3d831b3 100644 --- a/lib/chef/knife/cloud/server/create_options.rb +++ b/lib/chef/knife/cloud/server/create_options.rb @@ -70,6 +70,11 @@ def self.included(includer) :default => includer.snake_case_name.split('_').first, :proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name_prefix] = key } + option :custom_arguments, + :long => "--custom-arguments CUSTOM_ARGUMENTS", + :description => "Custom arguments to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} + end end From 550997cbc632eb177f48157a1947ae73b25186b8 Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Mon, 25 Nov 2013 15:30:37 +0530 Subject: [PATCH 07/10] Moved the custom-arguments to options.rb and passing the args to create_server, instead of connection. --- lib/chef/knife/cloud/fog/options.rb | 5 +++++ lib/chef/knife/cloud/fog/service.rb | 6 +++++- lib/chef/knife/cloud/server/create_options.rb | 5 ----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index f11493b..c1968b8 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -20,6 +20,11 @@ def self.included(includer) :long => "--api-endpoint ENDPOINT", :description => "Your API endpoint. Eg, for Eucalyptus it can be 'http://ecc.eucalyptus.com:8773/services/Eucalyptus'", :proc => Proc.new { |endpoint| Chef::Config[:knife][:api_endpoint] = endpoint } + + option :custom_arguments, + :long => "--custom-arguments CUSTOM_ARGUMENTS", + :description => "Custom arguments to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 5c42371..72c7e96 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -31,7 +31,6 @@ def load_fog_gem def connection add_api_endpoint - add_custom_arguments @connection ||= begin connection = Fog::Compute.new(@auth_params) rescue Excon::Errors::Unauthorized => e @@ -48,6 +47,7 @@ def connection # cloud server specific implementation methods for commands. def create_server(options = {}) begin + add_custom_arguments(options[:server_def]) server = connection.servers.create(options[:server_def]) rescue Excon::Errors::BadRequest => e response = Chef::JSONCompat.from_json(e.response.body) @@ -177,6 +177,10 @@ def is_image_windows?(image) def add_custom_arguments Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? end + + def add_custom_arguments(server_def) + Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? + end end end end diff --git a/lib/chef/knife/cloud/server/create_options.rb b/lib/chef/knife/cloud/server/create_options.rb index 3d831b3..def1681 100644 --- a/lib/chef/knife/cloud/server/create_options.rb +++ b/lib/chef/knife/cloud/server/create_options.rb @@ -70,11 +70,6 @@ def self.included(includer) :default => includer.snake_case_name.split('_').first, :proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name_prefix] = key } - option :custom_arguments, - :long => "--custom-arguments CUSTOM_ARGUMENTS", - :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} - end end From abdf12bb2b39d3f12841eacce4f7362f89c1626f Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Wed, 27 Nov 2013 18:18:55 +0530 Subject: [PATCH 08/10] Made the custom arguments separable using semi-colon. --- lib/chef/knife/cloud/fog/options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index c1968b8..4b8436a 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -24,7 +24,7 @@ def self.included(includer) option :custom_arguments, :long => "--custom-arguments CUSTOM_ARGUMENTS", :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} + :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end From 18a8db012d00b50db251f6b610782bd2fa40ea8a Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Wed, 27 Nov 2013 18:19:45 +0530 Subject: [PATCH 09/10] Added unit tests for custom_arguments. --- spec/unit/fog_service_spec.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/unit/fog_service_spec.rb b/spec/unit/fog_service_spec.rb index 6c47e52..2e836d3 100644 --- a/spec/unit/fog_service_spec.rb +++ b/spec/unit/fog_service_spec.rb @@ -2,7 +2,6 @@ # Copyright:: Copyright (c) 2013 Opscode, Inc. require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') require 'chef/knife/cloud/fog/service' - require 'support/shared_examples_for_service' describe Chef::Knife::Cloud::FogService do @@ -23,4 +22,20 @@ end end + + context "add_custom_arguments" do + before(:each) do + Chef::Config[:knife][:custom_arguments] = [{"state"=>"Inactive"}] + @server_def = {:name=>"vm-1", :image_ref=>"123",:flavor_ref=>"2", :key_name=>"key"} + instance.add_custom_arguments(@server_def) + end + + it "adds the custom arguments provided to server_def" do + expect(@server_def.include?(:state)).to be true + end + + it "sets the provided arguments with supplied values" do + expect(@server_def[:state] == "Inactive").to be true + end + end end From 6a8a2a012a9c094986ef270de2cf6a566f57575f Mon Sep 17 00:00:00 2001 From: prabhu-das Date: Mon, 9 Dec 2013 13:24:36 +0530 Subject: [PATCH 10/10] Generalized the --custom-attributes option to be an attribute of CloudService, not just FogService. --- lib/chef/knife/cloud/fog/options.rb | 5 ----- lib/chef/knife/cloud/fog/service.rb | 9 +-------- lib/chef/knife/cloud/server/options.rb | 5 +++++ lib/chef/knife/cloud/service.rb | 6 ++++++ spec/unit/fog_service_spec.rb | 10 +++++----- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index 4b8436a..1209c29 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -21,13 +21,8 @@ def self.included(includer) :description => "Your API endpoint. Eg, for Eucalyptus it can be 'http://ecc.eucalyptus.com:8773/services/Eucalyptus'", :proc => Proc.new { |endpoint| Chef::Config[:knife][:api_endpoint] = endpoint } - option :custom_arguments, - :long => "--custom-arguments CUSTOM_ARGUMENTS", - :description => "Custom arguments to be passed to Fog.", - :proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end - end end end diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 72c7e96..4c71b38 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -47,7 +47,7 @@ def connection # cloud server specific implementation methods for commands. def create_server(options = {}) begin - add_custom_arguments(options[:server_def]) + add_custom_attributes(options[:server_def]) server = connection.servers.create(options[:server_def]) rescue Excon::Errors::BadRequest => e response = Chef::JSONCompat.from_json(e.response.body) @@ -174,13 +174,6 @@ def is_image_windows?(image) !image_info.nil? ? image_info.platform == 'windows' : false end - def add_custom_arguments - Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? - end - - def add_custom_arguments(server_def) - Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil? - end end end end diff --git a/lib/chef/knife/cloud/server/options.rb b/lib/chef/knife/cloud/server/options.rb index c2a66c6..aeec73c 100644 --- a/lib/chef/knife/cloud/server/options.rb +++ b/lib/chef/knife/cloud/server/options.rb @@ -26,6 +26,11 @@ def self.included(includer) :short => "-N NAME", :long => "--node-name NAME", :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option." + + option :custom_attributes, + :long => "--custom-attributes CUSTOM_ATTRIBUTES", + :description => "Custom attributes to be passed to Fog.", + :proc => Proc.new {|args| Chef::Config[:knife][:custom_attributes] = args.split(';').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}} end end end diff --git a/lib/chef/knife/cloud/service.rb b/lib/chef/knife/cloud/service.rb index ee7f268..e992b71 100644 --- a/lib/chef/knife/cloud/service.rb +++ b/lib/chef/knife/cloud/service.rb @@ -68,6 +68,7 @@ def list_images(image_filters) raise Chef::Exceptions::Override, "You must override list_images in #{self.to_s}" end +<<<<<<< HEAD def list_resource_configurations raise Chef::Exceptions::Override, "You must override list_resource_configurations in #{self.to_s}" end @@ -79,6 +80,11 @@ def get_server(server_name) def server_summary(server, columns_with_info = []) raise Chef::Exceptions::Override, "You must override server_summary in #{self.to_s}" end + + def add_custom_attributes(server_def) + Chef::Config[:knife][:custom_attributes].map{|args| args.map{|k,v| server_def.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_attributes].nil? + end + end # class service end end diff --git a/spec/unit/fog_service_spec.rb b/spec/unit/fog_service_spec.rb index 2e836d3..13c4fbd 100644 --- a/spec/unit/fog_service_spec.rb +++ b/spec/unit/fog_service_spec.rb @@ -23,18 +23,18 @@ end - context "add_custom_arguments" do + context "add_custom_attributes" do before(:each) do - Chef::Config[:knife][:custom_arguments] = [{"state"=>"Inactive"}] + Chef::Config[:knife][:custom_attributes] = [{"state"=>"Inactive"}] @server_def = {:name=>"vm-1", :image_ref=>"123",:flavor_ref=>"2", :key_name=>"key"} - instance.add_custom_arguments(@server_def) + instance.add_custom_attributes(@server_def) end - it "adds the custom arguments provided to server_def" do + it "adds the custom attributes provided to server_def" do expect(@server_def.include?(:state)).to be true end - it "sets the provided arguments with supplied values" do + it "sets the provided attributes with supplied values" do expect(@server_def[:state] == "Inactive").to be true end end