knife-azure 2.0.17 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/azure_interface.rb +1 -1
  3. data/lib/azure/custom_errors.rb +1 -1
  4. data/lib/azure/helpers.rb +1 -1
  5. data/lib/azure/resource_management/ARM_deployment_template.rb +1 -1
  6. data/lib/azure/resource_management/ARM_interface.rb +5 -7
  7. data/lib/azure/resource_management/vnet_config.rb +1 -1
  8. data/lib/azure/resource_management/windows_credentials.rb +6 -7
  9. data/lib/azure/service_management/ASM_interface.rb +1 -1
  10. data/lib/azure/service_management/ag.rb +1 -1
  11. data/lib/azure/service_management/certificate.rb +4 -4
  12. data/lib/azure/service_management/connection.rb +1 -1
  13. data/lib/azure/service_management/deploy.rb +1 -1
  14. data/lib/azure/service_management/disk.rb +1 -1
  15. data/lib/azure/service_management/host.rb +1 -1
  16. data/lib/azure/service_management/image.rb +1 -1
  17. data/lib/azure/service_management/loadbalancer.rb +1 -1
  18. data/lib/azure/service_management/rest.rb +5 -4
  19. data/lib/azure/service_management/role.rb +2 -2
  20. data/lib/azure/service_management/storageaccount.rb +1 -1
  21. data/lib/azure/service_management/utility.rb +1 -1
  22. data/lib/azure/service_management/vnet.rb +1 -1
  23. data/lib/chef/knife/azure_ag_create.rb +4 -4
  24. data/lib/chef/knife/azure_ag_list.rb +1 -1
  25. data/lib/chef/knife/azure_image_list.rb +3 -3
  26. data/lib/chef/knife/azure_internal-lb_create.rb +5 -5
  27. data/lib/chef/knife/azure_internal-lb_list.rb +1 -1
  28. data/lib/chef/knife/azure_server_create.rb +71 -71
  29. data/lib/chef/knife/azure_server_delete.rb +7 -7
  30. data/lib/chef/knife/azure_server_list.rb +1 -1
  31. data/lib/chef/knife/azure_server_show.rb +1 -1
  32. data/lib/chef/knife/azure_vnet_create.rb +5 -5
  33. data/lib/chef/knife/azure_vnet_list.rb +1 -1
  34. data/lib/chef/knife/azurerm_server_create.rb +44 -44
  35. data/lib/chef/knife/azurerm_server_delete.rb +7 -7
  36. data/lib/chef/knife/azurerm_server_list.rb +2 -2
  37. data/lib/chef/knife/azurerm_server_show.rb +2 -2
  38. data/lib/chef/knife/bootstrap/bootstrapper.rb +33 -35
  39. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +3 -5
  40. data/lib/chef/knife/bootstrap_azure.rb +15 -15
  41. data/lib/chef/knife/bootstrap_azurerm.rb +6 -6
  42. data/lib/chef/knife/helpers/azure_base.rb +52 -63
  43. data/lib/chef/knife/helpers/azurerm_base.rb +43 -54
  44. data/lib/knife-azure/version.rb +2 -2
  45. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55796c18ca369c438d235edbbe415025af68ad22b27ca3a9a41ab926fbb5c0ac
4
- data.tar.gz: dfd5cc5a0bc90d0b42994a417deedd75041f224e08ac63a62049b972c362246b
3
+ metadata.gz: 8a120193f05d7ce565f575ffd1937b482a84b6ba67feef7ff1cb6a6e00d3b692
4
+ data.tar.gz: 5f6b7262ad5d2a88ebe3f15530fe0d46c77bb22e72525963986ae9d5d9125f64
5
5
  SHA512:
6
- metadata.gz: 411c2d695a55b7b2bee0ebfac1883b61ffe957388e02f391f2f6f6c1b7a907600d25f9a8768b5706e3df9c564462e10a606bed5714593082dc8491b87cda00e7
7
- data.tar.gz: b1d033dd7e856af827b365c5018b5ff90a4f91409c318b52146476f79f8c32a6c2b53d68456645c2db7c1f9b7cc7536fb519622cd5b969fb5a08ffa1fb9aed80
6
+ metadata.gz: fe70cb6103a17b9b19360614bc22819dddd767f7b63f769074c6dd08b91c5ff93a77c03c47d75e7cb4c32f59dedb48f59a05463f838a605e53ef700f191737e9
7
+ data.tar.gz: f2ab1d40bad24448b0f10824a16fcc4196393b35c6396d1b9016c8cf08bbc00d72fbd80bda17d29dee049c09029062a9eeec6d3b3341f17c1690a74b9c46af2e
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: vasundhara.jagdale@clogeny.com
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -323,7 +323,7 @@ module Azure
323
323
  else
