knife-azure 1.8.7 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/azure_interface.rb +79 -81
  3. data/lib/azure/custom_errors.rb +34 -35
  4. data/lib/azure/helpers.rb +43 -44
  5. data/lib/azure/resource_management/ARM_deployment_template.rb +679 -678
  6. data/lib/azure/resource_management/ARM_interface.rb +513 -515
  7. data/lib/azure/resource_management/vnet_config.rb +43 -43
  8. data/lib/azure/resource_management/windows_credentials.rb +181 -184
  9. data/lib/azure/service_management/ASM_interface.rb +309 -317
  10. data/lib/azure/service_management/ag.rb +16 -16
  11. data/lib/azure/service_management/certificate.rb +30 -31
  12. data/lib/azure/service_management/connection.rb +31 -31
  13. data/lib/azure/service_management/deploy.rb +40 -38
  14. data/lib/azure/service_management/disk.rb +14 -10
  15. data/lib/azure/service_management/host.rb +28 -24
  16. data/lib/azure/service_management/image.rb +23 -22
  17. data/lib/azure/service_management/loadbalancer.rb +12 -12
  18. data/lib/azure/service_management/rest.rb +20 -19
  19. data/lib/azure/service_management/role.rb +274 -273
  20. data/lib/azure/service_management/storageaccount.rb +29 -25
  21. data/lib/azure/service_management/utility.rb +6 -7
  22. data/lib/azure/service_management/vnet.rb +44 -44
  23. data/lib/chef/knife/azure_ag_create.rb +18 -18
  24. data/lib/chef/knife/azure_ag_list.rb +3 -3
  25. data/lib/chef/knife/azure_base.rb +56 -56
  26. data/lib/chef/knife/azure_image_list.rb +8 -10
  27. data/lib/chef/knife/azure_internal-lb_create.rb +15 -15
  28. data/lib/chef/knife/azure_internal-lb_list.rb +3 -3
  29. data/lib/chef/knife/azure_server_create.rb +49 -50
  30. data/lib/chef/knife/azure_server_delete.rb +22 -24
  31. data/lib/chef/knife/azure_server_list.rb +4 -4
  32. data/lib/chef/knife/azure_server_show.rb +5 -5
  33. data/lib/chef/knife/azure_vnet_create.rb +17 -17
  34. data/lib/chef/knife/azure_vnet_list.rb +3 -3
  35. data/lib/chef/knife/azurerm_base.rb +58 -60
  36. data/lib/chef/knife/azurerm_server_create.rb +23 -22
  37. data/lib/chef/knife/azurerm_server_delete.rb +30 -34
  38. data/lib/chef/knife/azurerm_server_list.rb +42 -42
  39. data/lib/chef/knife/azurerm_server_show.rb +1 -1
  40. data/lib/chef/knife/bootstrap/bootstrap_options.rb +7 -8
  41. data/lib/chef/knife/bootstrap/bootstrapper.rb +65 -65
  42. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +3 -4
  43. data/lib/chef/knife/bootstrap_azure.rb +13 -13
  44. data/lib/chef/knife/bootstrap_azurerm.rb +106 -106
  45. data/lib/knife-azure/version.rb +2 -2
  46. metadata +43 -76
  47. data/lib/azure/resource_management/ARM_base.rb +0 -29
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
4
- # Author:: Adam Jacob (<adam@opscode.com>)
5
- # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
3
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
4
+ # Author:: Adam Jacob (<adam@chef.io>)
5
+ # Copyright:: Copyright 2010-2018 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require File.expand_path('../azure_base', __FILE__)
21
+ require File.expand_path("../azure_base", __FILE__)
22
22
 
23
23
  class Chef
24
24
  class Knife
@@ -34,24 +34,22 @@ class Chef
34
34
  :boolean => true,
35
35
  :description => "Show all the fields of the images"
36
36
 
37
-
38
37
  def run
39
38
  $stdout.sync = true
40
39
 
41
40
  validate_asm_keys!
42
41
  items = service.list_images
43
42
 
