knife-azure 2.0.13 → 3.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/azure/azure_interface.rb +1 -1
- data/lib/azure/custom_errors.rb +1 -1
- data/lib/azure/helpers.rb +1 -1
- data/lib/azure/resource_management/ARM_deployment_template.rb +1 -1
- data/lib/azure/resource_management/ARM_interface.rb +7 -9
- data/lib/azure/resource_management/vnet_config.rb +2 -2
- data/lib/azure/resource_management/windows_credentials.rb +6 -7
- data/lib/azure/service_management/ASM_interface.rb +1 -1
- data/lib/azure/service_management/ag.rb +1 -1
- data/lib/azure/service_management/certificate.rb +4 -4
- data/lib/azure/service_management/connection.rb +1 -1
- data/lib/azure/service_management/deploy.rb +1 -1
- data/lib/azure/service_management/disk.rb +1 -1
- data/lib/azure/service_management/host.rb +1 -1
- data/lib/azure/service_management/image.rb +1 -1
- data/lib/azure/service_management/loadbalancer.rb +1 -1
- data/lib/azure/service_management/rest.rb +5 -4
- data/lib/azure/service_management/role.rb +2 -2
- data/lib/azure/service_management/storageaccount.rb +1 -1
- data/lib/azure/service_management/utility.rb +1 -1
- data/lib/azure/service_management/vnet.rb +1 -1
- data/lib/chef/knife/azure_ag_create.rb +4 -4
- data/lib/chef/knife/azure_ag_list.rb +1 -1
- data/lib/chef/knife/azure_image_list.rb +3 -3
- data/lib/chef/knife/azure_internal-lb_create.rb +5 -5
- data/lib/chef/knife/azure_internal-lb_list.rb +1 -1
- data/lib/chef/knife/azure_server_create.rb +71 -71
- data/lib/chef/knife/azure_server_delete.rb +7 -7
- data/lib/chef/knife/azure_server_list.rb +1 -1
- data/lib/chef/knife/azure_server_show.rb +1 -1
- data/lib/chef/knife/azure_vnet_create.rb +5 -5
- data/lib/chef/knife/azure_vnet_list.rb +1 -1
- data/lib/chef/knife/azurerm_server_create.rb +45 -45
- data/lib/chef/knife/azurerm_server_delete.rb +8 -8
- data/lib/chef/knife/azurerm_server_list.rb +3 -3
- data/lib/chef/knife/azurerm_server_show.rb +3 -3
- data/lib/chef/knife/bootstrap/bootstrapper.rb +29 -35
- data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +3 -5
- data/lib/chef/knife/bootstrap_azure.rb +15 -15
- data/lib/chef/knife/bootstrap_azurerm.rb +7 -7
- data/lib/chef/knife/helpers/azure_base.rb +54 -65
- data/lib/chef/knife/helpers/azurerm_base.rb +46 -57
- data/lib/knife-azure/version.rb +2 -2
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09efc06fd6788aa94f2af8ace7bd411b9d90c4f3df736a0559997bc5298a5336'
|
4
|
+
data.tar.gz: 6cfd515b9371c8d4a7c0c7ed58575f581470c2ecd3ed7604329291c2fb1a1eec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8e905e8136596fa27fa18898f73dd871138f52118792939df1be75da3f4122bcf358529605793b0a517fb7cf37036bf0b3b7f85ff57ffcec1a8aa1efff45652
|
7
|
+
data.tar.gz: 25b0054daa620887733644c1ad87983fd7e5c325de4781071c81773dee39f83c7a8c2a308c9ee1341220583be9415d8596fa8ac9cf525fd32d0d2facec11c8d0
|
data/lib/azure/custom_errors.rb
CHANGED
data/lib/azure/helpers.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
|
3
|
-
# Copyright:: Copyright
|
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
|
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");
|
@@ -215,7 +215,7 @@ module Azure
|
|
215
215
|
if e.body
|
216
216
|
err_json = JSON.parse(e.response.body)
|
217
217
|
if err_json["error"]["code"] == "ResourceNotFound"
|
218
|
-
|
218
|
+
false
|
219
219
|
else
|
220
220
|
raise e
|
221
221
|
end
|
@@ -229,7 +229,7 @@ module Azure
|
|
229
229
|
if e.body
|
230
230
|
err_json = JSON.parse(e.response.body)
|
231
231
|
if err_json["error"]["code"] == "ResourceNotFound"
|
232
|
-
|
232
|
+
false
|
233
233
|
else
|
234
234
|
raise e
|
235
235
|
end
|
@@ -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
|
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
|
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
|
-
|
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
|
-
|
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
|
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");
|
@@ -41,7 +41,7 @@ module Azure::ARM
|
|
41
41
|
if error.body
|
42
42
|
err_json = JSON.parse(error.response.body)
|
43
43
|
if err_json["error"]["code"] == "ResourceNotFound"
|
44
|
-
|
44
|
+
false
|
45
45
|
else
|
46
46
|
raise error
|
47
47
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
|
3
|
-
# Copyright:: Copyright
|
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
|
127
|
-
# Others end with --0-x,--1-x,--2-x etc, where x represents the total no. of
|
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
|
-
|
154
|
-
latest_target
|
153
|
+
latest_credential_target target_names
|
155
154
|
end
|
156
155
|
|
157
156
|
def latest_credential_target(targets)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Jeff Mendoza (jeffmendoza@live.com)
|
3
|
-
# Copyright:: Copyright
|
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
|
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
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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/
|
20
|
-
require "
|
21
|
-
require "
|
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
|
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
|
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
|
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
|
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
|
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:
|
54
|
-
azure_ag_desc:
|
55
|
-
azure_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
|
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
|
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 = !
|
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, !
|
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
|
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:
|
54
|
-
azure_lb_static_vip:
|
55
|
-
azure_subnet_name:
|
56
|
-
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
|
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
|
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] =
|
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
|
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 =
|
232
|
-
azure_vm_ready_timeout =
|
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
|
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(
|
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(
|
344
|
-
deployment = service.deployment("hostedservices/#{
|
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 ==
|
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:
|
388
|
-
azure_api_host_name:
|
389
|
-
azure_dns_name:
|
390
|
-
azure_vm_name:
|
391
|
-
azure_service_location:
|
392
|
-
azure_os_disk_name:
|
393
|
-
azure_source_image:
|
394
|
-
azure_vm_size:
|
395
|
-
tcp_endpoints:
|
396
|
-
udp_endpoints:
|
397
|
-
connection_protocol:
|
398
|
-
azure_connect_to_existing_dns:
|
399
|
-
connection_user:
|
400
|
-
azure_availability_set:
|
401
|
-
azure_affinity_group:
|
402
|
-
azure_network_name:
|
403
|
-
azure_subnet_name:
|
404
|
-
ssl_cert_fingerprint:
|
405
|
-
cert_path:
|
406
|
-
cert_password:
|
407
|
-
winrm_ssl:
|
408
|
-
winrm_max_timeout:
|
409
|
-
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
|
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
|
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
|
429
|
-
server_def[:connection_user] =
|
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
|
432
|
+
unless config[:connection_user]
|
433
433
|
ui.error("Connection User is compulsory parameter")
|
434
434
|
exit 1
|
435
435
|
end
|
436
|
-
unless
|
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] =
|
446
|
-
server_def[:connection_protocol] =
|
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] =
|
450
|
-
server_def[:connection_user] =
|
451
|
-
server_def[:connection_password] =
|
452
|
-
server_def[:ssh_identity_file] =
|
453
|
-
server_def[: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 =
|
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 =
|
459
|
-
port =
|
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 =
|
462
|
-
port =
|
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?(
|
468
|
-
server_def[: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
|
470
|
+
if config[:azure_domain_user]
|
471
471
|
# extract domain name since it should be part of username
|
472
|
-
case
|
472
|
+
case config[:azure_domain_user]
|
473
473
|
when /(\S+)\\(.+)/ # format - fully-qualified-DNS-domain\username
|
474
|
-
server_def[:azure_domain_name] = $1 if
|
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
|
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
|
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] =
|
486
|
+
server_def[:azure_domain_user] = config[:azure_domain_user]
|
487
487
|
end
|
488
488
|
end
|
489
|
-
server_def[:azure_domain_passwd] =
|
490
|
-
server_def[: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
|
503
|
-
config[:connection_user] =
|
502
|
+
unless config[:connection_user].nil?
|
503
|
+
config[:connection_user] = config[:connection_user]
|
504
504
|
end
|
505
505
|
|
506
|
-
unless
|
507
|
-
config[: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(
|
511
|
-
config[:azure_vm_name] =
|
512
|
-
config[: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
|
523
|
+
if config[:azure_vm_name].nil?
|
524
524
|
(prefix + SecureRandom.hex((MAX_VM_NAME_CHARACTERS - prefix.length) / 2))
|
525
525
|
else
|
526
|
-
|
526
|
+
config[:azure_vm_name]
|
527
527
|
end
|
528
528
|
end
|
529
529
|
end
|