knife-azure 2.0.17 → 3.0.0
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 +1 -1
- data/lib/azure/resource_management/vnet_config.rb +1 -1
- data/lib/azure/resource_management/windows_credentials.rb +1 -1
- 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 +2 -2
- 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 +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 +70 -70
- 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 +43 -43
- data/lib/chef/knife/azurerm_server_delete.rb +6 -6
- data/lib/chef/knife/azurerm_server_list.rb +2 -2
- data/lib/chef/knife/azurerm_server_show.rb +2 -2
- 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 +8 -8
- data/lib/chef/knife/bootstrap_azurerm.rb +5 -5
- data/lib/chef/knife/helpers/azure_base.rb +46 -55
- data/lib/chef/knife/helpers/azurerm_base.rb +30 -39
- data/lib/knife-azure/version.rb +2 -2
- metadata +5 -5
@@ -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");
|
@@ -52,7 +52,7 @@ class Chef
|
|
52
52
|
def plugin_create_instance!
|
53
53
|
if @name_args.length == 1
|
54
54
|
service.add_extension(@name_args[0], set_ext_params)
|
55
|
-
if
|
55
|
+
if config[:extended_logs]
|
56
56
|
print "\n\nWaiting for the Chef Extension to become available/ready"
|
57
57
|
wait_until_extension_available(Time.now, 10)
|
58
58
|
print "\n\nWaiting for the first chef-client run"
|
@@ -89,20 +89,20 @@ class Chef
|
|
89
89
|
ui.info "Looking for the server #{@name_args[0]}..."
|
90
90
|
server = service.find_server(
|
91
91
|
name: @name_args[0],
|
92
|
-
azure_dns_name:
|
92
|
+
azure_dns_name: config[:azure_dns_name]
|
93
93
|
)
|
94
94
|
|
95
95
|
## if azure_dns_name value not passed by user then set it using the hostedservicename attribute from the retrieved server's object ##
|
96
|
-
config[:azure_dns_name] = server.hostedservicename if
|
96
|
+
config[:azure_dns_name] = server.hostedservicename if config[:azure_dns_name].nil? && (server.instance_of? Azure::Role)
|
97
97
|
unless server.instance_of? Azure::Role
|
98
98
|
if server.nil?
|
99
|
-
if !
|
100
|
-
raise "Hosted service #{
|
99
|
+
if !config[:azure_dns_name].nil?
|
100
|
+
raise "Hosted service #{config[:azure_dns_name]} does not exist."
|
101
101
|
else
|
102
102
|
raise "Server #{@name_args[0]} does not exist."
|
103
103
|
end
|
104
104
|
else
|
105
|
-
raise "Server #{@name_args[0]} does not exist under the hosted service #{
|
105
|
+
raise "Server #{@name_args[0]} does not exist under the hosted service #{config[:azure_dns_name]}."
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
@@ -122,7 +122,7 @@ class Chef
|
|
122
122
|
raise "OS type #{server.os_type} is not supported."
|
123
123
|
end
|
124
124
|
|
125
|
-
ext_params[:azure_dns_name] = server.hostedservicename ||
|
125
|
+
ext_params[:azure_dns_name] = server.hostedservicename || config[:azure_dns_name]
|
126
126
|
ext_params[:deploy_name] = server.deployname
|
127
127
|
ext_params[:role_xml] = server.role_xml
|
128
128
|
ext_params[:azure_vm_name] = @name_args[0]
|
@@ -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");
|
@@ -87,7 +87,7 @@ class Chef
|
|
87
87
|
#### run() execution ends ####
|
88
88
|
|
89
89
|
def set_ext_params
|
90
|
-
server = service.find_server(
|
90
|
+
server = service.find_server(config[:azure_resource_group_name], name_args[0])
|
91
91
|
|
92
92
|
if server
|
93
93
|
if service.extension_already_installed?(server)
|
@@ -107,16 +107,16 @@ class Chef
|
|
107
107
|
raise "OS type #{server.storage_profile.os_disk.os_type} is not supported."
|
108
108
|
end
|
109
109
|
|
110
|
-
ext_params[:azure_resource_group_name] =
|
110
|
+
ext_params[:azure_resource_group_name] = config[:azure_resource_group_name]
|
111
111
|
ext_params[:azure_vm_name] = @name_args[0]
|
112
|
-
ext_params[:azure_service_location] =
|
112
|
+
ext_params[:azure_service_location] = config[:azure_service_location]
|
113
113
|
ext_params[:chef_extension_publisher] = get_chef_extension_publisher
|
114
114
|
ext_params[:chef_extension_version] = get_chef_extension_version(ext_params[:chef_extension])
|
115
115
|
ext_params[:chef_extension_public_param] = get_chef_extension_public_params
|
116
116
|
ext_params[:chef_extension_private_param] = get_chef_extension_private_params
|
117
117
|
end
|
118
118
|
else
|
119
|
-
raise "The given server '#{@name_args[0]}' does not exist under resource group '#{
|
119
|
+
raise "The given server '#{@name_args[0]}' does not exist under resource group '#{config[:azure_resource_group_name]}'"
|
120
120
|
end
|
121
121
|
|
122
122
|
ext_params
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Author:: Barry Davis (barryd@jetstreamsoftware.com)
|
2
2
|
# Author:: Seth Chisamore (<schisamo@chef.io>)
|
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");
|
@@ -35,20 +35,17 @@ class Chef
|
|
35
35
|
option :azure_subscription_id,
|
36
36
|
short: "-S ID",
|
37
37
|
long: "--azure-subscription-id ID",
|
38
|
-
description: "Your Azure subscription ID"
|
39
|
-
proc: proc { |key| Chef::Config[:knife][:azure_subscription_id] = key }
|
38
|
+
description: "Your Azure subscription ID"
|
40
39
|
|
41
40
|
option :azure_mgmt_cert,
|
42
41
|
short: "-p FILENAME",
|
43
42
|
long: "--azure-mgmt-cert FILENAME",
|
44
|
-
description: "Your Azure PEM file name"
|
45
|
-
proc: proc { |key| Chef::Config[:knife][:azure_mgmt_cert] = key }
|
43
|
+
description: "Your Azure PEM file name"
|
46
44
|
|
47
45
|
option :azure_api_host_name,
|
48
46
|
short: "-H HOSTNAME",
|
49
47
|
long: "--azure-api-host-name HOSTNAME",
|
50
|
-
description: "Your Azure host name"
|
51
|
-
proc: proc { |key| Chef::Config[:knife][:azure_api_host_name] = key }
|
48
|
+
description: "Your Azure host name"
|
52
49
|
|
53
50
|
option :verify_ssl_cert,
|
54
51
|
long: "--verify-ssl-cert",
|
@@ -58,14 +55,13 @@ class Chef
|
|
58
55
|
|
59
56
|
option :azure_publish_settings_file,
|
60
57
|
long: "--azure-publish-settings-file FILENAME",
|
61
|
-
description: "Your Azure Publish Settings File"
|
62
|
-
proc: proc { |key| Chef::Config[:knife][:azure_publish_settings_file] = key }
|
58
|
+
description: "Your Azure Publish Settings File"
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
66
62
|
def is_image_windows?
|
67
63
|
images = service.list_images
|
68
|
-
target_image = images.select { |i| i.name ==
|
64
|
+
target_image = images.select { |i| i.name == config[:azure_source_image] }
|
69
65
|
if target_image[0].nil?
|
70
66
|
ui.error('Invalid image. Use the command "knife azure image list" to verify the image name')
|
71
67
|
exit 1
|
@@ -77,21 +73,16 @@ class Chef
|
|
77
73
|
def service
|
78
74
|
@service ||= begin
|
79
75
|
service = Azure::ServiceManagement::ASMInterface.new(
|
80
|
-
azure_subscription_id:
|
81
|
-
azure_mgmt_cert:
|
82
|
-
azure_api_host_name:
|
83
|
-
verify_ssl_cert:
|
76
|
+
azure_subscription_id: config[:azure_subscription_id],
|
77
|
+
azure_mgmt_cert: config[:azure_mgmt_cert],
|
78
|
+
azure_api_host_name: config[:azure_api_host_name],
|
79
|
+
verify_ssl_cert: config[:verify_ssl_cert]
|
84
80
|
)
|
85
81
|
end
|
86
82
|
@service.ui = ui
|
87
83
|
@service
|
88
84
|
end
|
89
85
|
|
90
|
-
def locate_config_value(key)
|
91
|
-
key = key.to_sym
|
92
|
-
config[key] || Chef::Config[:knife][key]
|
93
|
-
end
|
94
|
-
|
95
86
|
def msg_pair(label, value, color = :cyan)
|
96
87
|
if value && !value.to_s.empty?
|
97
88
|
puts "#{ui.color(label, color)}: #{value}"
|
@@ -103,16 +94,16 @@ class Chef
|
|
103
94
|
msg_pair("DNS Name", server.hostedservicename + ".cloudapp.net")
|
104
95
|
msg_pair("VM Name", server.name)
|
105
96
|
msg_pair("Size", server.size)
|
106
|
-
msg_pair("Azure Source Image",
|
107
|
-
msg_pair("Azure Service Location",
|
97
|
+
msg_pair("Azure Source Image", config[:azure_source_image])
|
98
|
+
msg_pair("Azure Service Location", config[:azure_service_location])
|
108
99
|
msg_pair("Public Ip Address", server.publicipaddress)
|
109
100
|
msg_pair("Private Ip Address", server.ipaddress)
|
110
101
|
msg_pair("SSH Port", server.sshport) unless server.sshport.nil?
|
111
102
|
msg_pair("WinRM Port", server.winrmport) unless server.winrmport.nil?
|
112
103
|
msg_pair("TCP Ports", server.tcpports) unless server.tcpports.nil? || server.tcpports.empty?
|
113
104
|
msg_pair("UDP Ports", server.udpports) unless server.udpports.nil? || server.udpports.empty?
|
114
|
-
msg_pair("Environment",
|
115
|
-
msg_pair("Runlist",
|
105
|
+
msg_pair("Environment", config[:environment] || "_default")
|
106
|
+
msg_pair("Runlist", config[:run_list]) unless config[:run_list].empty?
|
116
107
|
puts "\n"
|
117
108
|
end
|
118
109
|
|
@@ -121,61 +112,61 @@ class Chef
|
|
121
112
|
end
|
122
113
|
|
123
114
|
# validate command pre-requisites (cli options)
|
124
|
-
# (
|
115
|
+
# (config[:connection_password].length <= 6 && config[:connection_password].length >= 72)
|
125
116
|
def validate_params!
|
126
|
-
if
|
117
|
+
if config[:connection_password] && !config[:connection_password].length.between?(6, 72)
|
127
118
|
ui.error("The supplied connection password must be 6-72 characters long and meet password complexity requirements")
|
128
119
|
exit 1
|
129
120
|
end
|
130
121
|
|
131
|
-
if
|
122
|
+
if config[:azure_connect_to_existing_dns] && config[:azure_vm_name].nil?
|
132
123
|
ui.error("Specify the VM name using --azure-vm-name option, since you are connecting to existing dns")
|
133
124
|
exit 1
|
134
125
|
end
|
135
126
|
|
136
|
-
unless !!
|
127
|
+
unless !!config[:azure_service_location] ^ !!config[:azure_affinity_group]
|
137
128
|
ui.error("Specify either --azure-service-location or --azure-affinity-group")
|
138
129
|
exit 1
|
139
130
|
end
|
140
131
|
|
141
|
-
unless service.valid_image?(
|
142
|
-
ui.error("Image '#{
|
132
|
+
unless service.valid_image?(config[:azure_source_image])
|
133
|
+
ui.error("Image '#{config[:azure_source_image]}' is invalid")
|
143
134
|
exit 1
|
144
135
|
end
|
145
136
|
|
146
137
|
# Validate join domain requirements.
|
147
|
-
if
|
148
|
-
if
|
138
|
+
if config[:azure_domain_name] || config[:azure_domain_user]
|
139
|
+
if config[:azure_domain_user].nil? || config[:azure_domain_passwd].nil?
|
149
140
|
ui.error("Must specify both --azure-domain-user and --azure-domain-passwd.")
|
150
141
|
exit 1
|
151
142
|
end
|
152
143
|
end
|
153
144
|
|
154
|
-
if
|
145
|
+
if config[:winrm_ssl] && config[:thumbprint].nil? && config[:winrm_no_verify_cert].nil?
|
155
146
|
ui.error("The SSL transport was specified without the --thumbprint option. Specify a thumbprint, or alternatively set the --winrm-no-verify-cert option to skip verification.")
|
156
147
|
exit 1
|
157
148
|
end
|
158
149
|
|
159
|
-
if
|
150
|
+
if config[:extended_logs] && config[:connection_protocol] != "cloud-api"
|
160
151
|
ui.error("--extended-logs option only works with --bootstrap-protocol cloud-api")
|
161
152
|
exit 1
|
162
153
|
end
|
163
154
|
|
164
|
-
if
|
155
|
+
if config[:connection_protocol] == "cloud-api" && config[:azure_vm_name].nil? && config[:azure_dns_name].nil?
|
165
156
|
ui.error("Specifying the DNS name using --azure-dns-name or VM name using --azure-vm-name option is required with --bootstrap-protocol cloud-api")
|
166
157
|
exit 1
|
167
158
|
end
|
168
159
|
|
169
|
-
if
|
160
|
+
if config[:daemon]
|
170
161
|
unless is_image_windows?
|
171
162
|
raise ArgumentError, "The daemon option is only supported for Windows nodes."
|
172
163
|
end
|
173
164
|
|
174
|
-
unless
|
165
|
+
unless config[:connection_protocol] == "cloud-api"
|
175
166
|
raise ArgumentError, "The --daemon option requires the use of --bootstrap-protocol cloud-api"
|
176
167
|
end
|
177
168
|
|
178
|
-
unless %w{none service task}.include?(
|
169
|
+
unless %w{none service task}.include?(config[:daemon].downcase)
|
179
170
|
raise ArgumentError, "Invalid value for --daemon option. Valid values are 'none', 'service' and 'task'."
|
180
171
|
end
|
181
172
|
end
|
@@ -185,7 +176,7 @@ class Chef
|
|
185
176
|
def validate!(keys)
|
186
177
|
errors = []
|
187
178
|
keys.each do |k|
|
188
|
-
if
|
179
|
+
if config[k].nil?
|
189
180
|
errors << "You did not provide a valid '#{pretty_key(k)}' value. Please set knife[:#{k}] in your knife.rb or pass as an option."
|
190
181
|
end
|
191
182
|
end
|
@@ -197,13 +188,13 @@ class Chef
|
|
197
188
|
mandatory_keys = %i{azure_subscription_id azure_mgmt_cert azure_api_host_name}
|
198
189
|
keys.concat(mandatory_keys)
|
199
190
|
|
200
|
-
unless
|
201
|
-
config[:azure_mgmt_cert] = File.read find_file(
|
191
|
+
unless config[:azure_mgmt_cert].nil?
|
192
|
+
config[:azure_mgmt_cert] = File.read find_file(config[:azure_mgmt_cert])
|
202
193
|
end
|
203
194
|
|
204
|
-
if !
|
205
|
-
parse_publish_settings_file(
|
206
|
-
elsif
|
195
|
+
if !config[:azure_publish_settings_file].nil?
|
196
|
+
parse_publish_settings_file(config[:azure_publish_settings_file])
|
197
|
+
elsif config[:azure_subscription_id].nil? && config[:azure_mgmt_cert].nil? && config[:azure_api_host_name].nil?
|
207
198
|
azureprofile_file = get_azure_profile_file_path
|
208
199
|
if File.exist?(File.expand_path(azureprofile_file))
|
209
200
|
errors = parse_azure_profile(azureprofile_file, errors)
|
@@ -224,15 +215,15 @@ class Chef
|
|
224
215
|
# check given PublishSettings XML file format.Currently PublishSettings file have two different XML format
|
225
216
|
if profile.attribute("SchemaVersion").nil?
|
226
217
|
management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value))
|
227
|
-
|
218
|
+
config[:azure_api_host_name] = URI(profile.attribute("Url").value).host
|
228
219
|
elsif profile.attribute("SchemaVersion").value == "2.0"
|
229
220
|
management_cert = OpenSSL::PKCS12.new(Base64.decode64(subscription.attribute("ManagementCertificate").value))
|
230
|
-
|
221
|
+
config[:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host
|
231
222
|
else
|
232
223
|
ui.error("Publish settings file Schema not supported - " + filename)
|
233
224
|
end
|
234
|
-
|
235
|
-
|
225
|
+
config[:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem
|
226
|
+
config[:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value
|
236
227
|
rescue
|
237
228
|
ui.error("Incorrect publish settings file - " + filename)
|
238
229
|
exit 1
|
@@ -252,11 +243,11 @@ class Chef
|
|
252
243
|
default_subscription = get_default_subscription(azure_profile)
|
253
244
|
if default_subscription.key?("id") && default_subscription.key?("managementCertificate") && default_subscription.key?("managementEndpointUrl")
|
254
245
|
|
255
|
-
|
246
|
+
config[:azure_subscription_id] = default_subscription["id"]
|
256
247
|
mgmt_key = OpenSSL::PKey::RSA.new(default_subscription["managementCertificate"]["key"]).to_pem
|
257
248
|
mgmt_cert = OpenSSL::X509::Certificate.new(default_subscription["managementCertificate"]["cert"]).to_pem
|
258
|
-
|
259
|
-
|
249
|
+
config[:azure_mgmt_cert] = mgmt_key + mgmt_cert
|
250
|
+
config[:azure_api_host_name] = URI(default_subscription["managementEndpointUrl"]).host
|
260
251
|
else
|
261
252
|
errors << "Check if values set for 'id', 'managementCertificate', 'managementEndpointUrl' in -> #{filename} for 'defaultSubscription'. \n OR "
|
262
253
|
end
|
@@ -300,8 +291,8 @@ class Chef
|
|
300
291
|
end
|
301
292
|
|
302
293
|
def fetch_deployment
|
303
|
-
deployment_name = service.deployment_name(
|
304
|
-
deployment = service.deployment("hostedservices/#{
|
294
|
+
deployment_name = service.deployment_name(config[:azure_dns_name])
|
295
|
+
deployment = service.deployment("hostedservices/#{config[:azure_dns_name]}/deployments/#{deployment_name}")
|
305
296
|
|
306
297
|
deployment
|
307
298
|
end
|
@@ -312,7 +303,7 @@ class Chef
|
|
312
303
|
if deployment.at_css("Deployment Name") != nil
|
313
304
|
role_list_xml = deployment.css("RoleInstanceList RoleInstance")
|
314
305
|
role_list_xml.each do |role|
|
315
|
-
if role.at_css("RoleName").text == (
|
306
|
+
if role.at_css("RoleName").text == (config[:azure_vm_name] || @name_args[0])
|
316
307
|
return role
|
317
308
|
end
|
318
309
|
end
|
@@ -391,11 +382,11 @@ class Chef
|
|
391
382
|
end
|
392
383
|
else
|
393
384
|
## Chef Extension could not be found ##
|
394
|
-
ui.error("Unable to find Chef extension under role #{
|
385
|
+
ui.error("Unable to find Chef extension under role #{config[:azure_vm_name] || @name_args[0]}.")
|
395
386
|
end
|
396
387
|
else
|
397
388
|
## server could not be found ##
|
398
|
-
ui.error("chef-client run logs could not be fetched since role #{
|
389
|
+
ui.error("chef-client run logs could not be fetched since role #{config[:azure_vm_name] || @name_args[0]} could not be found.")
|
399
390
|
end
|
400
391
|
end
|
401
392
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
|
3
3
|
#
|
4
|
-
# Copyright:: Copyright
|
4
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
5
5
|
# License:: Apache License, Version 2.0
|
6
6
|
#
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -24,7 +24,7 @@ class Chef
|
|
24
24
|
module AzurermBase
|
25
25
|
include Chef::Mixin::ShellOut
|
26
26
|
|
27
|
-
## azure-xplat-cli
|
27
|
+
## azure-xplat-cli version that introduced deprecation of Windows Credentials
|
28
28
|
## Manager (WCM) usage for authentication credentials storage purpose ##
|
29
29
|
XPLAT_VERSION_WITH_WCM_DEPRECATED ||= "0.10.5".freeze
|
30
30
|
|
@@ -53,26 +53,18 @@ class Chef
|
|
53
53
|
|
54
54
|
def service
|
55
55
|
details = authentication_details
|
56
|
-
details.update(azure_subscription_id:
|
56
|
+
details.update(azure_subscription_id: config[:azure_subscription_id])
|
57
57
|
@service ||= begin
|
58
|
+
require_relative "../../../azure/resource_management/ARM_interface"
|
58
59
|
service = Azure::ResourceManagement::ARMInterface.new(details)
|
59
60
|
end
|
60
61
|
@service.ui = ui
|
61
62
|
@service
|
62
63
|
end
|
63
64
|
|
64
|
-
def locate_config_value(key)
|
65
|
-
key = key.to_sym
|
66
|
-
if defined?(config_value) # Inherited by bootstrap
|
67
|
-
config_value(key) || default_config[key]
|
68
|
-
else
|
69
|
-
config[key] || Chef::Config[:knife][key] || default_config[key]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
65
|
# validates ARM mandatory keys
|
74
66
|
def validate_arm_keys!(*keys)
|
75
|
-
parse_publish_settings_file(
|
67
|
+
parse_publish_settings_file(config[:azure_publish_settings_file]) unless config[:azure_publish_settings_file].nil?
|
76
68
|
keys.push(:azure_subscription_id)
|
77
69
|
|
78
70
|
if azure_cred?
|
@@ -83,7 +75,7 @@ class Chef
|
|
83
75
|
|
84
76
|
errors = []
|
85
77
|
keys.each do |k|
|
86
|
-
if
|
78
|
+
if config[k].nil?
|
87
79
|
errors << "You did not provide a valid '#{pretty_key(k)}' value. Please set knife[:#{k}] in your knife.rb."
|
88
80
|
end
|
89
81
|
end
|
@@ -94,7 +86,7 @@ class Chef
|
|
94
86
|
|
95
87
|
def authentication_details
|
96
88
|
if is_azure_cred?
|
97
|
-
return { azure_tenant_id:
|
89
|
+
return { azure_tenant_id: config[:azure_tenant_id], azure_client_id: config[:azure_client_id], azure_client_secret: config[:azure_client_secret] }
|
98
90
|
elsif Chef::Platform.windows?
|
99
91
|
token_details = token_details_for_windows
|
100
92
|
else
|
@@ -175,8 +167,7 @@ class Chef
|
|
175
167
|
raise login_message if result.stdout.nil? || result.stdout.empty?
|
176
168
|
else
|
177
169
|
home_dir = File.expand_path("~")
|
178
|
-
|
179
|
-
if !File.exist?(home_dir + "/.azure/accessTokens.json") || File.size?(home_dir + "/.azure/accessTokens.json") <= 2
|
170
|
+
if !File.exist?(home_dir + "/.azure/accessTokens.json") || ( File.size?(home_dir + "/.azure/accessTokens.json") <= 2 )
|
180
171
|
raise login_message
|
181
172
|
end
|
182
173
|
end
|
@@ -194,15 +185,15 @@ class Chef
|
|
194
185
|
# check given PublishSettings XML file format.Currently PublishSettings file have two different XML format
|
195
186
|
if profile.attribute("SchemaVersion").nil?
|
196
187
|
management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value))
|
197
|
-
|
188
|
+
config[:azure_api_host_name] = URI(profile.attribute("Url").value).host
|
198
189
|
elsif profile.attribute("SchemaVersion").value == "2.0"
|
199
190
|
management_cert = OpenSSL::PKCS12.new(Base64.decode64(subscription.attribute("ManagementCertificate").value))
|
200
|
-
|
191
|
+
config[:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host
|
201
192
|
else
|
202
193
|
ui.error("Publish settings file Schema not supported - " + filename)
|
203
194
|
end
|
204
|
-
|
205
|
-
|
195
|
+
config[:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem
|
196
|
+
config[:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value
|
206
197
|
rescue => error
|
207
198
|
puts "#{error.class} and #{error.message}"
|
208
199
|
exit 1
|
@@ -265,56 +256,56 @@ class Chef
|
|
265
256
|
end
|
266
257
|
|
267
258
|
def validate_params!
|
268
|
-
if
|
259
|
+
if config[:connection_user].nil?
|
269
260
|
raise ArgumentError, "Please provide --connection-user option for authentication."
|
270
261
|
end
|
271
262
|
|
272
|
-
unless
|
263
|
+
unless config[:connection_password].nil? ^ config[:ssh_public_key].nil?
|
273
264
|
raise ArgumentError, "Please specify either --connection-password or --ssh-public-key option for authentication."
|
274
265
|
end
|
275
266
|
|
276
|
-
if
|
267
|
+
if config[:azure_vnet_subnet_name] && !config[:azure_vnet_name]
|
277
268
|
raise ArgumentError, "When --azure-vnet-subnet-name is specified, the --azure-vnet-name must also be specified."
|
278
269
|
end
|
279
270
|
|
280
|
-
if
|
271
|
+
if config[:azure_vnet_subnet_name] == "GatewaySubnet"
|
281
272
|
raise ArgumentError, "GatewaySubnet cannot be used as the name for --azure-vnet-subnet-name option. GatewaySubnet can only be used for virtual network gateways."
|
282
273
|
end
|
283
274
|
|
284
|
-
if
|
285
|
-
raise ArgumentError, "Invalid value '#{
|
275
|
+
if config[:node_ssl_verify_mode] && !%w{none peer}.include?(config[:node_ssl_verify_mode])
|
276
|
+
raise ArgumentError, "Invalid value '#{config[:node_ssl_verify_mode]}' for --node-ssl-verify-mode. Use Valid values i.e 'none', 'peer'."
|
286
277
|
end
|
287
278
|
|
288
279
|
if !is_image_windows?
|
289
|
-
if (
|
280
|
+
if (config[:azure_vm_name].match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,64})$/).nil?
|
290
281
|
raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximun length cannot exceed 64 charachters."
|
291
282
|
end
|
292
|
-
elsif (
|
283
|
+
elsif (config[:azure_vm_name].match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,15})$/).nil?
|
293
284
|
raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximun length cannot exceed 15 charachters."
|
294
285
|
end
|
295
286
|
|
296
|
-
if
|
287
|
+
if config[:server_count].to_i > 5
|
297
288
|
raise ArgumentError, "Maximum allowed value of --server-count is 5."
|
298
289
|
end
|
299
290
|
|
300
|
-
if
|
291
|
+
if config[:daemon]
|
301
292
|
unless is_image_windows?
|
302
293
|
raise ArgumentError, "The daemon option is only support for Windows nodes."
|
303
294
|
end
|
304
295
|
|
305
|
-
unless %w{none service task}.include?(
|
296
|
+
unless %w{none service task}.include?(config[:daemon])
|
306
297
|
raise ArgumentError, "Invalid value for --daemon option. Use valid daemon values i.e 'none', 'service' and 'task'."
|
307
298
|
end
|
308
299
|
end
|
309
300
|
|
310
|
-
if
|
311
|
-
unless %w{ubuntu centos rhel debian windows}.include?(
|
301
|
+
if config[:azure_image_os_type]
|
302
|
+
unless %w{ubuntu centos rhel debian windows}.include?(config[:azure_image_os_type])
|
312
303
|
raise ArgumentError, "Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|rhel|debian|windows"
|
313
304
|
end
|
314
305
|
end
|
315
306
|
|
316
|
-
config[:ohai_hints] = format_ohai_hints(
|
317
|
-
validate_ohai_hints unless
|
307
|
+
config[:ohai_hints] = format_ohai_hints(config[:ohai_hints])
|
308
|
+
validate_ohai_hints unless config[:ohai_hints].casecmp("default").zero?
|
318
309
|
end
|
319
310
|
|
320
311
|
private
|
@@ -330,15 +321,15 @@ class Chef
|
|
330
321
|
end
|
331
322
|
|
332
323
|
def is_image_windows?
|
333
|
-
|
324
|
+
config[:azure_image_reference_offer] =~ /WindowsServer.*/
|
334
325
|
end
|
335
326
|
|
336
327
|
def is_azure_cred?
|
337
|
-
|
328
|
+
config[:azure_tenant_id] && config[:azure_client_id] && config[:azure_client_secret]
|
338
329
|
end
|
339
330
|
|
340
331
|
def azure_cred?
|
341
|
-
|
332
|
+
config[:azure_tenant_id].nil? || config[:azure_client_id].nil? || config[:azure_client_secret].nil?
|
342
333
|
end
|
343
334
|
|
344
335
|
def is_old_xplat?
|