44
- image_labels = !locate_config_value(:show_all_fields) ? ['Name', 'OS', 'Location'] : ['Name', 'Category', 'Label', 'OS', 'Location']
45
- image_list = image_labels.map {|label| ui.color(label, :bold)}
43
+ image_labels = !locate_config_value(:show_all_fields) ? %w{Name OS Location} : %w{Name Category Label OS Location}
44
+ image_list = image_labels.map { |label| ui.color(label, :bold) }
46
45
 
47
- image_items = image_labels.map {|item| item.downcase }
46
+ image_items = image_labels.map { |item| item.downcase }
48
47
  items.each do |image|
49
- image_items.each {|item| image_list << image.send(item).to_s }
48
+ image_items.each { |item| image_list << image.send(item).to_s }
50
49
  end
51
50
 
52
51
  puts "\n"
53
52
  puts ui.list(image_list, :uneven_columns_across, !locate_config_value(:show_all_fields) ? 3 : 5)
54
-
55
53
  end
56
54
  end
57
55
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aiman Alsari (aiman.alsari@gmail.com)
3
- # Copyright:: Copyright (c) 2013 Opscode, Inc.
3
+ # Copyright:: Copyright 2013-2018 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,28 +16,28 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path('../azure_base', __FILE__)
19
+ require File.expand_path("../azure_base", __FILE__)
20
20
 
21
21
  class Chef
22
22
  class Knife
23
23
  class AzureInternalLbCreate < Knife
24
24
  include Knife::AzureBase
25
25
 
26
- banner 'knife azure internal lb create (options)'
26
+ banner "knife azure internal lb create (options)"
27
27
 
28
28
  option :azure_load_balancer,
29
- :short => '-n NAME',
30
- :long => '--azure-load-balancer NAME',
31
- :description => 'Required. Specifies new load balancer name.'
29
+ :short => "-n NAME",
30
+ :long => "--azure-load-balancer NAME",
31
+ :description => "Required. Specifies new load balancer name."
32
32
 
33
33
  option :azure_lb_static_vip,
34
- :long => '--azure-lb-static-vip VIP',
35
- :description => 'Optional. The Virtual IP that will be used for the load balancer.'
34
+ :long => "--azure-lb-static-vip VIP",
35
+ :description => "Optional. The Virtual IP that will be used for the load balancer."
36
36
 
37
37
  option :azure_subnet_name,
38
- :long => '--azure-subnet-name SUBNET_NAME',
39
- :description => 'Required if static VIP is set. Specifies the subnet name '\
40
- 'the load balancer is located in.'
38
+ :long => "--azure-subnet-name SUBNET_NAME",
39
+ :description => "Required if static VIP is set. Specifies the subnet name "\
40
+ "the load balancer is located in."
41
41
 
42
42
  option :azure_dns_name,
43
43
  :long => "--azure-dns-name DNS_NAME",
@@ -46,7 +46,7 @@ class Chef
46
46
  def run
47
47
  $stdout.sync = true
48
48
 
49
- Chef::Log.info('validating...')
49
+ Chef::Log.info("validating...")
50
50
  validate_asm_keys!(:azure_load_balancer)
51
51
 
