knife-ec2 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,11 +17,14 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'chef/json_compat'
21
20
 
22
21
  class Chef
23
22
  class Knife
24
23
  class Ec2InstanceData < Knife
24
+
25
+ deps do
26
+ require 'chef/json_compat'
27
+ end
25
28
 
26
29
  banner "knife ec2 instance data (options)"
27
30
 
@@ -45,7 +48,7 @@ class Chef
45
48
  "attributes" => { "run_list" => config[:run_list] }
46
49
  }
47
50
  data = edit_data(data) if config[:edit]
48
- output(data)
51
+ ui.output(data)
49
52
  end
50
53
  end
51
54
  end
@@ -16,22 +16,20 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'fog'
20
- require 'socket'
21
19
  require 'chef/knife'
22
- require 'chef/knife/bootstrap'
23
- require 'chef/json_compat'
24
20
 
25
21
  class Chef
26
22
  class Knife
27
23
  class Ec2ServerCreate < Knife
28
24
 
29
25
  deps do
26
+ require 'chef/knife/bootstrap'
30
27
  Chef::Knife::Bootstrap.load_deps
31
28
  require 'fog'
32
- require 'highline'
29
+ require 'socket'
33
30
  require 'net/ssh/multi'
34
31
  require 'readline'
32
+ require 'chef/json_compat'
35
33
  end
36
34
 
37
35
  banner "knife ec2 server create (options)"
@@ -154,10 +152,6 @@ class Chef
154
152
  :boolean => true,
155
153
  :default => false
156
154
 
157
- def h
158
- @highline ||= HighLine.new
159
- end
160
-
161
155
  def tcp_test_ssh(hostname)
162
156
  tcp_socket = TCPSocket.new(hostname, 22)
163
157
  readable = IO.select([tcp_socket], nil, nil, 5)
@@ -226,15 +220,15 @@ class Chef
226
220
  end
227
221
  server = connection.servers.create(server_def)
228
222
 
229
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
230
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
231
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
232
- puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
233
- puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
234
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
235
- puts "#{h.color("Subnet ID", :cyan)}: #{server.subnet_id}" if vpc_mode?
223
+ puts "#{ui.color("Instance ID", :cyan)}: #{server.id}"
224
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
225
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
226
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
227
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
228
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
229
+ puts "#{ui.color("Subnet ID", :cyan)}: #{server.subnet_id}" if vpc_mode?
236
230
 
237
- print "\n#{h.color("Waiting for server", :magenta)}"
231
+ print "\n#{ui.color("Waiting for server", :magenta)}"
238
232
 
239
233
  display_name = if vpc_mode?
240
234
  server.private_ip_address
@@ -248,13 +242,13 @@ class Chef
248
242
  puts("\n")
249
243
 
250
244
  if !vpc_mode?
251
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
252
- puts "#{h.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
253
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
245
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
246
+ puts "#{ui.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
247
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
254
248
  end
255
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
249
+ puts "#{ui.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
256
250
 
257
- print "\n#{h.color("Waiting for sshd", :magenta)}"
251
+ print "\n#{ui.color("Waiting for sshd", :magenta)}"
258
252
 
259
253
  ip_to_test = vpc_mode? ? server.private_ip_address : server.public_ip_address
