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.
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,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -46,8 +46,7 @@ class Chef
46
46
  short: "-m LOCATION",
47
47
  long: "--azure-service-location LOCATION",
48
48
  description: "Required if not using an Affinity Group. Specifies the geographic location - the name of the data center location that is valid for your subscription.
49
- Eg: West US, East US, East Asia, Southeast Asia, North Europe, West Europe",
50
- proc: Proc.new { |lo| Chef::Config[:knife][:azure_service_location] = lo }
49
+ Eg: West US, East US, East Asia, Southeast Asia, North Europe, West Europe"
51
50
 
52
51
  option :azure_storage_account,
53
52
  short: "-a NAME",
@@ -69,8 +68,7 @@ class Chef
69
68
  long: "--azure-vm-size SIZE",
70
69
  description: "Optional. Size of virtual machine. Default is Standard_A1_v2.
71
70
  Eg: Standard_A1_v2, Standard_F2, Standard_G1 etc.",
72
- default: "Standard_A1_v2",
73
- proc: Proc.new { |si| Chef::Config[:knife][:azure_vm_size] = si }
71
+ default: "Standard_A1_v2"
74
72
 
75
73
  deprecated_option :bootstrap_protocol,
76
74
  replacement: :connection_protocol,
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -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 locate_config_value(:extended_logs)
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: locate_config_value(: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 locate_config_value(:azure_dns_name).nil? && (server.instance_of? Azure::Role)
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 !locate_config_value(:azure_dns_name).nil?
100
- raise "Hosted service #{locate_config_value(:azure_dns_name)} does not exist."
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 #{locate_config_value(:azure_dns_name)}."
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 || locate_config_value(:azure_dns_name)
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]
@@ -139,10 +139,10 @@ class Chef
139
139
  ext_params
140
140
  end
141
141
 
142
- def wait_until_extension_available(extension_deploy_start_time, extension_availaibility_wait_timeout)
143
- extension_availaibility_wait_time = ((Time.now - extension_deploy_start_time) / 60).round
144
- if extension_availaibility_wait_time <= extension_availaibility_wait_timeout
145
- ## extension availaibility wait time has not exceeded the maximum threshold set for the wait timeout ##
142
+ def wait_until_extension_available(extension_deploy_start_time, extension_availability_wait_timeout)
143
+ extension_availability_wait_time = ((Time.now - extension_deploy_start_time) / 60).round
144
+ if extension_availability_wait_time <= extension_availability_wait_timeout
145
+ ## extension availability wait time has not exceeded the maximum threshold set for the wait timeout ##
146
146
  my_role = nil
147
147
  sleep_and_wait = false
148
148
  deployment = fetch_deployment
@@ -178,12 +178,12 @@ class Chef
178
178
  sleep 30
179
179
  wait_until_extension_available(
180
180
  extension_deploy_start_time,
181
- extension_availaibility_wait_timeout
181
+ extension_availability_wait_timeout
182
182
  )
183
183
  end
184
184
  else
185
- ## extension availaibility wait time exceeded maximum threshold set for the wait timeout ##
186
- raise "\nUnable to fetch chef-client run logs as Chef Extension seems to be unavailable even after #{extension_availaibility_wait_timeout} minutes of its deployment.\n"
185
+ ## extension availability wait time exceeded maximum threshold set for the wait timeout ##
186
+ raise "\nUnable to fetch chef-client run logs as Chef Extension seems to be unavailable even after #{extension_availability_wait_timeout} minutes of its deployment.\n"
187
187
  end
188
188
  end
189
189
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Nimisha Sharad (nimisha.sharad@clogeny.com)
3
- # Copyright:: Copyright 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,8 +29,8 @@ class Chef
29
29
  include Knife::Bootstrap::Bootstrapper
30
30
 
31
31
  deps do
32
- require "time"
33
- include Knife::AzurermBase.load_deps
32
+ require "time" unless defined?(Time)
33
+ include Knife::AzurermBase
34
34
  end
35
35
 
36
36
  banner "knife bootstrap azurerm SERVER (options)"
@@ -87,7 +87,7 @@ class Chef
87
87
  #### run() execution ends ####
88
88
 
89
89
  def set_ext_params
90
- server = service.find_server(locate_config_value(:azure_resource_group_name), name_args[0])
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] = locate_config_value(: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] = locate_config_value(: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 '#{locate_config_value(:azure_resource_group_name)}'"
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 2010-2019, Chef Software Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,26 +29,23 @@ class Chef
29
29
  deps do
30
30
  require "readline"
31
31
  require "chef/json_compat"
32
- require_relative "../../azure/service_management/ASM_interface"
32
+ require_relative "../../../azure/service_management/ASM_interface"
33
33
  end
34
34
 
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,40 +55,34 @@ 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 == locate_config_value(:azure_source_image) }
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
72
68
  else
73
- return target_image[0].os == "Windows"
69
+ target_image[0].os == "Windows"
74
70
  end
75
71
  end
76
72
 
77
73
  def service
78
74
  @service ||= begin
