Skip to content
Browse files

refactored to use knife ui class..kicked highline dependency to the curb

  • Loading branch information...
1 parent 1fdad5b commit b3e59d09e5d7a685935852400af125b92b061a11 @schisamo schisamo committed Apr 5, 2011
View
1 knife-ec2.gemspec
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
s.add_dependency "fog", "~> 0.6.0"
s.add_dependency "net-ssh", "~> 2.1.3"
s.add_dependency "net-ssh-multi", "~> 1.0.1"
- s.add_dependency "highline", "~> 1.6.1"
s.require_path = 'lib'
s.files = %w(LICENSE README.rdoc) + Dir.glob("lib/**/*")
end
View
7 lib/chef/knife/ec2_instance_data.rb
@@ -17,11 +17,14 @@
#
require 'chef/knife'
-require 'chef/json_compat'
class Chef
class Knife
class Ec2InstanceData < Knife
+
+ deps do
+ require 'chef/json_compat'
+ end
banner "knife ec2 instance data (options)"
@@ -45,7 +48,7 @@ def run
"attributes" => { "run_list" => config[:run_list] }
}
data = edit_data(data) if config[:edit]
- output(data)
+ ui.output(data)
end
end
end
View
72 lib/chef/knife/ec2_server_create.rb
@@ -16,22 +16,20 @@
# limitations under the License.
#
-require 'fog'
-require 'socket'
require 'chef/knife'
-require 'chef/knife/bootstrap'
-require 'chef/json_compat'
class Chef
class Knife
class Ec2ServerCreate < Knife
deps do
+ require 'chef/knife/bootstrap'
Chef::Knife::Bootstrap.load_deps
require 'fog'
- require 'highline'
+ require 'socket'
require 'net/ssh/multi'
require 'readline'
+ require 'chef/json_compat'
end
banner "knife ec2 server create (options)"
@@ -154,10 +152,6 @@ class Ec2ServerCreate < Knife
:boolean => true,
:default => false
- def h
- @highline ||= HighLine.new
- end
-
def tcp_test_ssh(hostname)
tcp_socket = TCPSocket.new(hostname, 22)
readable = IO.select([tcp_socket], nil, nil, 5)
@@ -226,15 +220,15 @@ def run
end
server = connection.servers.create(server_def)
- 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("Subnet ID", :cyan)}: #{server.subnet_id}" if vpc_mode?
+ puts "#{ui.color("Instance ID", :cyan)}: #{server.id}"
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
+ puts "#{ui.color("Subnet ID", :cyan)}: #{server.subnet_id}" if vpc_mode?
- print "\n#{h.color("Waiting for server", :magenta)}"
+ print "\n#{ui.color("Waiting for server", :magenta)}"
display_name = if vpc_mode?
server.private_ip_address
@@ -248,13 +242,13 @@ def run
puts("\n")
if !vpc_mode?
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
- puts "#{h.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
+ puts "#{ui.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
end
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
+ puts "#{ui.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
- print "\n#{h.color("Waiting for sshd", :magenta)}"
+ print "\n#{ui.color("Waiting for sshd", :magenta)}"
ip_to_test = vpc_mode? ? server.private_ip_address : server.public_ip_address
print(".") until tcp_test_ssh(ip_to_test) {
@@ -265,36 +259,36 @@ def run
bootstrap_for_node(server).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 "#{ui.color("Instance ID", :cyan)}: #{server.id}"
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
if vpc_mode?
- puts "#{h.color("Subnet ID", :cyan)}: #{server.subnet_id}"
+ puts "#{ui.color("Subnet ID", :cyan)}: #{server.subnet_id}"
else
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
- puts "#{h.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
+ puts "#{ui.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
end
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
- puts "#{h.color("Root Device Type", :cyan)}: #{server.root_device_type}"
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
+ puts "#{ui.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
+ puts "#{ui.color("Root Device Type", :cyan)}: #{server.root_device_type}"
if server.root_device_type == "ebs"
device_map = server.block_device_mapping.first
- puts "#{h.color("Root Volume ID", :cyan)}: #{device_map['volumeId']}"
- puts "#{h.color("Root Device Name", :cyan)}: #{device_map['deviceName']}"
- puts "#{h.color("Root Device Delete on Terminate", :cyan)}: #{device_map['deleteOnTermination']}"
+ puts "#{ui.color("Root Volume ID", :cyan)}: #{device_map['volumeId']}"
+ puts "#{ui.color("Root Device Name", :cyan)}: #{device_map['deviceName']}"
+ puts "#{ui.color("Root Device Delete on Terminate", :cyan)}: #{device_map['deleteOnTermination']}"
if config[:ebs_size]
if ami.block_device_mapping.first['volumeSize'].to_i < config[:ebs_size].to_i
- puts ("#{h.color("Warning", :yellow)}: #{config[:ebs_size]}GB " +
+ puts ("#{ui.color("Warning", :yellow)}: #{config[:ebs_size]}GB " +
"EBS volume size is larger than size set in AMI of " +
"#{ami.block_device_mapping.first['volumeSize']}GB.\n" +
"Use file system tools to make use of the increased volume size.")
end
end
end
- puts "#{h.color("Run List", :cyan)}: #{config[:run_list].join(', ')}"
+ puts "#{ui.color("Run List", :cyan)}: #{config[:run_list].join(', ')}"
end
def bootstrap_for_node(server)
View
21 lib/chef/knife/ec2_server_delete.rb
@@ -17,12 +17,18 @@
#
require 'chef/knife'
-require 'chef/json_compat'
class Chef
class Knife
class Ec2ServerDelete < Knife
+ deps do
+ require 'fog'
+ require 'net/ssh/multi'
+ require 'readline'
+ require 'chef/json_compat'
+ end
+
banner "knife ec2 server delete SERVER [SERVER] (options)"
option :aws_access_key_id,
@@ -43,16 +49,7 @@ class Ec2ServerDelete < Knife
:default => "us-east-1",
:proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
- def h
- @highline ||= HighLine.new
- end
-
def run
- require 'fog'
- require 'highline'
- require 'net/ssh/multi'
- require 'readline'
-
connection = Fog::Compute.new(
:provider => 'AWS',
:aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
@@ -79,13 +76,13 @@ def run
server.destroy
- Chef::Log.warn("Deleted server #{server.id}")
+ ui.warn("Deleted server #{server.id}")
end
end
def msg(label, value)
if value && !value.empty?
- puts "#{h.color(label, :cyan)}: #{value}"
+ puts "#{ui.color(label, :cyan)}: #{value}"
end
end
View
35 lib/chef/knife/ec2_server_list.rb
@@ -17,12 +17,18 @@
#
require 'chef/knife'
-require 'chef/json_compat'
class Chef
class Knife
class Ec2ServerList < Knife
+ deps do
+ require 'fog'
+ require 'net/ssh/multi'
+ require 'readline'
+ require 'chef/json_compat'
+ end
+
banner "knife ec2 server list (options)"
option :aws_access_key_id,
@@ -43,16 +49,7 @@ class Ec2ServerList < Knife
:default => "us-east-1",
:proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
- def h
- @highline ||= HighLine.new
- end
-
def run
- require 'fog'
- require 'highline'
- require 'net/ssh/multi'
- require 'readline'
-
$stdout.sync = true
connection = Fog::Compute.new(
@@ -63,24 +60,24 @@ def run
)
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)
+ ui.color('Instance ID', :bold),
+ ui.color('Public IP', :bold),
+ ui.color('Private IP', :bold),
+ ui.color('Flavor', :bold),
+ ui.color('Image', :bold),
+ ui.color('Security Groups', :bold),
+ ui.color('State', :bold)
]
connection.servers.all.each do |server|
server_list << server.id.to_s
- server_list << (server.ip_address == nil ? "" : server.public_ip_address)
+ server_list << (server.public_ip_address == nil ? "" : server.public_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)
+ puts ui.list(server_list, :columns_across, 7)
end
end

0 comments on commit b3e59d0

Please sign in to comment.
Something went wrong with that request. Please try again.