knife-azure 2.0.13 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +7 -9
  7. data/lib/azure/resource_management/vnet_config.rb +2 -2
  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 +45 -45
  35. data/lib/chef/knife/azurerm_server_delete.rb +8 -8
  36. data/lib/chef/knife/azurerm_server_list.rb +3 -3
  37. data/lib/chef/knife/azurerm_server_show.rb +3 -3
  38. data/lib/chef/knife/bootstrap/bootstrapper.rb +29 -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 +7 -7
  42. data/lib/chef/knife/helpers/azure_base.rb +54 -65
  43. data/lib/chef/knife/helpers/azurerm_base.rb +46 -57
  44. data/lib/knife-azure/version.rb +2 -2
  45. metadata +13 -13
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
3
  #
4
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
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 versio that introduced deprecation of Windows Credentials
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
 
@@ -33,10 +33,10 @@ class Chef
33
33
  deps do
34
34
  require "readline"
35
35
  require "chef/json_compat"
36
- require_relative "../../azure/resource_management/ARM_interface"
36
+ require_relative "../../../azure/resource_management/ARM_interface"
37
37
  require "chef/mixin/shell_out"
38
- require "time"
39
- require "json"
38
+ require "time" unless defined?(Time)
39
+ require "json" unless defined?(JSON)
40
40
 
41
41
  if Chef::Platform.windows?
42
42
  require_relative "../../azure/resource_management/windows_credentials"
@@ -53,26 +53,18 @@ class Chef
53
53
 
54
54
  def service
55
55
  details = authentication_details
56
- details.update(azure_subscription_id: locate_config_value(: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(locate_config_value(:azure_publish_settings_file)) unless locate_config_value(:azure_publish_settings_file).nil?
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 locate_config_value(k).nil?
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,20 +86,19 @@ class Chef
94
86
 
95
87
  def authentication_details
96
88
  if is_azure_cred?
97
- return { azure_tenant_id: locate_config_value(:azure_tenant_id), azure_client_id: locate_config_value(:azure_client_id), azure_client_secret: locate_config_value(:azure_client_secret) }
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
101
93
  token_details = token_details_for_linux
102
94
  end
103
95
 
104
- token_details = check_token_validity(token_details)
105
- token_details
96
+ check_token_validity(token_details)
106
97
  end
107
98
 
108
99
  def get_azure_cli_version
109
100
  if @azure_version != ""
110
- get_version = shell_out!("azure -v || az -v | grep azure-cli", { returns: [0] }).stdout
101
+ get_version = shell_out!("azure -v || az -v | grep azure-cli", returns: [0]).stdout
111
102
  @azure_version = get_version.gsub(/[^0-9.]/, "")
112
103
  end
113
104
  @azure_prefix = @azure_version.to_i < 2 ? "azure" : "az"
@@ -130,19 +121,18 @@ class Chef
130
121
  home_dir = File.expand_path("~")
131
122
  file = File.read(home_dir + "/.azure/accessTokens.json")
132
123
  file = JSON.parse(file)
133
- token_details = { tokentype: file[-1]["tokenType"], user: file[-1]["userId"], token: file[-1]["accessToken"], clientid: file[-1]["_clientId"], expiry_time: file[-1]["expiresOn"], refreshtoken: file[-1]["refreshToken"] }
134
- token_details
124
+ { tokentype: file[-1]["tokenType"], user: file[-1]["userId"], token: file[-1]["accessToken"], clientid: file[-1]["_clientId"], expiry_time: file[-1]["expiresOn"], refreshtoken: file[-1]["refreshToken"] }
135
125
  end
136
126
 
137
127
  def is_token_valid?(token_details)
138
128
  time_difference = Time.parse(token_details[:expiry_time]) - Time.now.utc
139
129
  if time_difference <= 0
140
- return false
130
+ false
141
131
  elsif time_difference <= 600 # 600sec = 10min
142
132
  # This is required otherwise a long running command may fail inbetween if the token gets expired.
143
133
  raise "Token will expire within 10 minutes. Please run '#{@azure_prefix} login' command"
144
134
  else
145
- return true
135
+ true
146
136
  end
147
137
  end
148
138
 
@@ -175,18 +165,17 @@ class Chef
175
165
  raise login_message if result.stdout.nil? || result.stdout.empty?
176
166
  else
177
167
  home_dir = File.expand_path("~")
178
- puts "File.exist? = #{File.exist?("a")}"
179
- if !File.exist?(home_dir + "/.azure/accessTokens.json") || File.size?(home_dir + "/.azure/accessTokens.json") <= 2
168
+ if !File.exist?(home_dir + "/.azure/accessTokens.json") || ( File.size?(home_dir + "/.azure/accessTokens.json") <= 2 )
180
169
  raise login_message
181
170
  end
182
171
  end
183
172
  end
184
173
 
185
174
  def parse_publish_settings_file(filename)
186
- require "nokogiri"
187
- require "base64"
188
- require "openssl"
189
- require "uri"
175
+ require "nokogiri" unless defined?(Nokogiri)
176
+ require "base64" unless defined?(Base64)
177
+ require "openssl" unless defined?(OpenSSL)
178
+ require "uri" unless defined?(URI)
190
179
  begin
191
180
  doc = Nokogiri::XML(File.open(find_file(filename)))
192
181
  profile = doc.at_css("PublishProfile")
@@ -194,15 +183,15 @@ class Chef
194
183
  # check given PublishSettings XML file format.Currently PublishSettings file have two different XML format
195
184
  if profile.attribute("SchemaVersion").nil?
196
185
  management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value))
