diff options
-rw-r--r-- | chef/lib/chef/knife/bootstrap.rb | 16 | ||||
-rw-r--r-- | chef/lib/chef/knife/ec2_server_create.rb | 39 | ||||
-rw-r--r-- | chef/lib/chef/knife/ec2_server_delete.rb | 84 | ||||
-rw-r--r-- | chef/lib/chef/knife/ec2_server_list.rb | 82 |
4 files changed, 203 insertions, 18 deletions
diff --git a/chef/lib/chef/knife/bootstrap.rb b/chef/lib/chef/knife/bootstrap.rb index b320a86397..6a7e591615 100644 --- a/chef/lib/chef/knife/bootstrap.rb +++ b/chef/lib/chef/knife/bootstrap.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2009 Opscode, Inc. +# Copyright:: Copyright (c) 2010 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,12 +26,6 @@ class Chef banner "Sub-Command: knife bootstrap FQDN [RUN LIST...] (options)" - option :concurrency, - :short => "-C NUM", - :long => "--concurrency NUM", - :description => "The number of concurrent connections", - :default => nil - option :ssh_user, :short => "-x USERNAME", :long => "--ssh-user USERNAME", @@ -43,6 +37,12 @@ class Chef :long => "--ssh-password PASSWORD", :description => "The ssh password" + option :chef_node_name, + :short => "-N NAME", + :long => "--node-name NAME", + :description => "The Chef node name for your new node" + + def h @highline ||= HighLine.new end @@ -86,6 +86,7 @@ log_level :info log_location STDOUT chef_server_url "#{Chef::Config[:chef_server_url]}" validation_client_name "#{Chef::Config[:validation_client_name]}" +#{config[:chef_node_name] == nil ? "# Using default node name" : "node_name \"#{config[:chef_node_name]}\""} EOP ) > /etc/chef/client.rb @@ -123,4 +124,3 @@ EOH end end - diff --git a/chef/lib/chef/knife/ec2_server_create.rb b/chef/lib/chef/knife/ec2_server_create.rb index a820e649cf..bf0be5dd5c 100644 --- a/chef/lib/chef/knife/ec2_server_create.rb +++ b/chef/lib/chef/knife/ec2_server_create.rb @@ -34,8 +34,7 @@ class Chef option :image, :short => "-i IMAGE", :long => "--image IMAGE", - :description => "The AMI for the server", - :default => "ami-17f51c7e" + :description => "The AMI for the server" option :security_groups, :short => "-G X,Y,Z", @@ -56,6 +55,12 @@ class Chef :description => "The SSH root key", :proc => Proc.new { |key| Chef::Config[:knife][:aws_ssh_key_id] = key } + option :ssh_user, + :short => "-x USERNAME", + :long => "--ssh-user USERNAME", + :description => "The ssh username", + :default => "root" + option :aws_access_key_id, :short => "-A ID", :long => "--aws-access-key-id KEY", @@ -90,12 +95,6 @@ class Chef :groups => config[:security_groups], :flavor_id => config[:flavor], :key_name => Chef::Config[:knife][:aws_ssh_key_id], - :user_data => { - "chef_server" => Chef::Config[:chef_server_url], - "validation_client_name" => Chef::Config[:validation_client_name], - "validation_key" => IO.read(Chef::Config[:validation_key]), - "attributes" => { "run_list" => @name_args } - }.to_json, :availability_zone => config[:availability_zone] ) @@ -118,10 +117,30 @@ class Chef puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}" puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}" + puts "\nWaiting 15 seconds for SSH...\n" + + sleep 15 + + bootstrap = Chef::Knife::Bootstrap.new + bootstrap.name_args = [ server.ip_address, @name_args ].flatten + bootstrap.config[:ssh_user] = config[:ssh_user] + bootstrap.config[:chef_node_name] = server.id + bootstrap.run + + puts "\n" + puts "#{h.color("Instance ID", :cyan)}: #{server.id}" + puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}" + puts "#{h.color("Image", :cyan)}: #{server.image_id}" + puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}" + puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}" + puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}" + puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}" + puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}" + puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}" + puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}" + puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}" end end end end - - diff --git a/chef/lib/chef/knife/ec2_server_delete.rb b/chef/lib/chef/knife/ec2_server_delete.rb new file mode 100644 index 0000000000..c41a9e88a4 --- /dev/null +++ b/chef/lib/chef/knife/ec2_server_delete.rb @@ -0,0 +1,84 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2009 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/knife' +require 'json' + +class Chef + class Knife + class Ec2ServerDelete < Knife + + banner "Sub-Command: ec2 server delete SERVER [SERVER] (options)" + + option :aws_access_key_id, + :short => "-A ID", + :long => "--aws-access-key-id KEY", + :description => "Your AWS Access Key ID", + :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key } + + option :aws_secret_access_key, + :short => "-K SECRET", + :long => "--aws-secret-access-key SECRET", + :description => "Your AWS API Secret Access Key", + :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key } + + def h + @highline ||= HighLine.new + end + + def run + require 'fog' + require 'highline' + require 'net/ssh/multi' + require 'readline' + + connection = Fog::AWS::EC2.new( + :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id], + :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key] + ) + + @name_args.each do |instance_id| + server = connection.servers.get(instance_id) + + puts "#{h.color("Instance ID", :cyan)}: #{server.id}" + puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}" + puts "#{h.color("Image", :cyan)}: #{server.image_id}" + puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}" + puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}" + puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}" + puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}" + puts "#{h.color("Public IP Address", :cyan)}: #{server.ip_address}" + puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}" + puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}" + + puts "\n" + confirm("Do you really want to delete this server") + + server.destroy + + Chef::Log.warn("Deleted server #{server.id}") + end + end + end + end +end + + + + + diff --git a/chef/lib/chef/knife/ec2_server_list.rb b/chef/lib/chef/knife/ec2_server_list.rb new file mode 100644 index 0000000000..bae86994a1 --- /dev/null +++ b/chef/lib/chef/knife/ec2_server_list.rb @@ -0,0 +1,82 @@ +# +# Author:: Adam Jacob (<adam@opscode.com>) +# Copyright:: Copyright (c) 2010 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/knife' +require 'json' + +class Chef + class Knife + class Ec2ServerList < Knife + + banner "Sub-Command: ec2 server list [RUN LIST...] (options)" + + option :aws_access_key_id, + :short => "-A ID", + :long => "--aws-access-key-id KEY", + :description => "Your AWS Access Key ID", + :proc => Proc.new { |key| Chef::Config[:knife][:aws_access_key_id] = key } + + option :aws_secret_access_key, + :short => "-K SECRET", + :long => "--aws-secret-access-key SECRET", + :description => "Your AWS API Secret Access Key", + :proc => Proc.new { |key| Chef::Config[:knife][:aws_secret_access_key] = key } + + def h + @highline ||= HighLine.new + end + + def run + require 'fog' + require 'highline' + require 'net/ssh/multi' + require 'readline' + + $stdout.sync = true + + connection = Fog::AWS::EC2.new( + :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id], + :aws_secret_access_key => Chef::Config[:knife][:aws_secret_access_key] + ) + + server_list = [ + h.color('Instance ID', :bold), + h.color('Public IP', :bold), + h.color('Private IP', :bold), + h.color('Flavor', :bold), + h.color('Image', :bold), + h.color('Security Groups', :bold), + h.color('State', :bold) + ] + connection.servers.all.each do |server| + server_list << server.id.to_s + server_list << (server.ip_address == nil ? "" : server.ip_address) + server_list << (server.private_ip_address == nil ? "" : server.private_ip_address) + server_list << (server.flavor_id == nil ? "" : server.flavor_id) + server_list << (server.image_id == nil ? "" : server.image_id) + server_list << server.groups.join(", ") + server_list << server.state + end + puts h.list(server_list, :columns_across, 7) + + end + end + end +end + + |