52
52
  params = {
@@ -58,9 +58,9 @@ class Chef
58
58
 
59
59
  rsp = service.create_internal_lb(params)
60
60
  print "\n"
61
- if rsp.at_css('Status').nil?
62
- if rsp.at_css('Code').nil? || rsp.at_css('Message').nil?
63
- puts 'Unknown Error. try -VV'
61
+ if rsp.at_css("Status").nil?
62
+ if rsp.at_css("Code").nil? || rsp.at_css("Message").nil?
63
+ puts "Unknown Error. try -VV"
64
64
  else
65
65
  puts "#{rsp.at_css('Code').content}: "\
66
66
  "#{rsp.at_css('Message').content}"
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aiman Alsari (aiman.alsari@gmail.com)
3
- # Copyright:: Copyright (c) 2013 Opscode, Inc.
3
+ # Copyright:: Copyright 2013-2018 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,14 +16,14 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require File.expand_path('../azure_base', __FILE__)
19
+ require File.expand_path("../azure_base", __FILE__)
20
20
 
21
21
  class Chef
22
22
  class Knife
23
23
  class AzureInternalLbList < Knife
24
24
  include Knife::AzureBase
25
25
 
26
- banner 'knife azure internal lb list (options)'
26
+ banner "knife azure internal lb list (options)"
27
27
 
28
28
  def run
29
29
  $stdout.sync = true
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Adam Jacob (<adam@opscode.com>)
4
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
5
- # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
3
+ # Author:: Adam Jacob (<adam@chef.io>)
4
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
5
+ # Copyright:: Copyright 2010-2018 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,11 +18,11 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require 'chef/knife/azure_base'
22
- require 'chef/knife/winrm_base'
23
- require 'securerandom'
24
- require 'chef/knife/bootstrap/bootstrap_options'
25
- require 'chef/knife/bootstrap/bootstrapper'
21
+ require "chef/knife/azure_base"
22
+ require "chef/knife/winrm_base"
23
+ require "securerandom"
24
+ require "chef/knife/bootstrap/bootstrap_options"
25
+ require "chef/knife/bootstrap/bootstrapper"
26
26
 
27
27
  class Chef
28
28
  class Knife
@@ -34,11 +34,11 @@ class Chef
34
34
  include Knife::Bootstrap::Bootstrapper
35
35
 
36
36
  deps do
37
- require 'readline'
38
- require 'chef/json_compat'
39
- require 'chef/knife/bootstrap'
40
- require 'chef/knife/bootstrap_windows_ssh'
41
- require 'chef/knife/core/windows_bootstrap_context'
37
+ require "readline"
38
+ require "chef/json_compat"
39
+ require "chef/knife/bootstrap"
40
+ require "chef/knife/bootstrap_windows_ssh"
41
+ require "chef/knife/core/windows_bootstrap_context"
42
42
  Chef::Knife::Bootstrap.load_deps
43
43
  end
44
44
 
@@ -46,7 +46,6 @@ class Chef
46
46
 
47
47
  attr_accessor :initial_sleep_delay
48
48
 
49
-
50
49
  option :bootstrap_protocol,
51
50
  :long => "--bootstrap-protocol protocol",
52
51
  :description => "Protocol to bootstrap windows servers. options: 'winrm' or 'ssh' or 'cloud-api'.",
@@ -71,7 +70,7 @@ class Chef
71
70
  :long => "--node-ssl-verify-mode [peer|none]",
72
71
  :description => "Whether or not to verify the SSL cert for all HTTPS requests.",
73
72
  :proc => Proc.new { |v|
74
- valid_values = ["none", "peer"]
73
+ valid_values = %w{none peer}
75
74
  unless valid_values.include?(v)
76
75
  raise "Invalid value '#{v}' for --node-ssl-verify-mode. Valid values are: #{valid_values.join(", ")}"
77
76
  end
@@ -131,8 +130,9 @@ class Chef
131
130
  option :azure_vm_size,
132
131
  :short => "-z SIZE",
133
132
  :long => "--azure-vm-size SIZE",
134
- :description => "Optional. Size of virtual machine (ExtraSmall, Small, Medium, Large, ExtraLarge)",
135
- :default => 'Small',
133
+ :description => "Optional. Size of virtual machine. Default is Standard_A1_v2.
134
+ Eg: Standard_A1_v2, Standard_F2, Standard_G1 etc.",
135
+ :default => "Standard_A1_v2",
136
136
  :proc => Proc.new { |si| Chef::Config[:knife][:azure_vm_size] = si }
137
137
 
138
138
  option :azure_availability_set,
@@ -263,14 +263,14 @@ class Chef
263
263
  end
264
264
  end
265
265
  rescue Exception => e
266
- Chef::Log.error("#{e.to_s}")
267
- raise 'Verify connectivity to Azure and subscription resource limit compliance (e.g. maximum CPU core limits) and try again.'
266
+ Chef::Log.error("#{e}")
267
+ raise "Verify connectivity to Azure and subscription resource limit compliance (e.g. maximum CPU core limits) and try again."
268
268
  end
269
269
  end
270
270
 
271
271
  def wait_for_virtual_machine_state(vm_status_goal, total_wait_time_in_minutes, retry_interval_in_seconds)
272
- vm_status_ordering = {:vm_status_not_detected => 0, :vm_status_provisioning => 1, :vm_status_ready => 2}
273
- vm_status_description = {:vm_status_not_detected => 'any', :vm_status_provisioning => 'provisioning', :vm_status_ready => 'ready'}
272
+ vm_status_ordering = { :vm_status_not_detected => 0, :vm_status_provisioning => 1, :vm_status_ready => 2 }
273
+ vm_status_description = { :vm_status_not_detected => "any", :vm_status_provisioning => "provisioning", :vm_status_ready => "ready" }
274
274
 
275
275
  print ui.color("Waiting for virtual machine to reach status '#{vm_status_description[vm_status_goal]}'", :magenta)
276
276
 
@@ -283,7 +283,7 @@ class Chef
283
283
  begin
284
284
  vm_status = get_virtual_machine_status()
285
285
  vm_ready = vm_status_ordering[vm_status] >= vm_status_ordering[vm_status_goal]
286
- print '.'
286
+ print "."
287
287
  sleep retry_interval_in_seconds if !vm_ready
288
288
  polling_attempts += 1
289
289
  end until vm_ready || polling_attempts >= max_polling_attempts
@@ -298,10 +298,9 @@ class Chef
298
298
  end
299
299
 
300
300
  def wait_for_resource_extension_state(extension_status_goal, total_wait_time_in_minutes, retry_interval_in_seconds)
301
+ extension_status_ordering = { :extension_status_not_detected => 0, :wagent_provisioning => 1, :extension_installing => 2, :extension_provisioning => 3, :extension_ready => 4 }
301
302
 
302
- extension_status_ordering = {:extension_status_not_detected => 0, :wagent_provisioning => 1, :extension_installing => 2, :extension_provisioning => 3, :extension_ready => 4}
303
-
304
- status_description = {:extension_status_not_detected => 'any', :wagent_provisioning => 'wagent provisioning', :extension_installing => "installing", :extension_provisioning => "provisioning", :extension_ready => "ready" }
303
+ status_description = { :extension_status_not_detected => "any", :wagent_provisioning => "wagent provisioning", :extension_installing => "installing", :extension_provisioning => "provisioning", :extension_ready => "ready" }
305
304
 
306
305
  print ui.color("Waiting for Resource Extension to reach status '#{status_description[extension_status_goal]}'", :magenta)
307
306
 
@@ -313,7 +312,7 @@ class Chef
313
312
  begin
314
313
  extension_status = get_extension_status()
315
314
  extension_ready = extension_status_ordering[extension_status[:status]] >= extension_status_ordering[extension_status_goal]
316
- print '.'
315
+ print "."
317
316
  sleep retry_interval_in_seconds if !extension_ready
318
317
  polling_attempts += 1
319
318
  end until extension_ready || polling_attempts >= max_polling_attempts
@@ -328,11 +327,11 @@ class Chef
328
327
  extension_status[:status]
329
328
  end
330
329
 
331
- def get_virtual_machine_status()
330
+ def get_virtual_machine_status
332
331
  role = service.get_role_server(locate_config_value(:azure_dns_name), locate_config_value(:azure_vm_name))
333
332
  unless role.nil?
334
- Chef::Log.debug("Role status is #{role.status.to_s}")
335
- if "ReadyRole".eql? role.status.to_s
333
+ Chef::Log.debug("Role status is #{role.status}")
334
+ if "ReadyRole".eql? role.status.to_s
336
335
  return :vm_status_ready
337
336
  elsif "Provisioning".eql? role.status.to_s
338
337
  return :vm_status_provisioning
@@ -340,16 +339,16 @@ class Chef
340
339
  return :vm_status_not_detected
341
340
  end
342
341
  end
343
- return :vm_status_not_detected
342
+ :vm_status_not_detected
344
343
  end
345
344
 
346
- def get_extension_status()
345
+ def get_extension_status
347
346
  deployment_name = service.deployment_name(locate_config_value(:azure_dns_name))
348
347
  deployment = service.deployment("hostedservices/#{locate_config_value(:azure_dns_name)}/deployments/#{deployment_name}")
349
348
  extension_status = Hash.new
350
349
 
351
- if deployment.at_css('Deployment Name') != nil
352
- role_list_xml = deployment.css('RoleInstanceList RoleInstance')
350
+ if deployment.at_css("Deployment Name") != nil
351
+ role_list_xml = deployment.css("RoleInstanceList RoleInstance")
353
352
  role_list_xml.each do |role|
354
353
  if role.at_css("RoleName").text == locate_config_value(:azure_vm_name)
355
354
  lnx_waagent_fail_msg = "Failed to deserialize the status reported by the Guest Agent"
@@ -370,7 +369,7 @@ class Chef
370
369
  extension_status[:status] = :extension_status_not_detected
371
370
  end
372
371
  # This fix is for linux waagent issue: api unable to deserialize the waagent status.
373
- elsif (role.at_css('GuestAgentStatus Status').text == 'NotReady') && (waagent_status_msg == lnx_waagent_fail_msg)
372
+ elsif (role.at_css("GuestAgentStatus Status").text == "NotReady") && (waagent_status_msg == lnx_waagent_fail_msg)
374
373
  extension_status[:status] = :extension_ready
375
374
  else
376
375
  extension_status[:status] = :wagent_provisioning
@@ -383,7 +382,7 @@ class Chef
383
382
  else
384
383
  extension_status[:status] = :extension_status_not_detected
385
384
  end
386
- return extension_status
385
+ extension_status
387
386
  end
388
387
 
389
388
  def run
@@ -399,14 +398,14 @@ class Chef
399
398
  config[:chef_node_name] = locate_config_value(:azure_vm_name) unless locate_config_value(:chef_node_name)
400
399
  service.create_server(create_server_def)
401
400
  wait_until_virtual_machine_ready()
402
- if locate_config_value(:bootstrap_protocol) == 'cloud-api' && locate_config_value(:extended_logs)
401
+ if locate_config_value(:bootstrap_protocol) == "cloud-api" && locate_config_value(:extended_logs)
403
402
  print "\n\nWaiting for the first chef-client run"
404
403
  fetch_chef_client_logs(Time.now, 30)
405
404
  end
406
405
  server = service.get_role_server(locate_config_value(:azure_dns_name), locate_config_value(:azure_vm_name))
407
406
  msg_server_summary(server)
408
407
 
409
- bootstrap_exec(server) unless locate_config_value(:bootstrap_protocol) == 'cloud-api'
408
+ bootstrap_exec(server) unless locate_config_value(:bootstrap_protocol) == "cloud-api"
410
409
  end
411
410
 
412
411
  def create_server_def
@@ -436,7 +435,7 @@ class Chef
436
435
  :winrm_max_memoryPerShell => locate_config_value(:winrm_max_memory_per_shell)
437
436
  }
438
437
 
439
- if locate_config_value(:bootstrap_protocol) == 'cloud-api'
438
+ if locate_config_value(:bootstrap_protocol) == "cloud-api"
440
439
  server_def[:chef_extension] = get_chef_extension_name
441
440
  server_def[:chef_extension_publisher] = get_chef_extension_publisher
442
441
  server_def[:chef_extension_version] = get_chef_extension_version
@@ -444,7 +443,7 @@ class Chef
444
443
  server_def[:chef_extension_private_param] = get_chef_extension_private_params
445
444
  else
446
445
  if is_image_windows?
447
- if not locate_config_value(:winrm_password) or not locate_config_value(:bootstrap_protocol)
446
+ if (not locate_config_value(:winrm_password)) || (not locate_config_value(:bootstrap_protocol))
448
447
  ui.error("WinRM Password and Bootstrapping Protocol are compulsory parameters")
449
448
  exit 1
450
449
  end
@@ -465,7 +464,7 @@ class Chef
465
464
  ui.error("SSH User is compulsory parameter")
466
465
  exit 1
467
466
  end
468
- unless locate_config_value(:ssh_password) or locate_config_value(:identity_file)
467
+ unless locate_config_value(:ssh_password) || locate_config_value(:identity_file)
469
468
  ui.error("Specify either SSH Key or SSH Password")
470
469
  exit 1
471
470
  end
@@ -473,12 +472,12 @@ class Chef
473
472
  end
474
473
 
475
474
  if is_image_windows?
476
- server_def[:os_type] = 'Windows'
475
+ server_def[:os_type] = "Windows"
477
476
  server_def[:admin_password] = locate_config_value(:winrm_password)
478
477
  server_def[:bootstrap_proto] = locate_config_value(:bootstrap_protocol)
479
478
  else
480
- server_def[:os_type] = 'Linux'
481
- server_def[:bootstrap_proto] = (locate_config_value(:bootstrap_protocol) == 'winrm') ? 'ssh' : locate_config_value(:bootstrap_protocol)
479
+ server_def[:os_type] = "Linux"
480
+ server_def[:bootstrap_proto] = (locate_config_value(:bootstrap_protocol) == "winrm") ? "ssh" : locate_config_value(:bootstrap_protocol)
482
481
  server_def[:ssh_user] = locate_config_value(:ssh_user)
483
482
  server_def[:ssh_password] = locate_config_value(:ssh_password)
484
483
  server_def[:identity_file] = locate_config_value(:identity_file)
@@ -486,11 +485,11 @@ class Chef
486
485
  end
487
486
 
488
487
  azure_connect_to_existing_dns = locate_config_value(:azure_connect_to_existing_dns)
489
- if is_image_windows? && server_def[:bootstrap_proto] == 'winrm'
490
- port = locate_config_value(:winrm_port) || '5985'
488
+ if is_image_windows? && server_def[:bootstrap_proto] == "winrm"
489
+ port = locate_config_value(:winrm_port) || "5985"
491
490
  port = locate_config_value(:winrm_port) || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
492
- elsif server_def[:bootstrap_proto] == 'ssh'
493
- port = locate_config_value(:ssh_port) || '22'
491
+ elsif server_def[:bootstrap_proto] == "ssh"
492
+ port = locate_config_value(:ssh_port) || "22"
494
493
  port = locate_config_value(:ssh_port) || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
495
494
  end
496
495
 
@@ -502,11 +501,11 @@ class Chef
502
501
  if locate_config_value(:azure_domain_user)
503
502
  # extract domain name since it should be part of username
504
503
  case locate_config_value(:azure_domain_user)
505
- when /(\S+)\\(.+)/ # format - fully-qualified-DNS-domain\username
504
+ when /(\S+)\\(.+)/ # format - fully-qualified-DNS-domain\username
506
505
  server_def[:azure_domain_name] = $1 if locate_config_value(:azure_domain_name).nil?
507
506
  server_def[:azure_user_domain_name] = $1
508
507
  server_def[:azure_domain_user] = $2
509
- when /(.+)@(\S+)/ # format - user@fully-qualified-DNS-domain
508
+ when /(.+)@(\S+)/ # format - user@fully-qualified-DNS-domain
510
509
  server_def[:azure_domain_name] = $2 if locate_config_value(:azure_domain_name).nil?
511
510
  server_def[:azure_user_domain_name] = $2
512
511
  server_def[:azure_domain_user] = $1
@@ -557,7 +556,7 @@ class Chef
557
556
  def get_dns_name(azure_dns_name, prefix = "az-")
558
557
  return azure_dns_name unless azure_dns_name.nil?
559
558
  if locate_config_value(:azure_vm_name).nil?
560
- azure_dns_name = prefix + SecureRandom.hex(( MAX_VM_NAME_CHARACTERS - prefix.length)/2)
559
+ azure_dns_name = prefix + SecureRandom.hex(( MAX_VM_NAME_CHARACTERS - prefix.length) / 2)
561
560
  else
562
561
  azure_dns_name = locate_config_value(:azure_vm_name)
563
562
  end
@@ -1,8 +1,8 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Author:: Adam Jacob (<adam@opscode.com>)
4
- # Author:: Seth Chisamore (<schisamo@opscode.com>)
5
- # Copyright:: Copyright (c) 2009-2011 Opscode, Inc.
3
+ # Author:: Adam Jacob (<adam@chef.io>)
4
+ # Author:: Seth Chisamore (<schisamo@chef.io>)
5
+ # Copyright:: Copyright 2009-2018 Chef Software, Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,11 +18,11 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require File.expand_path('../azure_base', __FILE__)
21
+ require File.expand_path("../azure_base", __FILE__)
22
22
 
23
23
  # These two are needed for the '--purge' deletion case
24
- require 'chef/node'
25
- require 'chef/api_client'
24
+ require "chef/node"
25
+ require "chef/api_client"
26
26
 
27
27
  class Chef
28
28
  class Knife
@@ -84,22 +84,20 @@ class Chef
84
84
  # the user is already making their intent known. It is not
85
85
  # necessary to make them confirm two more times.
86
86
  def destroy_item(klass, name, type_name)
87
- begin
88
- object = klass.load(name)
89
- object.destroy
90
- ui.warn("Deleted #{type_name} #{name}")
91
- rescue Net::HTTPServerException
92
- ui.warn("Could not find a #{type_name} named #{name} to delete. Please provide --node-name option and it's value")
93
- end
87
+ object = klass.load(name)
88
+ object.destroy
89
+ ui.warn("Deleted #{type_name} #{name}")
90
+ rescue Net::HTTPServerException
91
+ ui.warn("Could not find a #{type_name} named #{name} to delete. Please provide --node-name option and it's value")
94
92
  end
95
93
 
96
94
  def validate_disk_and_storage
97
- if locate_config_value(:preserve_azure_os_disk) && locate_config_value(:delete_azure_storage_account)
98
- ui.warn("Cannot delete storage account while keeping OS Disk. Please set any one option.")
99
- exit
100
- else
101
- true
102
- end
95
+ if locate_config_value(:preserve_azure_os_disk) && locate_config_value(:delete_azure_storage_account)
96
+ ui.warn("Cannot delete storage account while keeping OS Disk. Please set any one option.")
97
+ exit
98
+ else
99
+ true
100
+ end
103
101
  end
104
102
 
105
103
  def run
@@ -108,16 +106,16 @@ class Chef
108
106
  @name_args.each do |name|
109
107
  begin
110
108
  service.delete_server( { name: name, preserve_azure_os_disk: locate_config_value(:preserve_azure_os_disk),
111
- preserve_azure_vhd: locate_config_value(:preserve_azure_vhd),
112
- preserve_azure_dns_name: locate_config_value(:preserve_azure_dns_name),
113
- delete_azure_storage_account: locate_config_value(:delete_azure_storage_account),
109
+ preserve_azure_vhd: locate_config_value(:preserve_azure_vhd),
110
+ preserve_azure_dns_name: locate_config_value(:preserve_azure_dns_name),
111
+ delete_azure_storage_account: locate_config_value(:delete_azure_storage_account),
114
112
  wait: locate_config_value(:wait) } )
115
113
 
116
114
  if config[:purge]
117
115
  node_to_delete = config[:chef_node_name] || name
118
116
  if node_to_delete
119
- destroy_item(Chef::Node, node_to_delete, 'node')
120
- destroy_item(Chef::ApiClient, node_to_delete, 'client')
117
+ destroy_item(Chef::Node, node_to_delete, "node")
118
+ destroy_item(Chef::ApiClient, node_to_delete, "client")
121
119
  else
122
120
  ui.warn("Node name to purge not provided. Corresponding client node will remain on Chef Server.")
123
121
  end