79
75
  service = Azure::ServiceManagement::ASMInterface.new(
80
- azure_subscription_id: locate_config_value(:azure_subscription_id),
81
- azure_mgmt_cert: locate_config_value(:azure_mgmt_cert),
82
- azure_api_host_name: locate_config_value(:azure_api_host_name),
83
- verify_ssl_cert: locate_config_value(: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", locate_config_value(:azure_source_image))
107
- msg_pair("Azure Service Location", locate_config_value(: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", locate_config_value(:environment) || "_default")
115
- msg_pair("Runlist", locate_config_value(:run_list)) unless locate_config_value(:run_list).empty?
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
- # (locate_config_value(:connection_password).length <= 6 && locate_config_value(:connection_password).length >= 72)
115
+ # (config[:connection_password].length <= 6 && config[:connection_password].length >= 72)
125
116
  def validate_params!
126
- if locate_config_value(:connection_password) && !locate_config_value(:connection_password).length.between?(6, 72)
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 locate_config_value(:azure_connect_to_existing_dns) && locate_config_value(:azure_vm_name).nil?
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 !!locate_config_value(:azure_service_location) ^ !!locate_config_value(:azure_affinity_group)
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?(locate_config_value(:azure_source_image))
142
- ui.error("Image '#{locate_config_value(:azure_source_image)}' is invalid")
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 locate_config_value(:azure_domain_name) || locate_config_value(:azure_domain_user)
148
- if locate_config_value(:azure_domain_user).nil? || locate_config_value(:azure_domain_passwd).nil?
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 locate_config_value(:winrm_ssl) && locate_config_value(:thumbprint).nil? && locate_config_value(:winrm_no_verify_cert).nil?
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 locate_config_value(:extended_logs) && locate_config_value(:connection_protocol) != "cloud-api"
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 locate_config_value(:connection_protocol) == "cloud-api" && locate_config_value(:azure_vm_name).nil? && locate_config_value(:azure_dns_name).nil?
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 locate_config_value(:daemon)
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 locate_config_value(:connection_protocol) == "cloud-api"
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?(locate_config_value(:daemon).downcase)
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 locate_config_value(k).nil?
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 locate_config_value(:azure_mgmt_cert).nil?
201
- config[:azure_mgmt_cert] = File.read find_file(locate_config_value(:azure_mgmt_cert))
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 !locate_config_value(:azure_publish_settings_file).nil?
205
- parse_publish_settings_file(locate_config_value(:azure_publish_settings_file))
206
- elsif locate_config_value(:azure_subscription_id).nil? && locate_config_value(:azure_mgmt_cert).nil? && locate_config_value(:azure_api_host_name).nil?
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)
@@ -213,10 +204,10 @@ class Chef
213
204
  end
214
205
 
215
206
  def parse_publish_settings_file(filename)
216
- require "nokogiri"
217
- require "base64"
218
- require "openssl"
219
- require "uri"
207
+ require "nokogiri" unless defined?(Nokogiri)
208
+ require "base64" unless defined?(Base64)
209
+ require "openssl" unless defined?(OpenSSL)
210
+ require "uri" unless defined?(URI)
220
211
  begin
221
212
  doc = Nokogiri::XML(File.open(find_file(filename)))
222
213
  profile = doc.at_css("PublishProfile")
@@ -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
- Chef::Config[:knife][:azure_api_host_name] = URI(profile.attribute("Url").value).host
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
- Chef::Config[:knife][:azure_api_host_name] = URI(subscription.attribute("ServiceManagementUrl").value).host
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
- Chef::Config[:knife][:azure_mgmt_cert] = management_cert.certificate.to_pem + management_cert.key.to_pem
235
- Chef::Config[:knife][:azure_subscription_id] = doc.at_css("Subscription").attribute("Id").value
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
@@ -244,19 +235,19 @@ class Chef
244
235
  end
245
236
 
246
237
  def parse_azure_profile(filename, errors)
247
- require "openssl"
248
- require "uri"
238
+ require "openssl" unless defined?(OpenSSL)
239
+ require "uri" unless defined?(URI)
249
240
  errors = [] if errors.nil?
250
241
  azure_profile = File.read(File.expand_path(filename))
251
242
  azure_profile = JSON.parse(azure_profile)
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
- Chef::Config[:knife][:azure_subscription_id] = default_subscription["id"]
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
- Chef::Config[:knife][:azure_mgmt_cert] = mgmt_key + mgmt_cert
259
- Chef::Config[:knife][:azure_api_host_name] = URI(default_subscription["managementEndpointUrl"]).host
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,10 +291,8 @@ class Chef
300
291
  end
301
292
 
302
293
  def fetch_deployment
303
- deployment_name = service.deployment_name(locate_config_value(:azure_dns_name))
304
- deployment = service.deployment("hostedservices/#{locate_config_value(:azure_dns_name)}/deployments/#{deployment_name}")
305
-
306
- deployment
294
+ deployment_name = service.deployment_name(config[:azure_dns_name])
295
+ service.deployment("hostedservices/#{config[:azure_dns_name]}/deployments/#{deployment_name}")
307
296
  end
308
297
 
309
298
  def fetch_role
@@ -312,7 +301,7 @@ class Chef
312
301
  if deployment.at_css("Deployment Name") != nil
313
302
  role_list_xml = deployment.css("RoleInstanceList RoleInstance")
314
303
  role_list_xml.each do |role|
315
- if role.at_css("RoleName").text == (locate_config_value(:azure_vm_name) || @name_args[0])
304
+ if role.at_css("RoleName").text == (config[:azure_vm_name] || @name_args[0])
316
305
  return role
317
306
  end
318
307
  end
@@ -391,11 +380,11 @@ class Chef
391
380
  end
392
381
  else
393
382
  ## Chef Extension could not be found ##
394
- ui.error("Unable to find Chef extension under role #{locate_config_value(:azure_vm_name) || @name_args[0]}.")
383
+ ui.error("Unable to find Chef extension under role #{config[:azure_vm_name] || @name_args[0]}.")
395
384
  end
396
385
  else
397
386
  ## server could not be found ##
398
- ui.error("chef-client run logs could not be fetched since role #{locate_config_value(:azure_vm_name) || @name_args[0]} could not be found.")
387
+ ui.error("chef-client run logs could not be fetched since role #{config[:azure_vm_name] || @name_args[0]} could not be found.")
399
388
  end
400
389
  end
401
390
  end