197
- Chef::Config[:knife][:azure_api_host_name] = URI(profile.attribute("Url").value).host
186
+ config[:azure_api_host_name] = URI(profile.attribute("Url").value).host
198
187
  elsif profile.attribute("SchemaVersion").value == "2.0"
199
188
  management_cert = OpenSSL::PKCS12.new(Base64.decode64(subscription.attribute("ManagementCertificate").value))
200
- Chef::Config[:knife][:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host
189
+ config[:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host
201
190
  else
202
191
  ui.error("Publish settings file Schema not supported - " + filename)
203
192
  end
204
- Chef::Config[:knife][:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem
205
- Chef::Config[:knife][:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value
193
+ config[:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem
194
+ config[:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value
206
195
  rescue => error
207
196
  puts "#{error.class} and #{error.message}"
208
197
  exit 1
@@ -228,7 +217,7 @@ class Chef
228
217
  def msg_server_summary(server)
229
218
  puts "\n\n"
230
219
  if server.provisioningstate == "Succeeded"
231
- Chef::Log.info("Server creation went successfull.")
220
+ Chef::Log.info("Server creation went successful.")
232
221
  puts "\nServer Details are:\n"
233
222
 
234
223
  msg_pair("Server ID", server.id)
@@ -249,7 +238,7 @@ class Chef
249
238
  puts "\n\n"
250
239
 
251
240
  if server.resources.provisioning_state == "Succeeded"
252
- Chef::Log.info("Server Extension creation went successfull.")
241
+ Chef::Log.info("Server Extension creation went successful.")
253
242
  puts "\nServer Extension Details are:\n"
254
243
 
255
244
  msg_pair("Server Extension ID", server.resources.id)
@@ -265,56 +254,56 @@ class Chef
265
254
  end
266
255
 
267
256
  def validate_params!
268
- if locate_config_value(:connection_user).nil?
257
+ if config[:connection_user].nil?
269
258
  raise ArgumentError, "Please provide --connection-user option for authentication."
270
259
  end
271
260
 
272
- unless locate_config_value(:connection_password).nil? ^ locate_config_value(:ssh_public_key).nil?
261
+ unless config[:connection_password].nil? ^ config[:ssh_public_key].nil?
273
262
  raise ArgumentError, "Please specify either --connection-password or --ssh-public-key option for authentication."
274
263
  end
275
264
 
276
- if locate_config_value(:azure_vnet_subnet_name) && !locate_config_value(:azure_vnet_name)
265
+ if config[:azure_vnet_subnet_name] && !config[:azure_vnet_name]
277
266
  raise ArgumentError, "When --azure-vnet-subnet-name is specified, the --azure-vnet-name must also be specified."
278
267
  end
279
268
 
280
- if locate_config_value(:azure_vnet_subnet_name) == "GatewaySubnet"
269
+ if config[:azure_vnet_subnet_name] == "GatewaySubnet"
281
270
  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
271
  end
283
272
 
284
- if locate_config_value(:node_ssl_verify_mode) && !%w{none peer}.include?(locate_config_value(:node_ssl_verify_mode))
285
- raise ArgumentError, "Invalid value '#{locate_config_value(:node_ssl_verify_mode)}' for --node-ssl-verify-mode. Use Valid values i.e 'none', 'peer'."
273
+ if config[:node_ssl_verify_mode] && !%w{none peer}.include?(config[:node_ssl_verify_mode])
274
+ raise ArgumentError, "Invalid value '#{config[:node_ssl_verify_mode]}' for --node-ssl-verify-mode. Use Valid values i.e 'none', 'peer'."
286
275
  end
287
276
 
288
277
  if !is_image_windows?
289
- if (locate_config_value(:azure_vm_name).match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,64})$/).nil?
290
- raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximun length cannot exceed 64 charachters."
278
+ if (config[:azure_vm_name].match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,64})$/).nil?
279
+ raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximum length cannot exceed 64 characters."
291
280
  end
292
- elsif (locate_config_value(:azure_vm_name).match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,15})$/).nil?
293
- raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximun length cannot exceed 15 charachters."
281
+ elsif (config[:azure_vm_name].match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,15})$/).nil?
282
+ raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximum length cannot exceed 15 characters."
294
283
  end
