knife-rackspace 0.11.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011-2012 Opscode, Inc.
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
+ # Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife/rackspace_base'
19
+ require "chef/knife/rackspace_base"
20
20
 
21
21
  class Chef
22
22
  class Knife
@@ -29,32 +29,32 @@ class Chef
29
29
  def run
30
30
  if version_one?
31
31
  flavor_list = [
32
- ui.color('ID', :bold),
33
- ui.color('Name', :bold),
34
- ui.color('Architecture', :bold),
35
- ui.color('RAM', :bold),
36
- ui.color('Disk', :bold)
32
+ ui.color("ID", :bold),
33
+ ui.color("Name", :bold),
34
+ ui.color("Architecture", :bold),
35
+ ui.color("RAM", :bold),
36
+ ui.color("Disk", :bold),
37
37
  ]
38
38
  else
39
39
  flavor_list = [
40
- ui.color('ID', :bold),
41
- ui.color('Name', :bold),
42
- ui.color('VCPUs', :bold),
43
- ui.color('RAM', :bold),
44
- ui.color('Disk', :bold)
40
+ ui.color("ID", :bold),
41
+ ui.color("Name", :bold),
42
+ ui.color("VCPUs", :bold),
43
+ ui.color("RAM", :bold),
44
+ ui.color("Disk", :bold),
45
45
  ]
46
46
  end
47
47
  connection.flavors.sort_by(&:id).each do |flavor|
48
- bits = flavor.respond_to?(:bits) ? "#{flavor.bits.to_s}-bit" : ""
48
+ bits = flavor.respond_to?(:bits) ? "#{flavor.bits}-bit" : ""
49
49
 
50
50
  flavor_list << flavor.id.to_s
51
51
  flavor_list << flavor.name
52
52
  flavor_list << bits if version_one?
53
53
  flavor_list << flavor.vcpus.to_s unless version_one?
54
- flavor_list << "#{flavor.ram.to_s}"
55
- flavor_list << "#{flavor.disk.to_s} GB"
54
+ flavor_list << "#{flavor.ram}"
55
+ flavor_list << "#{flavor.disk} GB"
56
56
  end
57
- puts ui.list(flavor_list, :uneven_columns_across, 5)
57
+ puts ui.list(flavor_list, :uneven_columns_across, 5)
58
58
  end
59
59
  end
60
60
  end
@@ -1,6 +1,6 @@
1
1
  #
2
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
3
- # Copyright:: Copyright (c) 2011 Opscode, Inc.
2
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
3
+ # Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require 'chef/knife/rackspace_base'
19
+ require "chef/knife/rackspace_base"
20
20
 
21
21
  class Chef
22
22
  class Knife
@@ -28,8 +28,8 @@ class Chef
28
28
 
29
29
  def run
30
30
  image_list = [
31
- ui.color('ID', :bold),
32
- ui.color('Name', :bold)
31
+ ui.color("ID", :bold),
32
+ ui.color("Name", :bold),
33
33
  ]
34
34
 
35
35
  connection.images.sort_by(&:name).each do |image|
@@ -1,4 +1,4 @@
1
- require 'chef/knife/rackspace_base'
1
+ require "chef/knife/rackspace_base"
2
2
 
3
3
  class Chef
4
4
  class Knife
@@ -26,9 +26,9 @@ class Chef
26
26
  exit 1
27
27
  else
28
28
  networks_list = [
29
- ui.color('Label', :bold),
30
- ui.color('CIDR', :bold),
31
- ui.color('ID', :bold)
29
+ ui.color("Label", :bold),
30
+ ui.color("CIDR", :bold),
31
+ ui.color("ID", :bold),
32
32
  ]
33
33
  end
34
34
  options = {}
@@ -1,4 +1,4 @@
1
- require 'chef/knife/rackspace_base'
1
+ require "chef/knife/rackspace_base"
2
2
 
3
3
  class Chef
4
4
  class Knife
@@ -15,7 +15,7 @@ class Chef
15
15
  else
16
16
  @name_args.each do |net_id|
17
17
  network = connection.networks.get(net_id)
18
- unless(network)
18
+ unless network
19
19
  ui.error "Could not locate network: #{net_id}"
20
20
  exit 1
21
21
  end
@@ -1,4 +1,4 @@
1
- require 'chef/knife/rackspace_base'
1
+ require "chef/knife/rackspace_base"
2
2
 
