Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNIFE-368 Ability to specify metadata during OpenStack server create #109

Merged
merged 6 commits into from
Jun 2, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 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 @@ -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]}) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use Chef::Config[:knife][:openstack_metadata] instead of md?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed !!!

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 @@ -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)
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 @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down