324
324
  ui.log("Creating ResourceGroup....\n\n")
325
325
  resource_group = create_resource_group(params)
326
- Chef::Log.info("ResourceGroup creation successfull.")
326
+ Chef::Log.info("ResourceGroup creation successful.")
327
327
  Chef::Log.info("Resource Group name is: #{resource_group.name}")
328
328
  Chef::Log.info("Resource Group ID is: #{resource_group.id}")
329
329
  end
@@ -355,7 +355,7 @@ module Azure
355
355
 
356
356
  ui.log("Creating Virtual Machine....")
357
357
  deployment = create_virtual_machine_using_template(params)
358
- ui.log("Virtual Machine creation successfull.") unless deployment.nil?
358
+ ui.log("Virtual Machine creation successful.") unless deployment.nil?
359
359
 
360
360
  unless deployment.nil?
361
361
  ui.log("Deployment name is: #{deployment.name}")
@@ -422,8 +422,7 @@ module Azure
422
422
  deploy_params = Deployment.new
423
423
  deploy_params.properties = deploy_prop
424
424
 
425
- deployment = resource_management_client.deployments.create_or_update(params[:azure_resource_group_name], "#{params[:azure_vm_name]}_deploy", deploy_params)
426
- deployment
425
+ resource_management_client.deployments.create_or_update(params[:azure_resource_group_name], "#{params[:azure_vm_name]}_deploy", deploy_params)
427
426
  end
428
427
 
429
428
  def create_vm_extension(params)
@@ -467,8 +466,7 @@ module Azure
467
466
  params[:chef_extension]
468
467
  ).last.name
469
468
  ext_version_split_values = ext_version.split(".")
470
- ext_version = ext_version_split_values[0] + "." + ext_version_split_values[1]
471
- ext_version
469
+ ext_version_split_values[0] + "." + ext_version_split_values[1]
472
470
  end
473
471
 
474
472
  def delete_resource_group(resource_group_name)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -19,8 +19,8 @@
19
19
  # XPLAT stores the access token and other information in windows credential manager.
20
20
  # Using FFI to call CredRead function
21
21
  require "chef"
22
- require "mixlib/shellout"
23
- require "ffi"
22
+ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
23
+ require "ffi" unless defined?(FFI)
24
24
  require "chef/win32/api"
25
25
 
26
26
  module Azure
@@ -123,8 +123,8 @@ module Azure
123
123
  def target_name
124
124
  # cmdkey command is used for accessing windows credential manager.
125
125
  # Multiple credentials get created in windows credential manager for a single Azure account in xplat-cli
126
- # One of them is for common tanent id, which can't be used
127
- # Others end with --0-x,--1-x,--2-x etc, where x represents the total no. of credentails across which the token is divided
126
+ # One of them is for common tenant id, which can't be used
127
+ # Others end with --0-x,--1-x,--2-x etc, where x represents the total no. of credentials across which the token is divided
128
128
  # The one ending with --0-x has the complete accessToken in the credentialBlob.
129
129
  # Refresh Token is split across both credentials (ending with --0-x and --1-x).
130
130
  # Xplat splits the credentials based on the number of bytes of the tokens.
@@ -150,8 +150,7 @@ module Azure
150
150
 
151
151
  # If "azure login" is run for multiple users, there will be multiple credentials
152
152
  # Picking up the latest logged in user's credentials
153
- latest_target = latest_credential_target target_names
154
- latest_target
153
+ latest_credential_target target_names
155
154
  end
156
155
 