3
3
  class Chef
4
4
  class Knife
@@ -14,9 +14,9 @@ class Chef
14
14
  exit 1
15
15
  else
16
16
  networks_list = [
17
- ui.color('Label', :bold),
18
- ui.color('CIDR', :bold),
19
- ui.color('ID', :bold)
17
+ ui.color("Label", :bold),
18
+ ui.color("CIDR", :bold),
19
+ ui.color("ID", :bold),
20
20
  ]
21
21
  end
22
22
  connection.networks.sort_by(&:id).each do |network|
@@ -1,7 +1,7 @@
1
1
  #
2
- # Author:: Adam Jacob (<adam@opscode.com>)
3
- # Author:: Matt Ray (<matt@opscode.com>)
4
- # Copyright:: Copyright (c) 2009-2012 Opscode, Inc.
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Author:: Matt Ray (<matt@chef.io>)
4
+ # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,9 +17,9 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require 'chef/knife/rackspace_base'
21
- require 'chef/knife/winrm_base'
22
- require 'chef/knife'
20
+ require "chef/knife/rackspace_base"
21
+ require "chef/knife/winrm_base"
22
+ require "chef/knife"
23
23
 
24
24
  class Chef
25
25
  class Knife
@@ -28,12 +28,11 @@ class Chef
28
28
  include Knife::RackspaceBase
29
29
  include Chef::Knife::WinrmBase
30
30
 
31
-
32
31
  deps do
33
- require 'fog'
34
- require 'readline'
35
- require 'chef/json_compat'
36
- require 'chef/knife/bootstrap'
32
+ require "fog/rackspace"
33
+ require "readline"
34
+ require "chef/json_compat"
35
+ require "chef/knife/bootstrap"
37
36
  Chef::Knife::Bootstrap.load_deps
38
37
  end
39
38
 
@@ -54,6 +53,12 @@ class Chef
54
53
  :description => "The image of the server",
55
54
  :proc => Proc.new { |i| Chef::Config[:knife][:image] = i.to_s }
56
55
 
56
+ option :boot_volume_size,
57
+ :long => "--boot-volume-size GB",
58
+ :description => "The size of the CBS to use as the server's boot device",
59
+ :proc => Proc.new { |i| Chef::Config[:knife][:boot_volume_size] = i.to_s },
60
+ :default => 100
61
+
57
62
  option :boot_volume_id,
58
63
  :short => "-B BOOT_VOLUME_ID",
59
64
  :long => "--boot-volume-id UUID",
@@ -73,7 +78,7 @@ class Chef
73
78
  option :bootstrap_network,
74
79
  :long => "--bootstrap-network LABEL",
75
80
  :description => "Use IP address on this network for bootstrap",
76
- :default => 'public'
81
+ :default => "public"
77
82
 
78
83
  option :private_network,
79
84
  :long => "--private-network",
@@ -106,7 +111,8 @@ class Chef
106
111
 
107
112
  option :prerelease,
108
113
  :long => "--prerelease",
109
- :description => "Install the pre-release chef gems"
114
+ :description => "Install the pre-release chef gems",
115
+ :default => false
110
116
 
111
117
  option :bootstrap_version,
112
118
  :long => "--bootstrap-version VERSION",
@@ -143,8 +149,8 @@ class Chef
143
149
  :short => "-M JSON",
144
150
  :long => "--rackspace-metadata JSON",
145
151
  :description => "JSON string version of metadata hash to be supplied with the server create call",
146
- :proc => Proc.new { |m| Chef::Config[:knife][:rackspace_metadata] = JSON.parse(m) },
147
- :default => ""
152
+ :proc => lambda { |m| JSON.parse(m) },
153
+ :default => {}
148
154
 
149
155
  option :rackconnect_wait,
150
156
  :long => "--rackconnect-wait",
@@ -153,8 +159,8 @@ class Chef
153
159
  :default => false
154
160
 
155
161
  option :rackconnect_v3_network_id,
156
- :long => '--rackconnect-v3-network-id ID',
157
- :description => 'Rackconnect V3 ONLY: Link a new server to an existing network',
162
+ :long => "--rackconnect-v3-network-id ID",
163
+ :description => "Rackconnect V3 ONLY: Link a new server to an existing network",
158
164
  :proc => lambda { |o| Chef::Config[:knife][:rackconnect_v3_network_id] = o },
