knife-azure 2.0.11 → 3.0.4
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 +12 -14
- data/lib/azure/resource_management/vnet_config.rb +2 -2
- data/lib/azure/resource_management/windows_credentials.rb +5 -6
- 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 +1 -1
- data/lib/azure/service_management/role.rb +1 -1
- 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 +5 -5
- data/lib/chef/knife/azure_ag_list.rb +2 -2
- data/lib/chef/knife/azure_image_list.rb +4 -4
- data/lib/chef/knife/azure_internal-lb_create.rb +6 -6
- data/lib/chef/knife/azure_internal-lb_list.rb +2 -2
- data/lib/chef/knife/azure_server_create.rb +71 -71
- data/lib/chef/knife/azure_server_delete.rb +8 -8
- data/lib/chef/knife/azure_server_list.rb +2 -2
- data/lib/chef/knife/azure_server_show.rb +2 -2
- data/lib/chef/knife/azure_vnet_create.rb +6 -6
- data/lib/chef/knife/azure_vnet_list.rb +2 -2
- data/lib/chef/knife/azurerm_server_create.rb +45 -45
- data/lib/chef/knife/azurerm_server_delete.rb +9 -9
- data/lib/chef/knife/azurerm_server_list.rb +4 -4
- data/lib/chef/knife/azurerm_server_show.rb +4 -4
- 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 +16 -16
- data/lib/chef/knife/bootstrap_azurerm.rb +7 -7
- data/lib/chef/knife/{azure_base.rb → helpers/azure_base.rb} +48 -59
- data/lib/chef/knife/{azurerm_base.rb → helpers/azurerm_base.rb} +40 -51
- data/lib/knife-azure/version.rb +2 -2
- metadata +15 -29
@@ -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");
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require_relative "azure_base"
|
21
|
+
require_relative "helpers/azure_base"
|
22
22
|
require "chef/knife/bootstrap"
|
23
23
|
require "chef/knife/bootstrap/client_builder"
|
24
24
|
require_relative "bootstrap/common_bootstrap_options"
|
@@ -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
|
@@ -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");
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require_relative "azure_base"
|
21
|
+
require_relative "helpers/azure_base"
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
class Knife
|
@@ -94,7 +94,7 @@ class Chef
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def validate_disk_and_storage
|
97
|
-
if
|
97
|
+
if config[:preserve_azure_os_disk] && config[:delete_azure_storage_account]
|
98
98
|
ui.warn("Cannot delete storage account while keeping OS Disk. Please set any one option.")
|
99
99
|
exit
|
100
100
|
else
|
@@ -107,11 +107,11 @@ class Chef
|
|
107
107
|
validate_disk_and_storage
|
108
108
|
@name_args.each do |name|
|
109
109
|
begin
|
110
|
-
service.delete_server( { name: name, preserve_azure_os_disk:
|
111
|
-
preserve_azure_vhd:
|
112
|
-
preserve_azure_dns_name:
|
113
|
-
delete_azure_storage_account:
|
114
|
-
wait:
|
110
|
+
service.delete_server( { name: name, preserve_azure_os_disk: config[:preserve_azure_os_disk],
|
111
|
+
preserve_azure_vhd: config[:preserve_azure_vhd],
|
112
|
+
preserve_azure_dns_name: config[:preserve_azure_dns_name],
|
113
|
+
delete_azure_storage_account: config[:delete_azure_storage_account],
|
114
|
+
wait: config[:wait] } )
|
115
115
|
|
116
116
|
if config[:purge]
|
117
117
|
node_to_delete = config[:chef_node_name] || name
|
@@ -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");
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require_relative "azure_base"
|
21
|
+
require_relative "helpers/azure_base"
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
class Knife
|
@@ -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");
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# limitations under the License.
|
19
19
|
#
|
20
20
|
|
21
|
-
require_relative "azure_base"
|
21
|
+
require_relative "helpers/azure_base"
|
22
22
|
|
23
23
|
class Chef
|
24
24
|
class Knife
|
@@ -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");
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require_relative "azure_base"
|
19
|
+
require_relative "helpers/azure_base"
|
20
20
|
|
21
21
|
class Chef
|
22
22
|
class Knife
|
@@ -50,10 +50,10 @@ class Chef
|
|
50
50
|
validate_asm_keys!(:azure_network_name, :azure_affinity_group, :azure_address_space)
|
51
51
|
|
52
52
|
params = {
|
53
|
-
azure_vnet_name:
|
54
|
-
azure_ag_name:
|
55
|
-
azure_address_space:
|
56
|
-
azure_subnet_name:
|
53
|
+
azure_vnet_name: config[:azure_network_name],
|
54
|
+
azure_ag_name: config[:azure_affinity_group],
|
55
|
+
azure_address_space: config[:azure_address_space],
|
56
|
+
azure_subnet_name: config[:azure_subnet_name] || "Subnet-#{Random.rand(10)}",
|
57
57
|
}
|
58
58
|
|
59
59
|
rsp = service.create_vnet(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");
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require_relative "azure_base"
|
19
|
+
require_relative "helpers/azure_base"
|
20
20
|
|
21
21
|
class Chef
|
22
22
|
class Knife
|
@@ -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");
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require_relative "azurerm_base"
|
19
|
+
require_relative "helpers/azurerm_base"
|
20
20
|
require "chef/knife/bootstrap"
|
21
21
|
require "chef/knife/bootstrap/client_builder"
|
22
22
|
require_relative "bootstrap/common_bootstrap_options"
|
@@ -32,7 +32,7 @@ class Chef
|
|
32
32
|
|
33
33
|
deps do
|
34
34
|
require "securerandom"
|
35
|
-
include Knife::AzurermBase
|
35
|
+
include Knife::AzurermBase
|
36
36
|
end
|
37
37
|
|
38
38
|
banner "knife azurerm server create (options)"
|
@@ -156,55 +156,55 @@ class Chef
|
|
156
156
|
|
157
157
|
def create_server_def
|
158
158
|
server_def = {
|
159
|
-
azure_resource_group_name:
|
160
|
-
azure_storage_account:
|
161
|
-
azure_storage_account_type:
|
162
|
-
azure_vm_name:
|
163
|
-
azure_service_location:
|
164
|
-
azure_os_disk_name:
|
165
|
-
azure_os_disk_caching:
|
166
|
-
azure_os_disk_create_option:
|
167
|
-
azure_vm_size:
|
168
|
-
azure_image_reference_publisher:
|
169
|
-
azure_image_reference_offer:
|
170
|
-
azure_image_reference_sku:
|
171
|
-
azure_image_reference_version:
|
172
|
-
azure_availability_set:
|
173
|
-
azure_vnet_name:
|
174
|
-
azure_vnet_subnet_name:
|
175
|
-
ssl_cert_fingerprint:
|
176
|
-
cert_path:
|
177
|
-
cert_password:
|
178
|
-
vnet_subnet_address_prefix:
|
179
|
-
server_count:
|
159
|
+
azure_resource_group_name: config[:azure_resource_group_name],
|
160
|
+
azure_storage_account: config[:azure_storage_account],
|
161
|
+
azure_storage_account_type: config[:azure_storage_account_type],
|
162
|
+
azure_vm_name: config[:azure_vm_name],
|
163
|
+
azure_service_location: config[:azure_service_location],
|
164
|
+
azure_os_disk_name: config[:azure_os_disk_name],
|
165
|
+
azure_os_disk_caching: config[:azure_os_disk_caching],
|
166
|
+
azure_os_disk_create_option: config[:azure_os_disk_create_option],
|
167
|
+
azure_vm_size: config[:azure_vm_size],
|
168
|
+
azure_image_reference_publisher: config[:azure_image_reference_publisher],
|
169
|
+
azure_image_reference_offer: config[:azure_image_reference_offer],
|
170
|
+
azure_image_reference_sku: config[:azure_image_reference_sku],
|
171
|
+
azure_image_reference_version: config[:azure_image_reference_version],
|
172
|
+
azure_availability_set: config[:azure_availability_set],
|
173
|
+
azure_vnet_name: config[:azure_vnet_name],
|
174
|
+
azure_vnet_subnet_name: config[:azure_vnet_subnet_name],
|
175
|
+
ssl_cert_fingerprint: config[:thumbprint],
|
176
|
+
cert_path: config[:cert_path],
|
177
|
+
cert_password: config[:cert_passphrase],
|
178
|
+
vnet_subnet_address_prefix: config[:vnet_subnet_address_prefix],
|
179
|
+
server_count: config[:server_count],
|
180
180
|
}
|
181
181
|
|
182
|
-
server_def[:tcp_endpoints] =
|
182
|
+
server_def[:tcp_endpoints] = config[:tcp_endpoints] if config[:tcp_endpoints]
|
183
183
|
|
184
184
|
# We assign azure_vm_name to chef_node_name If node name is nill because storage account name is combination of hash value and node name.
|
185
|
-
config[:chef_node_name] ||=
|
185
|
+
config[:chef_node_name] ||= config[:azure_vm_name]
|
186
186
|
|
187
|
-
server_def[:azure_storage_account] =
|
187
|
+
server_def[:azure_storage_account] = config[:azure_vm_name] if server_def[:azure_storage_account].nil?
|
188
188
|
server_def[:azure_storage_account] = server_def[:azure_storage_account].gsub(/[!@#$%^&*()_-]/, "")
|
189
189
|
|
190
|
-
server_def[:azure_os_disk_name] =
|
190
|
+
server_def[:azure_os_disk_name] = config[:azure_vm_name] if server_def[:azure_os_disk_name].nil?
|
191
191
|
server_def[:azure_os_disk_name] = server_def[:azure_os_disk_name].gsub(/[!@#$%^&*()_-]/, "")
|
192
192
|
|
193
|
-
server_def[:azure_vnet_name] =
|
194
|
-
server_def[:azure_vnet_subnet_name] =
|
193
|
+
server_def[:azure_vnet_name] = config[:azure_vm_name] if server_def[:azure_vnet_name].nil?
|
194
|
+
server_def[:azure_vnet_subnet_name] = config[:azure_vm_name] if config[:azure_vnet_subnet_name].nil?
|
195
195
|
|
196
196
|
server_def[:chef_extension] = get_chef_extension_name
|
197
197
|
server_def[:chef_extension_publisher] = get_chef_extension_publisher
|
198
|
-
server_def[:chef_extension_version] =
|
198
|
+
server_def[:chef_extension_version] = config[:azure_chef_extension_version]
|
199
199
|
server_def[:chef_extension_public_param] = get_chef_extension_public_params
|
200
200
|
server_def[:chef_extension_private_param] = get_chef_extension_private_params
|
201
201
|
server_def[:auto_upgrade_minor_version] = false
|
202
|
-
server_def[:connection_user] =
|
203
|
-
server_def[:disablePasswordAuthentication] = if
|
204
|
-
server_def[:ssh_public_key] = File.read(
|
202
|
+
server_def[:connection_user] = config[:connection_user]
|
203
|
+
server_def[:disablePasswordAuthentication] = if config[:ssh_public_key]
|
204
|
+
server_def[:ssh_public_key] = File.read(config[:ssh_public_key])
|
205
205
|
"true"
|
206
206
|
else
|
207
|
-
server_def[:connection_password] =
|
207
|
+
server_def[:connection_password] = config[:connection_password]
|
208
208
|
"false"
|
209
209
|
end
|
210
210
|
|
@@ -229,7 +229,7 @@ class Chef
|
|
229
229
|
end
|
230
230
|
|
231
231
|
def validate_ohai_hints
|
232
|
-
hint_values =
|
232
|
+
hint_values = config[:ohai_hints].split(",")
|
233
233
|
hint_values.each do |hint|
|
234
234
|
unless is_supported_ohai_hint?(hint)
|
235
235
|
raise ArgumentError, "Ohai Hint name #{hint} passed is not supported. Please run the command help to see the list of supported values."
|
@@ -245,22 +245,22 @@ class Chef
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def set_configs
|
248
|
-
unless
|
249
|
-
config[:connection_user] =
|
248
|
+
unless config[:connection_user].nil?
|
249
|
+
config[:connection_user] = config[:connection_user]
|
250
250
|
end
|
251
251
|
|
252
|
-
unless
|
253
|
-
config[:connection_password] =
|
252
|
+
unless config[:connection_password].nil?
|
253
|
+
config[:connection_password] = config[:connection_password]
|
254
254
|
end
|
255
255
|
end
|
256
256
|
|
257
257
|
def set_default_image_reference!
|
258
258
|
begin
|
259
|
-
if
|
259
|
+
if config[:azure_image_os_type]
|
260
260
|
validate_publisher_and_offer
|
261
261
|
## if azure_image_os_type is given (with or without azure-image-reference-sku) and other image reference parameters are not given,
|
262
262
|
# set default image reference parameters
|
263
|
-
case
|
263
|
+
case config[:azure_image_os_type]
|
264
264
|
when "ubuntu"
|
265
265
|
set_os_image("Canonical", "UbuntuServer", "14.04.2-LTS")
|
266
266
|
when "centos"
|
@@ -292,15 +292,15 @@ class Chef
|
|
292
292
|
def set_os_image(publisher, img_offer, default_os_version)
|
293
293
|
config[:azure_image_reference_publisher] = publisher
|
294
294
|
config[:azure_image_reference_offer] = img_offer
|
295
|
-
config[:azure_image_reference_sku] =
|
295
|
+
config[:azure_image_reference_sku] = config[:azure_image_reference_sku] ? config[:azure_image_reference_sku] : default_os_version
|
296
296
|
end
|
297
297
|
|
298
298
|
def is_image_os_type?
|
299
|
-
|
299
|
+
config[:azure_image_reference_publisher] && config[:azure_image_reference_offer] && config[:azure_image_reference_sku] && config[:azure_image_reference_version]
|
300
300
|
end
|
301
301
|
|
302
302
|
def validate_publisher_and_offer
|
303
|
-
if
|
303
|
+
if config[:azure_image_reference_publisher] || config[:azure_image_reference_offer]
|
304
304
|
# if azure_image_os_type is given and any of the other image reference parameters like publisher or offer are also given,
|
305
305
|
# raise error
|
306
306
|
raise ArgumentError, 'Please specify either --azure-image-os-type OR --azure-image-os-type with --azure-image-reference-sku or 4 image reference parameters i.e.
|