157
156
  def latest_credential_target(targets)
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Mukta Aphale (mukta.aphale@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -85,7 +85,7 @@ module Azure
85
85
  ca.add_extension(ef.create_extension("keyUsage", "keyCertSign, cRLSign", true))
86
86
  ca.add_extension(ef.create_extension("subjectKeyIdentifier", "hash", false))
87
87
  ca.add_extension(ef.create_extension("authorityKeyIdentifier", "keyid:always", false))
88
- ca.sign(key, OpenSSL::Digest::SHA256.new)
88
+ ca.sign(key, OpenSSL::Digest.new("SHA256"))
89
89
  # Generate the SHA1 fingerprint of the der format of the X 509 certificate
90
90
  @fingerprint = OpenSSL::Digest::SHA1.new(ca.to_der)
91
91
  # Create the pfx format of the certificate
@@ -142,7 +142,7 @@ module Azure
142
142
  puts "Certificate Thumbprint: #{@thumbprint.to_s.upcase}"
143
143
  puts "*" * 70
144
144
 
145
- Chef::Config[:knife][:ca_trust_file] = file_path + ".pem" if Chef::Config[:knife][:ca_trust_file].nil?
145
+ config[:ca_trust_file] = file_path + ".pem" if config[:ca_trust_file].nil?
146
146
  cert_data = File.read (file_path + ".b64")
147
147
  add_certificate cert_data, @winrm_cert_passphrase, "pfx", cert_params[:azure_dns_name]
148
148
  @thumbprint
@@ -216,7 +216,7 @@ module Azure
216
216
  cert.add_extension(ef.create_extension("subjectKeyIdentifier", "hash", false))
217
217
  cert.add_extension(ef.create_extension("authorityKeyIdentifier", "keyid:always", false))
218
218
  cert.add_extension(ef.create_extension("extendedKeyUsage", "1.3.6.1.5.5.7.3.1", false))
219
- cert.sign(rsa_key, OpenSSL::Digest::SHA1.new)
219
+ cert.sign(rsa_key, OpenSSL::Digest.new("SHA1"))
220
220
  @thumbprint = OpenSSL::Digest::SHA1.new(cert.to_der)
221
221
  cert
222
222
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aiman Alsari (aiman.alsari@gmail.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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,9 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "net/https"
20
- require "uri"
21
- require "nokogiri"
19
+ require "net/http" unless defined?(Net::HTTP)
20
+ require "openssl" unless defined?(OpenSSL)
21
+ require "uri" unless defined?(URI)
22
+ require "nokogiri" unless defined?(Nokogiri)
22
23
 
23
24
  module AzureAPI
24
25
 
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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 "securerandom"
19
+ require "securerandom" unless defined?(SecureRandom)
20
20
  require_relative "utility"
21
21
 
22
22
  module Azure
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -50,9 +50,9 @@ class Chef
50
50
  :azure_service_location)
51
51
 
52
52
  params = {
53
- azure_ag_name: locate_config_value(:azure_affinity_group),
54
- azure_ag_desc: locate_config_value(:azure_ag_desc),
55
- azure_location: locate_config_value(:azure_service_location),
53
+ azure_ag_name: config[:azure_affinity_group],
54
+ azure_ag_desc: config[:azure_ag_desc],
55
+ azure_location: config[:azure_service_location],
56
56
  }
57
57
 
58
58
  rsp = service.create_affinity_group(params)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Seth Chisamore (<schisamo@chef.io>)
4
4
  # Author:: Adam Jacob (<adam@chef.io>)
5
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
5
+ # Copyright:: Copyright (c) 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");
@@ -40,7 +40,7 @@ class Chef
40
40
  validate_asm_keys!
41
41
  items = service.list_images
42
42
 
43
- image_labels = !locate_config_value(:show_all_fields) ? %w{Name OS Location} : %w{Name Category Label OS Location}
43
+ image_labels = !config[:show_all_fields] ? %w{Name OS Location} : %w{Name Category Label OS Location}
44
44
  image_list = image_labels.map { |label| ui.color(label, :bold) }
45
45
 
46
46
  image_items = image_labels.map(&:downcase)
@@ -49,7 +49,7 @@ class Chef
49
49
  end
50
50
 
51
51
  puts "\n"
52
- puts ui.list(image_list, :uneven_columns_across, !locate_config_value(:show_all_fields) ? 3 : 5)
52
+ puts ui.list(image_list, :uneven_columns_across, !config[:show_all_fields] ? 3 : 5)
53
53
  end
54
54
  end
55
55
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aiman Alsari (aiman.alsari@gmail.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -50,10 +50,10 @@ class Chef
50
50
  validate_asm_keys!(:azure_load_balancer)
51
51
 
52
52
  params = {
53
- azure_load_balancer: locate_config_value(:azure_load_balancer),
54
- azure_lb_static_vip: locate_config_value(:azure_lb_static_vip),
55
- azure_subnet_name: locate_config_value(:azure_subnet_name),
56
- azure_dns_name: locate_config_value(:azure_dns_name),
53
+ azure_load_balancer: config[:azure_load_balancer],
54
+ azure_lb_static_vip: config[:azure_lb_static_vip],
55
+ azure_subnet_name: config[:azure_subnet_name],
56
+ azure_dns_name: config[:azure_dns_name],
57
57
  }
58
58
 
59
59
  rsp = service.create_internal_lb(params)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aiman Alsari (aiman.alsari@gmail.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) 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");
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Adam Jacob (<adam@chef.io>)
4
4
  # Author:: Seth Chisamore (<schisamo@chef.io>)
5
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
5
+ # Copyright:: Copyright (c) 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");
@@ -32,7 +32,7 @@ class Chef
32
32
  include Knife::Bootstrap::Bootstrapper
33
33
 
34
34
  deps do
35
- require "securerandom"
35
+ require "securerandom" unless defined?(SecureRandom)
36
36
  require "readline"
37
37
  require "chef/json_compat"
38
38
  require "chef/knife/bootstrap"
@@ -196,7 +196,7 @@ class Chef
196
196
 
197
197
  config[:connection_port] = server_def[:port]
198
198
  config[:connection_protocol] = server_def[:connection_protocol]
199
- config[:chef_node_name] = locate_config_value(:chef_node_name) || server_name
199
+ config[:chef_node_name] = config[:chef_node_name] || server_name
200
200
  rescue => error
201
201
  ui.error("Something went wrong. Please use -VV option for more details.")
202
202
  Chef::Log.debug(error.backtrace.join("\n").to_s)
@@ -216,7 +216,7 @@ class Chef
216
216
  alias host_descriptor server_name
217
217
 
218
218
  def plugin_finalize
219
- if locate_config_value(:connection_protocol) == "cloud-api" && locate_config_value(:extended_logs)
219
+ if config[:connection_protocol] == "cloud-api" && config[:extended_logs]
220
220
  print "\nWaiting for the first chef-client run"
221
221
  fetch_chef_client_logs(Time.now, 30)
222
222
  end
@@ -228,8 +228,8 @@ class Chef
228
228
  def wait_until_virtual_machine_ready(retry_interval_in_seconds = 30)
229
229
  vm_status = nil
230
230
  begin
231
- azure_vm_startup_timeout = locate_config_value(:azure_vm_startup_timeout).to_i
232
- azure_vm_ready_timeout = locate_config_value(:azure_vm_ready_timeout).to_i
231
+ azure_vm_startup_timeout = config[:azure_vm_startup_timeout].to_i
232
+ azure_vm_ready_timeout = config[:azure_vm_ready_timeout].to_i
233
233
  vm_status = wait_for_virtual_machine_state(:vm_status_provisioning, azure_vm_startup_timeout, retry_interval_in_seconds)
234
234
  if vm_status != :vm_status_ready
235
235
  begin
@@ -242,7 +242,7 @@ class Chef
242
242
 
243
243
  msg_server_summary(@server)
244
244
 
245
- if locate_config_value(:connection_protocol) == "cloud-api"
245
+ if config[:connection_protocol] == "cloud-api"
246
246
  extension_status = wait_for_resource_extension_state(:wagent_provisioning, 5, retry_interval_in_seconds)
247
247
 
248
248
  if extension_status != :extension_installing
@@ -323,7 +323,7 @@ class Chef
323
323
  end
324
324
 
325
325
  def get_virtual_machine_status
326
- @server = service.get_role_server(locate_config_value(:azure_dns_name), locate_config_value(:azure_vm_name))
326
+ @server = service.get_role_server(config[:azure_dns_name], config[:azure_vm_name])
327
327
  if @server.nil?
328
328
  :vm_status_not_detected
329
329
  else
@@ -340,14 +340,14 @@ class Chef
340
340
  end
341
341
 
342
342
  def get_extension_status
343
- deployment_name = service.deployment_name(locate_config_value(:azure_dns_name))
344
- deployment = service.deployment("hostedservices/#{locate_config_value(:azure_dns_name)}/deployments/#{deployment_name}")
343
+ deployment_name = service.deployment_name(config[:azure_dns_name])
344
+ deployment = service.deployment("hostedservices/#{config[:azure_dns_name]}/deployments/#{deployment_name}")
345
345
  extension_status = {}
346
346
 
347
347
  if deployment.at_css("Deployment Name") != nil
348
348
  role_list_xml = deployment.css("RoleInstanceList RoleInstance")
349
349
  role_list_xml.each do |role|
350
- if role.at_css("RoleName").text == locate_config_value(:azure_vm_name)
350
+ if role.at_css("RoleName").text == config[:azure_vm_name]
351
351
  lnx_waagent_fail_msg = "Failed to deserialize the status reported by the Guest Agent"
352
352
  waagent_status_msg = role.at_css("GuestAgentStatus FormattedMessage Message").text
353
353
  if role.at_css("GuestAgentStatus Status").text == "Ready"
@@ -384,32 +384,32 @@ class Chef
384
384
 
385
385
  def create_server_def
386
386
  server_def = {
387
- azure_storage_account: locate_config_value(:azure_storage_account),
388
- azure_api_host_name: locate_config_value(:azure_api_host_name),
389
- azure_dns_name: locate_config_value(:azure_dns_name),
390
- azure_vm_name: locate_config_value(:azure_vm_name),
391
- azure_service_location: locate_config_value(:azure_service_location),
392
- azure_os_disk_name: locate_config_value(:azure_os_disk_name),
393
- azure_source_image: locate_config_value(:azure_source_image),
394
- azure_vm_size: locate_config_value(:azure_vm_size),
395
- tcp_endpoints: locate_config_value(:tcp_endpoints),
396
- udp_endpoints: locate_config_value(:udp_endpoints),
397
- connection_protocol: locate_config_value(:connection_protocol),
398
- azure_connect_to_existing_dns: locate_config_value(:azure_connect_to_existing_dns),
399
- connection_user: locate_config_value(:connection_user),
400
- azure_availability_set: locate_config_value(:azure_availability_set),
401
- azure_affinity_group: locate_config_value(:azure_affinity_group),
402
- azure_network_name: locate_config_value(:azure_network_name),
403
- azure_subnet_name: locate_config_value(:azure_subnet_name),
404
- ssl_cert_fingerprint: locate_config_value(:thumbprint),
405
- cert_path: locate_config_value(:cert_path),
406
- cert_password: locate_config_value(:cert_passphrase),
407
- winrm_ssl: locate_config_value(:winrm_ssl),
408
- winrm_max_timeout: locate_config_value(:winrm_max_timeout).to_i * 60 * 1000, # converting minutes to milliseconds
409
- winrm_max_memory_per_shell: locate_config_value(:winrm_max_memory_per_shell),
387
+ azure_storage_account: config[:azure_storage_account],
388
+ azure_api_host_name: config[:azure_api_host_name],
389
+ azure_dns_name: config[:azure_dns_name],
390
+ azure_vm_name: config[:azure_vm_name],
391
+ azure_service_location: config[:azure_service_location],
392
+ azure_os_disk_name: config[:azure_os_disk_name],
393
+ azure_source_image: config[:azure_source_image],
394
+ azure_vm_size: config[:azure_vm_size],
395
+ tcp_endpoints: config[:tcp_endpoints],
396
+ udp_endpoints: config[:udp_endpoints],
397
+ connection_protocol: config[:connection_protocol],
398
+ azure_connect_to_existing_dns: config[:azure_connect_to_existing_dns],
399
+ connection_user: config[:connection_user],
400
+ azure_availability_set: config[:azure_availability_set],
401
+ azure_affinity_group: config[:azure_affinity_group],
402
+ azure_network_name: config[:azure_network_name],
403
+ azure_subnet_name: config[:azure_subnet_name],
404
+ ssl_cert_fingerprint: config[:thumbprint],
405
+ cert_path: config[:cert_path],
406
+ cert_password: config[:cert_passphrase],
407
+ winrm_ssl: config[:winrm_ssl],
408
+ winrm_max_timeout: config[:winrm_max_timeout].to_i * 60 * 1000, # converting minutes to milliseconds
409
+ winrm_max_memory_per_shell: config[:winrm_max_memory_per_shell],
410
410
  }
411
411
 
412
- if locate_config_value(:connection_protocol) == "cloud-api"
412
+ if config[:connection_protocol] == "cloud-api"
413
413
  server_def[:chef_extension] = get_chef_extension_name
414
414
  server_def[:chef_extension_publisher] = get_chef_extension_publisher
415
415
  server_def[:chef_extension_version] = get_chef_extension_version
@@ -420,20 +420,20 @@ class Chef
420
420
  # We can specify the AdminUsername after API version 2013-03-01. However, in this API version,
421
421
  # the AdminUsername is a required parameter.
422
422
  # Also, the user name cannot be Administrator, Admin, Admin1 etc, for enhanced security (provided by Azure)
423
- if locate_config_value(:connection_user).nil? || locate_config_value(:connection_user).downcase =~ /admin*/
423
+ if config[:connection_user].nil? || config[:connection_user].downcase =~ /admin*/
424
424
  ui.error("Connection User is compulsory parameter and it cannot be named 'admin*'")
425
425
  exit 1
426
426
  # take cares of when user name contains domain
427
427
  # azure add role api doesn't support '\\' in user name
428
- elsif locate_config_value(:connection_user).split('\\').length.eql?(2)
429
- server_def[:connection_user] = locate_config_value(:connection_user).split('\\')[1]
428
+ elsif config[:connection_user].split('\\').length.eql?(2)
429
+ server_def[:connection_user] = config[:connection_user].split('\\')[1]
430
430
  end
431
431
  else
432
- unless locate_config_value(:connection_user)
432
+ unless config[:connection_user]
433
433
  ui.error("Connection User is compulsory parameter")
434
434
  exit 1
435
435
  end
436
- unless locate_config_value(:connection_password) || locate_config_value(:ssh_identity_file)
436
+ unless config[:connection_password] || config[:ssh_identity_file]
437
437
  ui.error("Specify either SSH Key or SSH Password")
438
438
  exit 1
439
439
  end
@@ -442,52 +442,52 @@ class Chef
442
442
 
443
443
  if is_image_windows?
444
444
  server_def[:os_type] = "Windows"
445
- server_def[:admin_password] = locate_config_value(:connection_password)
446
- server_def[:connection_protocol] = locate_config_value(:connection_protocol) || "winrm"
445
+ server_def[:admin_password] = config[:connection_password]
446
+ server_def[:connection_protocol] = config[:connection_protocol] || "winrm"
447
447
  else
448
448
  server_def[:os_type] = "Linux"
449
- server_def[:connection_protocol] = locate_config_value(:connection_protocol).nil? || locate_config_value(:connection_protocol) == "winrm" ? "ssh" : locate_config_value(:connection_protocol)
450
- server_def[:connection_user] = locate_config_value(:connection_user)
451
- server_def[:connection_password] = locate_config_value(:connection_password)
452
- server_def[:ssh_identity_file] = locate_config_value(:ssh_identity_file)
453
- server_def[:identity_file_passphrase] = locate_config_value(:identity_file_passphrase)
449
+ server_def[:connection_protocol] = config[:connection_protocol].nil? || config[:connection_protocol] == "winrm" ? "ssh" : config[:connection_protocol]
450
+ server_def[:connection_user] = config[:connection_user]
451
+ server_def[:connection_password] = config[:connection_password]
452
+ server_def[:ssh_identity_file] = config[:ssh_identity_file]
453
+ server_def[:identity_file_passphrase] = config[:identity_file_passphrase]
454
454
  end
455
455
 
456
- azure_connect_to_existing_dns = locate_config_value(:azure_connect_to_existing_dns)
456
+ azure_connect_to_existing_dns = config[:azure_connect_to_existing_dns]
457
457
  if is_image_windows? && server_def[:connection_protocol] == "winrm"
458
- port = locate_config_value(:connection_port) || "5985"
459
- port = locate_config_value(:connection_port) || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
458
+ port = config[:connection_port] || "5985"
459
+ port = config[:connection_port] || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
460
460
  elsif server_def[:connection_protocol] == "ssh"
461
- port = locate_config_value(:connection_port) || "22"
462
- port = locate_config_value(:connection_port) || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
461
+ port = config[:connection_port] || "22"
462
+ port = config[:connection_port] || Random.rand(64000) + 1000 if azure_connect_to_existing_dns
463
463
  end
464
464
 
465
465
  server_def[:port] = port
466
466
 
467
- server_def[:is_vm_image] = service.vm_image?(locate_config_value(:azure_source_image))
468
- server_def[:azure_domain_name] = locate_config_value(:azure_domain_name) if locate_config_value(:azure_domain_name)
467
+ server_def[:is_vm_image] = service.vm_image?(config[:azure_source_image])
468
+ server_def[:azure_domain_name] = config[:azure_domain_name] if config[:azure_domain_name]
469
469
 
470
- if locate_config_value(:azure_domain_user)
470
+ if config[:azure_domain_user]
471
471
  # extract domain name since it should be part of username
472
- case locate_config_value(:azure_domain_user)
472
+ case config[:azure_domain_user]
473
473
  when /(\S+)\\(.+)/ # format - fully-qualified-DNS-domain\username
474
- server_def[:azure_domain_name] = $1 if locate_config_value(:azure_domain_name).nil?
474
+ server_def[:azure_domain_name] = $1 if config[:azure_domain_name].nil?
475
475
  server_def[:azure_user_domain_name] = $1
476
476
  server_def[:azure_domain_user] = $2
477
477
  when /(.+)@(\S+)/ # format - user@fully-qualified-DNS-domain
478
- server_def[:azure_domain_name] = $2 if locate_config_value(:azure_domain_name).nil?
478
+ server_def[:azure_domain_name] = $2 if config[:azure_domain_name].nil?
479
479
  server_def[:azure_user_domain_name] = $2
480
480
  server_def[:azure_domain_user] = $1
481
481
  else
482
- if locate_config_value(:azure_domain_name).nil?
482
+ if config[:azure_domain_name].nil?
483
483
  ui.error('--azure-domain-name should be specified if --azure-domain-user is not in one of the following formats: fully-qualified-DNS-domain\username, user@fully-qualified-DNS-domain')
484
484
  exit 1
485
485
  end
486
- server_def[:azure_domain_user] = locate_config_value(:azure_domain_user)
486
+ server_def[:azure_domain_user] = config[:azure_domain_user]
487
487
  end
488
488
  end
489
- server_def[:azure_domain_passwd] = locate_config_value(:azure_domain_passwd)
490
- server_def[:azure_domain_ou_dn] = locate_config_value(:azure_domain_ou_dn)
489
+ server_def[:azure_domain_passwd] = config[:azure_domain_passwd]
490
+ server_def[:azure_domain_ou_dn] = config[:azure_domain_ou_dn]
491
491
 
492
492
  server_def
493
493
  end
@@ -499,17 +499,17 @@ class Chef
499
499
  end
500
500
 
501
501
  def set_configs
502
- unless locate_config_value(:connection_user).nil?
503
- config[:connection_user] = locate_config_value(:connection_user)
502
+ unless config[:connection_user].nil?
503
+ config[:connection_user] = config[:connection_user]
504
504
  end
505
505
 
506
- unless locate_config_value(:connection_password).nil?
507
- config[:connection_password] = locate_config_value(:connection_password)
506
+ unless config[:connection_password].nil?
507
+ config[:connection_password] = config[:connection_password]
508
508
  end
509
509
 
510
- config[:azure_dns_name] = get_dns_name(locate_config_value(:azure_dns_name))
511
- config[:azure_vm_name] = locate_config_value(:azure_dns_name) unless locate_config_value(:azure_vm_name)
512
- config[:chef_node_name] = locate_config_value(:azure_vm_name) unless locate_config_value(:chef_node_name)
510
+ config[:azure_dns_name] = get_dns_name(config[:azure_dns_name])
511
+ config[:azure_vm_name] = config[:azure_dns_name] unless config[:azure_vm_name]
512
+ config[:chef_node_name] = config[:azure_vm_name] unless config[:chef_node_name]
513
513
  end
514
514
 
515
515
  # This is related to Windows VM's specifically and computer name
@@ -520,10 +520,10 @@ class Chef
520
520
  def get_dns_name(azure_dns_name, prefix = "az-")
521
521
  return azure_dns_name unless azure_dns_name.nil?
522
522
 
523
- if locate_config_value(:azure_vm_name).nil?
523
+ if config[:azure_vm_name].nil?
524
524
  (prefix + SecureRandom.hex((MAX_VM_NAME_CHARACTERS - prefix.length) / 2))
525
525
  else
526
- locate_config_value(:azure_vm_name)
526
+ config[:azure_vm_name]
527
527
  end
528
528
  end
529
529
  end