295
284
 
296
- if locate_config_value(:server_count).to_i > 5
285
+ if config[:server_count].to_i > 5
297
286
  raise ArgumentError, "Maximum allowed value of --server-count is 5."
298
287
  end
299
288
 
300
- if locate_config_value(:daemon)
289
+ if config[:daemon]
301
290
  unless is_image_windows?
302
291
  raise ArgumentError, "The daemon option is only support for Windows nodes."
303
292
  end
304
293
 
305
- unless %w{none service task}.include?(locate_config_value(:daemon))
294
+ unless %w{none service task}.include?(config[:daemon])
306
295
  raise ArgumentError, "Invalid value for --daemon option. Use valid daemon values i.e 'none', 'service' and 'task'."
307
296
  end
308
297
  end
309
298
 
310
- if locate_config_value(:azure_image_os_type)
311
- unless %w{ubuntu centos rhel debian windows}.include?(locate_config_value(:azure_image_os_type))
299
+ if config[:azure_image_os_type]
300
+ unless %w{ubuntu centos rhel debian windows}.include?(config[:azure_image_os_type])
312
301
  raise ArgumentError, "Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|rhel|debian|windows"
313
302
  end
314
303
  end
315
304
 
316
- config[:ohai_hints] = format_ohai_hints(locate_config_value(:ohai_hints))
317
- validate_ohai_hints unless locate_config_value(:ohai_hints).casecmp("default").zero?
305
+ config[:ohai_hints] = format_ohai_hints(config[:ohai_hints])
306
+ validate_ohai_hints unless config[:ohai_hints].casecmp("default").zero?
318
307
  end
319
308
 
320
309
  private
@@ -330,15 +319,15 @@ class Chef
330
319
  end
331
320
 
332
321
  def is_image_windows?
333
- locate_config_value(:azure_image_reference_offer) =~ /WindowsServer.*/
322
+ config[:azure_image_reference_offer] =~ /WindowsServer.*/
334
323
  end
335
324
 
336
325
  def is_azure_cred?
337
- locate_config_value(:azure_tenant_id) && locate_config_value(:azure_client_id) && locate_config_value(:azure_client_secret)
326
+ config[:azure_tenant_id] && config[:azure_client_id] && config[:azure_client_secret]
338
327
  end
339
328
 
340
329
  def azure_cred?
341
- locate_config_value(:azure_tenant_id).nil? || locate_config_value(:azure_client_id).nil? || locate_config_value(:azure_client_secret).nil?
330
+ config[:azure_tenant_id].nil? || config[:azure_client_id].nil? || config[:azure_client_secret].nil?
342
331
  end
343
332
 
344
333
  def is_old_xplat?
@@ -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");
@@ -17,7 +17,7 @@
17
17
 
18
18
  module Knife
19
19
  module Azure
20
- VERSION = "2.0.13".freeze
20
+ VERSION = "3.0.5".freeze
21
21
  MAJOR, MINOR, TINY = VERSION.split(".")
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-azure
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.13
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barry Davis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-02-12 00:00:00.000000000 Z
12
+ date: 2020-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '15.1'
20
+ version: 15.10.21
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '15.1'
27
+ version: 15.10.21
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: nokogiri
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -83,22 +83,22 @@ dependencies:
83
83
  name: azure_mgmt_storage
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '0.17'
89
86
  - - ">="
90
87
  - !ruby/object:Gem::Version
91
- version: 0.17.3
88
+ version: 0.20.0
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '0.20'
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - "~>"
97
- - !ruby/object:Gem::Version
98
- version: '0.17'
99
96
  - - ">="
100
97
  - !ruby/object:Gem::Version
101
- version: 0.17.3
98
+ version: 0.20.0
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.20'
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: azure_mgmt_network
104
104
  requirement: !ruby/object:Gem::Requirement
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - ">="
227
227
  - !ruby/object:Gem::Version
228
- version: '2.5'
228
+ version: '2.6'
229
229
  required_rubygems_version: !ruby/object:Gem::Requirement
230
230
  requirements:
231
231
  - - ">="