260
254
  print(".") until tcp_test_ssh(ip_to_test) {
@@ -265,36 +259,36 @@ class Chef
265
259
  bootstrap_for_node(server).run
266
260
 
267
261
  puts "\n"
268
- puts "#{h.color("Instance ID", :cyan)}: #{server.id}"
269
- puts "#{h.color("Flavor", :cyan)}: #{server.flavor_id}"
270
- puts "#{h.color("Image", :cyan)}: #{server.image_id}"
271
- puts "#{h.color("Availability Zone", :cyan)}: #{server.availability_zone}"
272
- puts "#{h.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
262
+ puts "#{ui.color("Instance ID", :cyan)}: #{server.id}"
263
+ puts "#{ui.color("Flavor", :cyan)}: #{server.flavor_id}"
264
+ puts "#{ui.color("Image", :cyan)}: #{server.image_id}"
265
+ puts "#{ui.color("Availability Zone", :cyan)}: #{server.availability_zone}"
266
+ puts "#{ui.color("Security Groups", :cyan)}: #{server.groups.join(", ")}"
273
267
  if vpc_mode?
274
- puts "#{h.color("Subnet ID", :cyan)}: #{server.subnet_id}"
268
+ puts "#{ui.color("Subnet ID", :cyan)}: #{server.subnet_id}"
275
269
  else
276
- puts "#{h.color("Public DNS Name", :cyan)}: #{server.dns_name}"
277
- puts "#{h.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
278
- puts "#{h.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
270
+ puts "#{ui.color("Public DNS Name", :cyan)}: #{server.dns_name}"
271
+ puts "#{ui.color("Public IP Address", :cyan)}: #{server.public_ip_address}"
272
+ puts "#{ui.color("Private DNS Name", :cyan)}: #{server.private_dns_name}"
279
273
  end
280
- puts "#{h.color("SSH Key", :cyan)}: #{server.key_name}"
281
- puts "#{h.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
282
- puts "#{h.color("Root Device Type", :cyan)}: #{server.root_device_type}"
274
+ puts "#{ui.color("SSH Key", :cyan)}: #{server.key_name}"
275
+ puts "#{ui.color("Private IP Address", :cyan)}: #{server.private_ip_address}"
276
+ puts "#{ui.color("Root Device Type", :cyan)}: #{server.root_device_type}"
283
277
  if server.root_device_type == "ebs"
284
278
  device_map = server.block_device_mapping.first
285
- puts "#{h.color("Root Volume ID", :cyan)}: #{device_map['volumeId']}"
286
- puts "#{h.color("Root Device Name", :cyan)}: #{device_map['deviceName']}"
287
- puts "#{h.color("Root Device Delete on Terminate", :cyan)}: #{device_map['deleteOnTermination']}"
279
+ puts "#{ui.color("Root Volume ID", :cyan)}: #{device_map['volumeId']}"
280
+ puts "#{ui.color("Root Device Name", :cyan)}: #{device_map['deviceName']}"
281
+ puts "#{ui.color("Root Device Delete on Terminate", :cyan)}: #{device_map['deleteOnTermination']}"
288
282
  if config[:ebs_size]
289
283
  if ami.block_device_mapping.first['volumeSize'].to_i < config[:ebs_size].to_i
290
- puts ("#{h.color("Warning", :yellow)}: #{config[:ebs_size]}GB " +
284
+ puts ("#{ui.color("Warning", :yellow)}: #{config[:ebs_size]}GB " +
291
285
  "EBS volume size is larger than size set in AMI of " +
292
286
  "#{ami.block_device_mapping.first['volumeSize']}GB.\n" +
293
287
  "Use file system tools to make use of the increased volume size.")
294
288
  end
295
289
  end
296
290
  end
297
- puts "#{h.color("Run List", :cyan)}: #{@name_args.join(', ')}"
291
+ puts "#{ui.color("Run List", :cyan)}: #{config[:run_list].join(', ')}"
298
292
  end
299
293
 
300
294
  def bootstrap_for_node(server)
@@ -17,12 +17,18 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'chef/json_compat'
21
20
 
22
21
  class Chef
23
22
  class Knife
24
23
  class Ec2ServerDelete < Knife
25
24
 
25
+ deps do
26
+ require 'fog'
27
+ require 'net/ssh/multi'
28
+ require 'readline'
29
+ require 'chef/json_compat'
30
+ end
31
+
26
32
  banner "knife ec2 server delete SERVER [SERVER] (options)"
27
33
 
28
34
  option :aws_access_key_id,
@@ -43,16 +49,7 @@ class Chef
43
49
  :default => "us-east-1",
44
50
  :proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
45
51
 
46
- def h
47
- @highline ||= HighLine.new
48
- end
49
-
50
52
  def run
51
- require 'fog'
52
- require 'highline'
53
- require 'net/ssh/multi'
54
- require 'readline'
55
-
56
53
  connection = Fog::Compute.new(
57
54
  :provider => 'AWS',
58
55
  :aws_access_key_id => Chef::Config[:knife][:aws_access_key_id],
@@ -79,13 +76,13 @@ class Chef
79
76
 
80
77
  server.destroy
81
78
 
82
- Chef::Log.warn("Deleted server #{server.id}")
79
+ ui.warn("Deleted server #{server.id}")
83
80
  end
84
81
  end
85
82
 
86
83
  def msg(label, value)
87
84
  if value && !value.empty?
88
- puts "#{h.color(label, :cyan)}: #{value}"
85
+ puts "#{ui.color(label, :cyan)}: #{value}"
89
86
  end
90
87
  end
91
88
 
@@ -17,12 +17,18 @@
17
17
  #
18
18
 
19
19
  require 'chef/knife'
20
- require 'chef/json_compat'
21
20
 
22
21
  class Chef
23
22
  class Knife
24
23
  class Ec2ServerList < Knife
25
24
 
25
+ deps do
26
+ require 'fog'
27
+ require 'net/ssh/multi'
28
+ require 'readline'
29
+ require 'chef/json_compat'
30
+ end
31
+
26
32
  banner "knife ec2 server list (options)"
27
33
 
28
34
  option :aws_access_key_id,
@@ -43,16 +49,7 @@ class Chef
43
49
  :default => "us-east-1",
44
50
  :proc => Proc.new { |key| Chef::Config[:knife][:region] = key }
45
51
 
46
- def h
47
- @highline ||= HighLine.new
48
- end
49
-
50
52
  def run
51
- require 'fog'
52
- require 'highline'
53
- require 'net/ssh/multi'
54
- require 'readline'
55
-
56
53
  $stdout.sync = true
57
54
 
58
55
  connection = Fog::Compute.new(
@@ -63,24 +60,24 @@ class Chef
63
60
  )
64
61
 
65
62
  server_list = [
66
- h.color('Instance ID', :bold),
67
- h.color('Public IP', :bold),
68
- h.color('Private IP', :bold),
69
- h.color('Flavor', :bold),
70
- h.color('Image', :bold),
71
- h.color('Security Groups', :bold),
72
- h.color('State', :bold)
63
+ ui.color('Instance ID', :bold),
64
+ ui.color('Public IP', :bold),
65
+ ui.color('Private IP', :bold),
66
+ ui.color('Flavor', :bold),
67
+ ui.color('Image', :bold),
68
+ ui.color('Security Groups', :bold),
69
+ ui.color('State', :bold)
73
70
  ]
74
71
  connection.servers.all.each do |server|
75
72
  server_list << server.id.to_s
76
- server_list << (server.ip_address == nil ? "" : server.public_ip_address)
73
+ server_list << (server.public_ip_address == nil ? "" : server.public_ip_address)
77
74
  server_list << (server.private_ip_address == nil ? "" : server.private_ip_address)
78
75
  server_list << (server.flavor_id == nil ? "" : server.flavor_id)
79
76
  server_list << (server.image_id == nil ? "" : server.image_id)
80
77
  server_list << server.groups.join(", ")
81
78
  server_list << server.state
82
79
  end
83
- puts h.list(server_list, :columns_across, 7)
80
+ puts ui.list(server_list, :columns_across, 7)
84
81
 
85
82
  end
86
83
  end
@@ -1,4 +1,4 @@
1
1
  module KnifeEC2
2
- VERSION = "0.5.2"
2
+ VERSION = "0.5.3"
3
3
  end
4
4
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knife-ec2
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.2
5
+ version: 0.5.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Jacob
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-31 00:00:00 -07:00
13
+ date: 2011-04-05 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -46,17 +46,6 @@ dependencies:
46
46
  version: 1.0.1
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: highline
51
- prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ~>
56
- - !ruby/object:Gem::Version
57
- version: 1.6.1
58
- type: :runtime
59
- version_requirements: *id004
60
49
  description: EC2 Support for Chef's Knife Command
61
50
  email: adam@opscode.com
62
51
  executables: []