159
165
  :default => nil
160
166
 
@@ -207,7 +213,7 @@ class Chef
207
213
  :default => true
208
214
 
209
215
  option :network,
210
- :long => '--network [LABEL_OR_ID]',
216
+ :long => "--network [LABEL_OR_ID]",
211
217
  :description => "Add private network. Use multiple --network options to specify multiple networks.",
212
218
  :proc => Proc.new{ |name|
213
219
  Chef::Config[:knife][:rackspace_networks] ||= []
@@ -223,7 +229,7 @@ class Chef
223
229
  :long => "--server-create-timeout timeout",
224
230
  :description => "How long to wait until the server is ready; default is 1200 seconds",
225
231
  :default => 1200,
226
- :proc => Proc.new { |v| Chef::Config[:knife][:server_create_timeout] = v}
232
+ :proc => Proc.new { |v| Chef::Config[:knife][:server_create_timeout] = v }
227
233
 
228
234
  option :bootstrap_proxy,
229
235
  :long => "--bootstrap-proxy PROXY_URL",
@@ -232,9 +238,8 @@ class Chef
232
238
 
233
239
  option :rackspace_disk_config,
234
240
  :long => "--rackspace-disk-config DISKCONFIG",
235
- :description => "Specify if want to manage your own disk partitioning scheme (AUTO or MANUAL), default is AUTO",
236
- :proc => Proc.new { |k| Chef::Config[:knife][:rackspace_disk_config] = k },
237
- :default => "AUTO"
241
+ :description => "Specify if want to manage your own disk partitioning scheme (AUTO or MANUAL)",
242
+ :proc => Proc.new { |k| Chef::Config[:knife][:rackspace_disk_config] = k }
238
243
 
239
244
  option :rackspace_config_drive,
240
245
  :long => "--rackspace_config_drive CONFIGDRIVE",
@@ -259,15 +264,15 @@ class Chef
259
264
  :proc => Proc.new { |sf| Chef::Config[:knife][:secret_file] = sf }
260
265
 
261
266
  option :bootstrap_vault_file,
262
- :long => '--bootstrap-vault-file VAULT_FILE',
263
- :description => 'A JSON file with a list of vault(s) and item(s) to be updated'
267
+ :long => "--bootstrap-vault-file VAULT_FILE",
268
+ :description => "A JSON file with a list of vault(s) and item(s) to be updated"
264
269
 
265
270
  option :bootstrap_vault_json,
266
- :long => '--bootstrap-vault-json VAULT_JSON',
267
- :description => 'A JSON string with the vault(s) and item(s) to be updated'
271
+ :long => "--bootstrap-vault-json VAULT_JSON",
272
+ :description => "A JSON string with the vault(s) and item(s) to be updated"
268
273
 
269
274
  option :bootstrap_vault_item,
270
- :long => '--bootstrap-vault-item VAULT_ITEM',
275
+ :long => "--bootstrap-vault-item VAULT_ITEM",
271
276
  :description => 'A single vault and item to update as "vault:item"',
272
277
  :proc => Proc.new { |i|
273
278
  (vault, item) = i.split(/:/)
@@ -278,21 +283,21 @@ class Chef
278
283
  }
279
284
 
280
285
  def load_winrm_deps
281
- require 'winrm'
282
- require 'em-winrm'
283
- require 'chef/knife/bootstrap_windows_winrm'
284
- require 'chef/knife/core/windows_bootstrap_context'
285
- require 'chef/knife/winrm'
286
+ require "winrm"
287
+ require "em-winrm"
288
+ require "chef/knife/bootstrap_windows_winrm"
289
+ require "chef/knife/core/windows_bootstrap_context"
290
+ require "chef/knife/winrm"
286
291
  end
287
292
 
288
293
  def tcp_test_ssh(server, bootstrap_ip)
289
- return true unless config[:tcp_test_ssh] != nil
294
+ return true unless locate_config_value(:tcp_test_ssh) != nil
290
295
 
291
- limit = Chef::Config[:knife][:retry_ssh_limit].to_i
296
+ limit = locate_config_value(:retry_ssh_limit).to_i
292
297
  count = 0
293
298
 
294
299
  begin
295
- Net::SSH.start(bootstrap_ip, 'root', :password => server.password ) do |ssh|
300
+ Net::SSH.start(bootstrap_ip, "root", :password => server.password ) do |ssh|
296
301
  Chef::Log.debug("sshd accepting connections on #{bootstrap_ip}")
297
302
  break
298
303
  end
@@ -300,8 +305,8 @@ class Chef
300
305
  count += 1
301
306
 
302
307
  if count <= limit
303
- print '.'
304
- sleep config[:retry_ssh_every].to_i
308
+ print "."
309
+ sleep locate_config_value(:retry_ssh_every).to_i
305
310
  tcp_test_ssh(server, bootstrap_ip)
306
311
  else
307
312
  ui.error "Unable to SSH into #{bootstrap_ip}"
@@ -311,7 +316,7 @@ class Chef
311
316
  end
312
317
 
313
318
  def parse_file_argument(arg)
314
- dest, src = arg.split('=')
319
+ dest, src = arg.split("=")
315
320
  unless dest && src
316
321
  ui.error "Unable to process file arguments #{arg}. The --file option requires both the destination on the remote machine as well as the local source be supplied using the form DESTINATION-PATH=SOURCE-PATH"
317
322
  exit 1
@@ -331,7 +336,7 @@ class Chef
331
336
  end
332
337
 
333
338
  def files
334
- return {} unless Chef::Config[:knife][:file]
339
+ return {} unless Chef::Config[:knife][:file]
335
340
 
336
341
  files = []
337
342
  Chef::Config[:knife][:file].each do |arg|
@@ -339,14 +344,12 @@ class Chef
339
344
  Chef::Log.debug("Inject file #{src} into #{dest}")
340
345
  files << {
341
346
  :path => dest,
342
- :contents => encode_file(src)
347
+ :contents => encode_file(src),
343
348
  }
344
349
  end
345
350
  files
346
351
  end
347
352
 
348
-
349
-
350
353
  def tcp_test_winrm(hostname, port)
351
354
  TCPSocket.new(hostname, port)
352
355
  return true
@@ -372,18 +375,18 @@ class Chef
372
375
  $stdout.sync = true
373
376
 
374
377
  server_create_options = {
375
- :metadata => Chef::Config[:knife][:rackspace_metadata],
376
- :disk_config => Chef::Config[:knife][:rackspace_disk_config],
378
+ :metadata => locate_config_value(:rackspace_metadata),
379
+ :disk_config => locate_config_value(:rackspace_disk_config),
377
380
  :user_data => user_data,
378
381
  :config_drive => locate_config_value(:rackspace_config_drive) || false,
379
382
  :personality => files,
380
- :key_name => Chef::Config[:knife][:rackspace_ssh_keypair],
383
+ :key_name => locate_config_value(:rackspace_ssh_keypair),
381
384
  :name => get_node_name(config[:chef_node_name] || config[:server_name]),
382
- :networks => get_networks(Chef::Config[:knife][:rackspace_networks], Chef::Config[:knife][:rackconnect_v3_network_id]),
385
+ :networks => get_networks(locate_config_value(:rackspace_networks), locate_config_value(:rackconnect_v3_network_id)),
383
386
  }
384
387
 
385
388
  # Maybe deprecate this option at some point
386
- config[:bootstrap_network] = 'private' if config[:private_network]
389
+ config[:bootstrap_network] = "private" if locate_config_value(:private_network)
387
390
 
388
391
  flavor_id = locate_config_value(:flavor)
389
392
  flavor = connection.flavors.get(flavor_id)
@@ -400,24 +403,25 @@ class Chef
400
403
  # In the case we are trying to create one of these flavors, we should
401
404
  # swap out the image_id argument with the boot_image_id argument.
402
405
  if flavor.disk == 0
403
- server_create_options[:image_id] = ''
404
- server_create_options[:boot_volume_id] = Chef::Config[:knife][:boot_volume_id]
405
- server_create_options[:boot_image_id] = Chef::Config[:knife][:image]
406
+ server_create_options[:image_id] = ""
407
+ server_create_options[:boot_volume_id] = locate_config_value(:boot_volume_id)
408
+ server_create_options[:boot_image_id] = locate_config_value(:image)
409
+ server_create_options[:boot_volume_size] = locate_config_value(:boot_volume_size)
406
410
 
407
411
  if server_create_options[:boot_image_id] && server_create_options[:boot_volume_id]
408
- ui.error('Please specify exactly one of --boot-volume-id (-B) and --image (-I)')
412
+ ui.error("Please specify either --boot-volume-id (-B) or --image (-I)")
409
413
  exit 1
410
414
  end
411
415
  else
412
- server_create_options[:image_id] = Chef::Config[:knife][:image]
416
+ server_create_options[:image_id] = locate_config_value(:image)
413
417
 
414
418
  if !server_create_options[:image_id]
415
- ui.error('Please specify an Image ID for the server with --image (-I)')
419
+ ui.error("Please specify an Image ID for the server with --image (-I)")
416
420
  exit 1
417
421
  end
418
422
  end
419
423
 
420
- if locate_config_value(:bootstrap_protocol) == 'winrm'
424
+ if locate_config_value(:bootstrap_protocol) == "winrm"
421
425
  load_winrm_deps
422
426
  end
423
427
 
@@ -429,8 +433,8 @@ class Chef
429
433
  server.save(:networks => server_create_options[:networks])
430
434
  end
431
435
 
432
- rackconnect_wait = Chef::Config[:knife][:rackconnect_wait] || config[:rackconnect_wait]
433
- rackspace_servicelevel_wait = Chef::Config[:knife][:rackspace_servicelevel_wait] || config[:rackspace_servicelevel_wait]
436
+ rackconnect_wait = locate_config_value(:rackconnect_wait)
437
+ rackspace_servicelevel_wait = locate_config_value(:rackspace_servicelevel_wait)
434
438
 
435
439
  msg_pair("Instance ID", server.id)
436
440
  msg_pair("Host ID", server.host_id)
@@ -440,37 +444,37 @@ class Chef
440
444
  msg_pair("Boot Image ID", server.boot_image_id) if server.boot_image_id
441
445
  msg_pair("Metadata", server.metadata.all)
442
446
  msg_pair("ConfigDrive", server.config_drive)
443
- msg_pair("UserData", Chef::Config[:knife][:rackspace_user_data])
444
- msg_pair("RackConnect Wait", rackconnect_wait ? 'yes' : 'no')
445
- msg_pair("RackConnect V3", Chef::Config[:knife][:rackconnect_v3_network_id] ? 'yes' : 'no')
446
- msg_pair("ServiceLevel Wait", rackspace_servicelevel_wait ? 'yes' : 'no')
447
- msg_pair("SSH Key", Chef::Config[:knife][:rackspace_ssh_keypair])
447
+ msg_pair("UserData", locate_config_value(:rackspace_user_data))
448
+ msg_pair("RackConnect Wait", rackconnect_wait ? "yes" : "no")
449
+ msg_pair("RackConnect V3", locate_config_value(:rackconnect_v3_network_id) ? "yes" : "no")
450
+ msg_pair("ServiceLevel Wait", rackspace_servicelevel_wait ? "yes" : "no")
451
+ msg_pair("SSH Key", locate_config_value(:rackspace_ssh_keypair))
448
452
 
449
453
  # wait for it to be ready to do stuff
450
454
  begin
451
- server.wait_for(Integer(locate_config_value(:server_create_timeout))) {
455
+ server.wait_for(Integer(locate_config_value(:server_create_timeout))) do
452
456
  print ".";
453
457
  Chef::Log.debug("#{progress}%")
454
458
 
455
- if rackconnect_wait and rackspace_servicelevel_wait
459
+ if rackconnect_wait && rackspace_servicelevel_wait
456
460
  Chef::Log.debug("rackconnect_automation_status: #{metadata.all['rackconnect_automation_status']}")
457
461
  Chef::Log.debug("rax_service_level_automation: #{metadata.all['rax_service_level_automation']}")
458
- ready? and metadata.all['rackconnect_automation_status'] == 'DEPLOYED' and metadata.all['rax_service_level_automation'] == 'Complete'
462
+ ready? && metadata.all["rackconnect_automation_status"] == "DEPLOYED" && metadata.all["rax_service_level_automation"] == "Complete"
459
463
  elsif rackconnect_wait
460
464
  Chef::Log.debug("rackconnect_automation_status: #{metadata.all['rackconnect_automation_status']}")
461
- ready? and metadata.all['rackconnect_automation_status'] == 'DEPLOYED'
465
+ ready? && metadata.all["rackconnect_automation_status"] == "DEPLOYED"
462
466
  elsif rackspace_servicelevel_wait
463
467
  Chef::Log.debug("rax_service_level_automation: #{metadata.all['rax_service_level_automation']}")
464
- ready? and metadata.all['rax_service_level_automation'] == 'Complete'
468
+ ready? && metadata.all["rax_service_level_automation"] == "Complete"
465
469
  else
466
470
  ready?
467
471
  end
468
- }
472
+ end
469
473
  rescue Fog::Errors::TimeoutError
470
- ui.error('Timeout waiting for the server to be created')
471
- msg_pair('Progress', "#{server.progress}%")
472
- msg_pair('rackconnect_automation_status', server.metadata.all['rackconnect_automation_status'])
473
- msg_pair('rax_service_level_automation', server.metadata.all['rax_service_level_automation'])
474
+ ui.error("Timeout waiting for the server to be created")
475
+ msg_pair("Progress", "#{server.progress}%")
476
+ msg_pair("rackconnect_automation_status", server.metadata.all["rackconnect_automation_status"])
477
+ msg_pair("rax_service_level_automation", server.metadata.all["rax_service_level_automation"])
474
478
  Chef::Application.fatal! 'Server didn\'t finish on time'
475
479
  end
476
480
 
@@ -480,7 +484,7 @@ class Chef
480
484
 
481
485
  puts("\n")
482
486
 
483
- if Chef::Config[:knife][:rackconnect_v3_network_id]
487
+ if locate_config_value(:rackconnect_v3_network_id)
484
488
  print "\n#{ui.color("Setting up RackconnectV3 network and IPs", :magenta)}"
485
489
  setup_rackconnect_network!(server)
486
490
  while server.ipv4_address == ""
@@ -489,17 +493,17 @@ class Chef
489
493
  end
490
494
  end
491
495
 
492
- if server_create_options[:networks] && Chef::Config[:knife][:rackspace_networks]
493
- msg_pair("Networks", Chef::Config[:knife][:rackspace_networks].sort.join(', '))
496
+ if server_create_options[:networks] && locate_config_value(:rackspace_networks)
497
+ msg_pair("Networks", locate_config_value(:rackspace_networks).sort.join(", "))
494
498
  end
495
499
 
496
500
  msg_pair("Public DNS Name", public_dns_name(server))
497
- msg_pair("Public IP Address", ip_address(server, 'public'))
498
- msg_pair("Private IP Address", ip_address(server, 'private'))
501
+ msg_pair("Public IP Address", ip_address(server, "public"))
502
+ msg_pair("Private IP Address", ip_address(server, "private"))
499
503
  msg_pair("Password", server.password)
500
504
  msg_pair("Metadata", server.metadata.all)
501
505
 
502
- bootstrap_ip_address = ip_address(server, config[:bootstrap_network])
506
+ bootstrap_ip_address = ip_address(server, locate_config_value(:bootstrap_network))
503
507
 
504
508
  Chef::Log.debug("Bootstrap IP Address #{bootstrap_ip_address}")
505
509
  if bootstrap_ip_address.nil?
@@ -507,7 +511,7 @@ class Chef
507
511
  exit 1
508
512
  end
509
513
 
510
- if locate_config_value(:bootstrap_protocol) == 'winrm'
514
+ if locate_config_value(:bootstrap_protocol) == "winrm"
511
515
  print "\n#{ui.color("Waiting for winrm", :magenta)}"
512
516
  print(".") until tcp_test_winrm(bootstrap_ip_address, locate_config_value(:winrm_port))
513
517
  bootstrap_for_windows_node(server, bootstrap_ip_address).run
@@ -526,11 +530,11 @@ class Chef
526
530
  msg_pair("Boot Image ID", server.boot_image_id) if server.boot_image_id
527
531
  msg_pair("Metadata", server.metadata)
528
532
  msg_pair("Public DNS Name", public_dns_name(server))
529
- msg_pair("Public IP Address", ip_address(server, 'public'))
530
- msg_pair("Private IP Address", ip_address(server, 'private'))
533
+ msg_pair("Public IP Address", ip_address(server, "public"))
534
+ msg_pair("Private IP Address", ip_address(server, "private"))
531
535
  msg_pair("Password", server.password)
532
- msg_pair("Environment", config[:environment] || '_default')
533
- msg_pair("Run List", config[:run_list].join(', '))
536
+ msg_pair("Environment", config[:environment] || "_default")
537
+ msg_pair("Run List", config[:run_list].join(", "))
534
538
  end
535
539
 
536
540
  def setup_rackconnect_network!(server)
@@ -542,8 +546,8 @@ class Chef
542
546
  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
543
547
  begin
544
548
  req = Net::HTTP::Post.new(uri.request_uri)
545
- req['X-Auth-Token'] = auth_token
546
- req['Content-Type'] = 'application/json'
549
+ req["X-Auth-Token"] = auth_token
550
+ req["Content-Type"] = "application/json"
547
551
  req.body = JSON.dump("cloud_server" => { "id" => server.id })
548
552
  http.use_ssl = true
549
553
  http.request req
@@ -554,7 +558,7 @@ class Chef
554
558
  end
555
559
 
556
560
  def user_data
557
- file = Chef::Config[:knife][:rackspace_user_data]
561
+ file = locate_config_value(:rackspace_user_data)
558
562
  return unless file
559
563
 
560
564
  begin
@@ -570,17 +574,17 @@ class Chef
570
574
  def bootstrap_for_node(server, bootstrap_ip_address)
571
575
  bootstrap = Chef::Knife::Bootstrap.new
572
576
  bootstrap.name_args = [bootstrap_ip_address]
573
- bootstrap.config[:ssh_user] = config[:ssh_user] || "root"
577
+ bootstrap.config[:ssh_user] = locate_config_value(:ssh_user) || "root"
574
578
  bootstrap.config[:ssh_password] = server.password
575
- bootstrap.config[:ssh_port] = config[:ssh_port] || Chef::Config[:knife][:ssh_port]
576
- bootstrap.config[:identity_file] = config[:identity_file]
577
- bootstrap.config[:host_key_verify] = config[:host_key_verify]
578
- bootstrap.config[:bootstrap_vault_file] = config[:bootstrap_vault_file] if config[:bootstrap_vault_file]
579
- bootstrap.config[:bootstrap_vault_json] = config[:bootstrap_vault_json] if config[:bootstrap_vault_json]
580
- bootstrap.config[:bootstrap_vault_item] = config[:bootstrap_vault_item] if config[:bootstrap_vault_item]
579
+ bootstrap.config[:ssh_port] = locate_config_value(:ssh_port)
580
+ bootstrap.config[:identity_file] = locate_config_value(:identity_file)
581
+ bootstrap.config[:host_key_verify] = locate_config_value(:host_key_verify)
582
+ bootstrap.config[:bootstrap_vault_file] = locate_config_value(:bootstrap_vault_file) if locate_config_value(:bootstrap_vault_file)
583
+ bootstrap.config[:bootstrap_vault_json] = locate_config_value(:bootstrap_vault_json) if locate_config_value(:bootstrap_vault_json)
584
+ bootstrap.config[:bootstrap_vault_item] = locate_config_value(:bootstrap_vault_item) if locate_config_value(:bootstrap_vault_item)
581
585
  # bootstrap will run as root...sudo (by default) also messes up Ohai on CentOS boxes
582
- bootstrap.config[:use_sudo] = true unless config[:ssh_user] == 'root'
583
- bootstrap.config[:distro] = locate_config_value(:distro) || 'chef-full'
586
+ bootstrap.config[:use_sudo] = true unless locate_config_value(:ssh_user) == "root"
587
+ bootstrap.config[:distro] = locate_config_value(:distro) || "chef-full"
584
588
  bootstrap_common_params(bootstrap, server)
585
589
  end
586
590
 
@@ -592,15 +596,16 @@ class Chef
592
596
  else
593
597
  bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.name
594
598
  end
595
- bootstrap.config[:prerelease] = config[:prerelease]
599
+ bootstrap.config[:prerelease] = locate_config_value(:prerelease)
596
600
  bootstrap.config[:bootstrap_version] = locate_config_value(:bootstrap_version)
597
601
  bootstrap.config[:template_file] = locate_config_value(:template_file)
598
- bootstrap.config[:first_boot_attributes] = config[:first_boot_attributes]
602
+ bootstrap.config[:first_boot_attributes] = locate_config_value(:first_boot_attributes)
599
603
  bootstrap.config[:bootstrap_proxy] = locate_config_value(:bootstrap_proxy)
600
- bootstrap.config[:encrypted_data_bag_secret] = config[:encrypted_data_bag_secret]
601
- bootstrap.config[:encrypted_data_bag_secret_file] = config[:encrypted_data_bag_secret_file]
604
+ # TODO: Remove dead code. There's no command line parameter for these two.
605
+ # bootstrap.config[:encrypted_data_bag_secret] = config[:encrypted_data_bag_secret]
606
+ # bootstrap.config[:encrypted_data_bag_secret_file] = config[:encrypted_data_bag_secret_file]
602
607
  bootstrap.config[:secret] = locate_config_value(:secret)
603
- bootstrap.config[:secret_file] = locate_config_value(:secret_file) || ""
608
+ bootstrap.config[:secret_file] = locate_config_value(:secret_file) || ""
604
609
 
605
610
  Chef::Config[:knife][:hints] ||= {}
606
611
  Chef::Config[:knife][:hints]["rackspace"] ||= {}
@@ -610,11 +615,11 @@ class Chef
610
615
  def bootstrap_for_windows_node(server, bootstrap_ip_address)
611
616
  bootstrap = Chef::Knife::BootstrapWindowsWinrm.new
612
617
  bootstrap.name_args = [bootstrap_ip_address]
613
- bootstrap.config[:winrm_user] = locate_config_value(:winrm_user) || 'Administrator'
618
+ bootstrap.config[:winrm_user] = locate_config_value(:winrm_user) || "Administrator"
614
619
  bootstrap.config[:winrm_password] = locate_config_value(:winrm_password) || server.password
615
620
  bootstrap.config[:winrm_transport] = locate_config_value(:winrm_transport)
616
621
  bootstrap.config[:winrm_port] = locate_config_value(:winrm_port)
617
- bootstrap.config[:distro] = locate_config_value(:distro) || 'windows-chef-client-msi'
622
+ bootstrap.config[:distro] = locate_config_value(:distro) || "windows-chef-client-msi"
618
623
  bootstrap_common_params(bootstrap, server)
619
624
  end
620
625
 
@@ -623,29 +628,29 @@ class Chef
623
628
  def get_node_name(chef_node_name)
624
629
  return chef_node_name unless chef_node_name.nil?
625
630
  #lazy uuids
626
- chef_node_name = "rs-"+rand.to_s.split('.')[1] unless version_one?
631
+ chef_node_name = "rs-" + rand.to_s.split(".")[1] unless version_one?
627
632
  end
628
633
 
629
- def get_networks(names, rackconnect3=false)
634
+ def get_networks(names, rackconnect3 = false)
630
635
  names = Array(names)
631
636
 
632
- if(Chef::Config[:knife][:rackspace_version] == 'v2')
633
- if rackconnect3
634
- nets = [Chef::Config[:knife][:rackconnect_v3_network_id]]
635
- elsif config[:default_networks]
636
- nets = [
637
- '00000000-0000-0000-0000-000000000000',
638
- '11111111-1111-1111-1111-111111111111'
639
- ]
640
- else
641
- nets = []
642
- end
637
+ if locate_config_value(:rackspace_version) == "v2"
638
+ nets = if rackconnect3
639
+ [locate_config_value(:rackconnect_v3_network_id)]
640
+ elsif locate_config_value(:default_networks)
641
+ [
642
+ "00000000-0000-0000-0000-000000000000",
643
+ "11111111-1111-1111-1111-111111111111",
644
+ ]
645
+ else
646
+ []
647
+ end
643
648
 
644
649
  available_networks = connection.networks.all
645
650
 
646
651
  names.each do |name|
647
- net = available_networks.detect{|n| n.label == name || n.id == name}
648
- if(net)
652
+ net = available_networks.detect { |n| n.label == name || n.id == name }
653
+ if net
649
654
  nets << net.id
650
655
  else
651
656
  ui.error("Failed to locate network: #{name}")
@@ -653,7 +658,7 @@ class Chef
653
658
  end
654
659
  end
655
660
  nets
656
- elsif(names && !names.empty?)
661
+ elsif names && !names.empty?
657
662
  ui.error("Custom networks are only available in v2 API")
658
663
  exit 1
659
664
  end