knife-azure 1.8.7 → 1.9.0

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/azure_interface.rb +79 -81
  3. data/lib/azure/custom_errors.rb +34 -35
  4. data/lib/azure/helpers.rb +43 -44
  5. data/lib/azure/resource_management/ARM_deployment_template.rb +679 -678
  6. data/lib/azure/resource_management/ARM_interface.rb +513 -515
  7. data/lib/azure/resource_management/vnet_config.rb +43 -43
  8. data/lib/azure/resource_management/windows_credentials.rb +181 -184
  9. data/lib/azure/service_management/ASM_interface.rb +309 -317
  10. data/lib/azure/service_management/ag.rb +16 -16
  11. data/lib/azure/service_management/certificate.rb +30 -31
  12. data/lib/azure/service_management/connection.rb +31 -31
  13. data/lib/azure/service_management/deploy.rb +40 -38
  14. data/lib/azure/service_management/disk.rb +14 -10
  15. data/lib/azure/service_management/host.rb +28 -24
  16. data/lib/azure/service_management/image.rb +23 -22
  17. data/lib/azure/service_management/loadbalancer.rb +12 -12
  18. data/lib/azure/service_management/rest.rb +20 -19
  19. data/lib/azure/service_management/role.rb +274 -273
  20. data/lib/azure/service_management/storageaccount.rb +29 -25
  21. data/lib/azure/service_management/utility.rb +6 -7
  22. data/lib/azure/service_management/vnet.rb +44 -44
  23. data/lib/chef/knife/azure_ag_create.rb +18 -18
  24. data/lib/chef/knife/azure_ag_list.rb +3 -3
  25. data/lib/chef/knife/azure_base.rb +56 -56
  26. data/lib/chef/knife/azure_image_list.rb +8 -10
  27. data/lib/chef/knife/azure_internal-lb_create.rb +15 -15
  28. data/lib/chef/knife/azure_internal-lb_list.rb +3 -3
  29. data/lib/chef/knife/azure_server_create.rb +49 -50
  30. data/lib/chef/knife/azure_server_delete.rb +22 -24
  31. data/lib/chef/knife/azure_server_list.rb +4 -4
  32. data/lib/chef/knife/azure_server_show.rb +5 -5
  33. data/lib/chef/knife/azure_vnet_create.rb +17 -17
  34. data/lib/chef/knife/azure_vnet_list.rb +3 -3
  35. data/lib/chef/knife/azurerm_base.rb +58 -60
  36. data/lib/chef/knife/azurerm_server_create.rb +23 -22
  37. data/lib/chef/knife/azurerm_server_delete.rb +30 -34
  38. data/lib/chef/knife/azurerm_server_list.rb +42 -42
  39. data/lib/chef/knife/azurerm_server_show.rb +1 -1
  40. data/lib/chef/knife/bootstrap/bootstrap_options.rb +7 -8
  41. data/lib/chef/knife/bootstrap/bootstrapper.rb +65 -65
  42. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +3 -4
  43. data/lib/chef/knife/bootstrap_azure.rb +13 -13
  44. data/lib/chef/knife/bootstrap_azurerm.rb +106 -106
  45. data/lib/knife-azure/version.rb +2 -2
  46. metadata +43 -76
  47. data/lib/azure/resource_management/ARM_base.rb +0 -29
@@ -1,317 +1,309 @@
1
- #
2
- # Author::
3
- # Copyright:: Copyright (c) 2016 Opscode, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require 'azure/azure_interface'
20
- require 'azure/service_management/rest'
21
- require 'azure/service_management/connection'
22
-
23
- module Azure
24
- class ServiceManagement
25
- class ASMInterface < AzureInterface
26
- include AzureAPI
27
-
28
- attr_accessor :connection
29
-
30
- def initialize(params = {})
31
- @rest = Rest.new(params)
32
- @connection = Azure::ServiceManagement::Connection.new(@rest)
33
- super
34
- end
35
-
36
- def list_images
37
- connection.images.all
38
- end
39
-
40
- def list_servers
41
- servers = connection.roles.all
42
- cols = ['DNS Name', 'VM Name', 'Status', 'IP Address', 'SSH Port', 'WinRM Port', 'RDP Port']
43
- rows = []
44
- servers.each do |server|
45
- rows << server.hostedservicename.to_s+".cloudapp.net" # Info about the DNS name at http://msdn.microsoft.com/en-us/library/ee460806.aspx
46
- rows << server.name.to_s
47
- rows << begin
48
- state = server.status.to_s.downcase
49
- case state
50
- when 'shutting-down','terminated','stopping','stopped'
51
- ui.color(state, :red)
52
- when 'pending'
53
- ui.color(state, :yellow)
54
- else
55
- ui.color('ready', :green)
56
- end
57
- end
58
- rows << server.publicipaddress.to_s
59
- rows << server.sshport.to_s
60
- rows << server.winrmport.to_s
61
- ports = server.tcpports
62
- rows << rdp_port(ports)
63
- end
64
- display_list(ui, cols, rows)
65
- end
66
-
67
- def rdp_port(arr_ports)
68
- if !arr_ports
69
- return ''
70
- end
71
- if arr_ports.length > 0
72
- arr_ports.each do |port|
73
- if port['Name'] == "Remote Desktop"
74
- return port['PublicPort']
75
- end
76
- end
77
- end
78
- return ''
79
- end
80
-
81
- def find_server(params = {})
82
- server = connection.roles.find(params[:name], params = { :azure_dns_name => params[:azure_dns_name] })
83
- end
84
-
85
- def delete_server(params = {})
86
- server = find_server({name: params[:name], azure_dns_name: params[:azure_dns_name]})
87
-
88
- unless server
89
- puts "\n"
90
- ui.error("Server #{params[:name]} does not exist")
91
- exit!
92
- end
93
-
94
- puts "\n"
95
- msg_pair(ui, 'DNS Name', server.hostedservicename + ".cloudapp.net")
96
- msg_pair(ui, 'VM Name', server.name)
97
- msg_pair(ui, 'Size', server.size)
98
- msg_pair(ui, 'Public Ip Address', server.publicipaddress)
99
- puts "\n"
100
-
101
- begin
102
- ui.confirm('Do you really want to delete this server')
103
- rescue SystemExit # Need to handle this as confirming with N/n raises SystemExit exception
104
- server = nil # Cleanup is implicitly performed in other cloud plugins
105
- exit!
106
- end
107
-
108
- params[:azure_dns_name] = server.hostedservicename
109
-
110
- connection.roles.delete(params)
111
-
112
- puts "\n"
113
- ui.warn("Deleted server #{server.name}")
114
- end
115
-
116
- def show_server(name)
117
- begin
118
- role = connection.roles.find name
119
-
120
- puts ''
121
- if (role)
122
- details = Array.new
123
- details << ui.color('Role name', :bold, :cyan)
124
- details << role.name
125
- details << ui.color('Status', :bold, :cyan)
126
- details << role.status
127
- details << ui.color('Size', :bold, :cyan)
128
- details << role.size
129
- details << ui.color('Hosted service name', :bold, :cyan)
130
- details << role.hostedservicename
131
- details << ui.color('Deployment name', :bold, :cyan)
132
- details << role.deployname
133
- details << ui.color('Host name', :bold, :cyan)
134
- details << role.hostname
135
- unless role.sshport.nil?
136
- details << ui.color('SSH port', :bold, :cyan)
137
- details << role.sshport
138
- end
139
- unless role.winrmport.nil?
140
- details << ui.color('WinRM port', :bold, :cyan)
141
- details << role.winrmport
142
- end
143
- details << ui.color('Public IP', :bold, :cyan)
144
- details << role.publicipaddress.to_s
145
-
146
- unless role.thumbprint.empty?
147
- details << ui.color('Thumbprint', :bold, :cyan)
148
- details << role.thumbprint
149
- end
150
- puts ui.list(details, :columns_across, 2)
151
- if role.tcpports.length > 0 || role.udpports.length > 0
152
- details.clear
153
- details << ui.color('Ports open', :bold, :cyan)
154
- details << ui.color('Local port', :bold, :cyan)
155
- details << ui.color('IP', :bold, :cyan)
156
- details << ui.color('Public port', :bold, :cyan)
157
- if role.tcpports.length > 0
158
- role.tcpports.each do |port|
159
- details << 'tcp'
160
- details << port['LocalPort']
161
- details << port['Vip']
162
- details << port['PublicPort']
163
- end
164
- end
165
- if role.udpports.length > 0
166
- role.udpports.each do |port|
167
- details << 'udp'
168
- details << port['LocalPort']
169
- details << port['Vip']
170
- details << port['PublicPort']
171
- end
172
- end
173
- puts ui.list(details, :columns_across, 4)
174
- end
175
- else
176
- puts "No VM found"
177
- end
178
-
179
- rescue => error
180
- puts "#{error.class} and #{error.message}"
181
- end
182
-
183
- end
184
-
185
- def list_internal_lb
186
- lbs = connection.lbs.all
187
- cols = %w{Name Service Subnet VIP}
188
- rows = []
189
- lbs.each do |lb|
190
- cols.each { |col| rows << lb.send(col.downcase).to_s }
191
- end
192
- display_list(ui, cols, rows)
193
- end
194
-
195
- def create_internal_lb(params = {})
196
- connection.lbs.create(params)
197
- end
198
-
199
- def list_vnets
200
- vnets = connection.vnets.all
201
- cols = ['Name', 'Affinity Group', 'State']
202
- rows = []
203
- vnets.each do |vnet|
204
- %w(name affinity_group state).each{ |col| rows << vnet.send(col).to_s }
205
- end
206
- display_list(ui, cols, rows)
207
- end
208
-
209
- def create_vnet(params = {})
210
- connection.vnets.create(params)
211
- end
212
-
213
- def list_affinity_groups
214
- affinity_groups = connection.ags.all
215
- cols = %w{Name Location Description}
216
- rows = []
217
- affinity_groups.each do |affinity_group|
218
- cols.each { |col| rows << affinity_group.send(col.downcase).to_s }
219
- end
220
- display_list(ui, cols, rows)
221
- end
222
-
223
- def create_affinity_group(params = {})
224
- connection.ags.create(params)
225
- end
226
-
227
- def create_server(params = {})
228
- remove_hosted_service_on_failure = params[:azure_dns_name]
229
- if connection.hosts.exists?(params[:azure_dns_name])
230
- remove_hosted_service_on_failure = nil
231
- end
232
-
233
- #If Storage Account is not specified, check if the geographic location has one to re-use
234
- if not params[:azure_storage_account]
235
- storage_accts = connection.storageaccounts.all
236
- storage = storage_accts.find { |storage_acct| storage_acct.location.to_s == params[:azure_service_location] }
237
- unless storage
238
- params[:azure_storage_account] = [strip_non_ascii(params[:azure_vm_name]), random_string].join.downcase
239
- remove_storage_service_on_failure = params[:azure_storage_account]
240
- else
241
- remove_storage_service_on_failure = nil
242
- params[:azure_storage_account] = storage.name.to_s
243
- end
244
- else
245
- if connection.storageaccounts.exists?(params[:azure_storage_account])
246
- remove_storage_service_on_failure = nil
247
- else
248
- remove_storage_service_on_failure = params[:azure_storage_account]
249
- end
250
- end
251
-
252
- begin
253
- connection.deploys.create(params)
254
- rescue Exception => e
255
- Chef::Log.error("Failed to create the server -- exception being rescued: #{e.to_s}")
256
- backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
257
- Chef::Log.debug("#{backtrace_message}")
258
- cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
259
- end
260
-
261
- end
262
-
263
- def cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
264
- Chef::Log.warn("Cleaning up resources...")
265
-
266
- if remove_hosted_service_on_failure
267
- ret_val = connection.hosts.delete(remove_hosted_service_on_failure)
268
- ret_val.content.empty? ? Chef::Log.warn("Deleted created DNS: #{remove_hosted_service_on_failure}.") : Chef::Log.warn("Deletion failed for created DNS:#{remove_hosted_service_on_failure}. " + ret_val.text)
269
- end
270
-
271
- if remove_storage_service_on_failure
272
- ret_val = connection.storageaccounts.delete(remove_storage_service_on_failure)
273
- ret_val.content.empty? ? Chef::Log.warn("Deleted created Storage Account: #{remove_storage_service_on_failure}.") : Chef::Log.warn("Deletion failed for created Storage Account: #{remove_storage_service_on_failure}. " + ret_val.text)
274
- end
275
- exit 1
276
- end
277
-
278
- def get_role_server(dns_name, vm_name)
279
- deploy = connection.deploys.queryDeploy(dns_name)
280
- deploy.find_role(vm_name)
281
- end
282
-
283
- def get_extension(name, publisher)
284
- connection.query_azure("resourceextensions/#{publisher}/#{name}")
285
- end
286
-
287
- def deployment_name(dns_name)
288
- connection.deploys.get_deploy_name_for_hostedservice(dns_name)
289
- end
290
-
291
- def deployment(path)
292
- connection.query_azure(path)
293
- end
294
-
295
- def valid_image?(name)
296
- connection.images.exists?(name)
297
- end
298
-
299
- def vm_image?(name)
300
- connection.images.is_vm_image(name)
301
- end
302
-
303
- def add_extension(name, params = {})
304
- begin
305
- ui.info "Started with Chef Extension deployment on the server #{name}..."
306
- connection.roles.update(name, params)
307
- ui.info "\nSuccessfully deployed Chef Extension on the server #{name}."
308
- rescue Exception => e
309
- Chef::Log.error("Failed to add extension to the server -- exception being rescued: #{e.to_s}")
310
- backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
311
- Chef::Log.debug("#{backtrace_message}")
312
- end
313
- end
314
- end
315
- end
316
- end
317
-
1
+ #
2
+ # Copyright:: Copyright 2016-2018 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require "azure/azure_interface"
19
+ require "azure/service_management/rest"
20
+ require "azure/service_management/connection"
21
+
22
+ module Azure
23
+ class ServiceManagement
24
+ class ASMInterface < AzureInterface
25
+ include AzureAPI
26
+
27
+ attr_accessor :connection
28
+
29
+ def initialize(params = {})
30
+ @rest = Rest.new(params)
31
+ @connection = Azure::ServiceManagement::Connection.new(@rest)
32
+ super
33
+ end
34
+
35
+ def list_images
36
+ connection.images.all
37
+ end
38
+
39
+ def list_servers
40
+ servers = connection.roles.all
41
+ cols = ["DNS Name", "VM Name", "Status", "IP Address", "SSH Port", "WinRM Port", "RDP Port"]
42
+ rows = []
43
+ servers.each do |server|
44
+ rows << server.hostedservicename.to_s + ".cloudapp.net" # Info about the DNS name at http://msdn.microsoft.com/en-us/library/ee460806.aspx
45
+ rows << server.name.to_s
46
+ rows << begin
47
+ state = server.status.to_s.downcase
48
+ case state
49
+ when "shutting-down", "terminated", "stopping", "stopped"
50
+ ui.color(state, :red)
51
+ when "pending"
52
+ ui.color(state, :yellow)
53
+ else
54
+ ui.color("ready", :green)
55
+ end
56
+ end
57
+ rows << server.publicipaddress.to_s
58
+ rows << server.sshport.to_s
59
+ rows << server.winrmport.to_s
60
+ ports = server.tcpports
61
+ rows << rdp_port(ports)
62
+ end
63
+ display_list(ui, cols, rows)
64
+ end
65
+
66
+ def rdp_port(arr_ports)
67
+ if !arr_ports
68
+ return ""
69
+ end
70
+ if arr_ports.length > 0
71
+ arr_ports.each do |port|
72
+ if port["Name"] == "Remote Desktop"
73
+ return port["PublicPort"]
74
+ end
75
+ end
76
+ end
77
+ ""
78
+ end
79
+
80
+ def find_server(params = {})
81
+ server = connection.roles.find(params[:name], params = { :azure_dns_name => params[:azure_dns_name] })
82
+ end
83
+
84
+ def delete_server(params = {})
85
+ server = find_server({ name: params[:name], azure_dns_name: params[:azure_dns_name] })
86
+
87
+ unless server
88
+ puts "\n"
89
+ ui.error("Server #{params[:name]} does not exist")
90
+ exit!
91
+ end
92
+
93
+ puts "\n"
94
+ msg_pair(ui, "DNS Name", server.hostedservicename + ".cloudapp.net")
95
+ msg_pair(ui, "VM Name", server.name)
96
+ msg_pair(ui, "Size", server.size)
97
+ msg_pair(ui, "Public Ip Address", server.publicipaddress)
98
+ puts "\n"
99
+
100
+ begin
101
+ ui.confirm("Do you really want to delete this server")
102
+ rescue SystemExit # Need to handle this as confirming with N/n raises SystemExit exception
103
+ server = nil # Cleanup is implicitly performed in other cloud plugins
104
+ exit!
105
+ end
106
+
107
+ params[:azure_dns_name] = server.hostedservicename
108
+
109
+ connection.roles.delete(params)
110
+
111
+ puts "\n"
112
+ ui.warn("Deleted server #{server.name}")
113
+ end
114
+
115
+ def show_server(name)
116
+ role = connection.roles.find name
117
+
118
+ puts ""
119
+ if role
120
+ details = Array.new
121
+ details << ui.color("Role name", :bold, :cyan)
122
+ details << role.name
123
+ details << ui.color("Status", :bold, :cyan)
124
+ details << role.status
125
+ details << ui.color("Size", :bold, :cyan)
126
+ details << role.size
127
+ details << ui.color("Hosted service name", :bold, :cyan)
128
+ details << role.hostedservicename
129
+ details << ui.color("Deployment name", :bold, :cyan)
130
+ details << role.deployname
131
+ details << ui.color("Host name", :bold, :cyan)
132
+ details << role.hostname
133
+ unless role.sshport.nil?
134
+ details << ui.color("SSH port", :bold, :cyan)
135
+ details << role.sshport
136
+ end
137
+ unless role.winrmport.nil?
138
+ details << ui.color("WinRM port", :bold, :cyan)
139
+ details << role.winrmport
140
+ end
141
+ details << ui.color("Public IP", :bold, :cyan)
142
+ details << role.publicipaddress.to_s
143
+
144
+ unless role.thumbprint.empty?
145
+ details << ui.color("Thumbprint", :bold, :cyan)
146
+ details << role.thumbprint
147
+ end
148
+ puts ui.list(details, :columns_across, 2)
149
+ if role.tcpports.length > 0 || role.udpports.length > 0
150
+ details.clear
151
+ details << ui.color("Ports open", :bold, :cyan)
152
+ details << ui.color("Local port", :bold, :cyan)
153
+ details << ui.color("IP", :bold, :cyan)
154
+ details << ui.color("Public port", :bold, :cyan)
155
+ if role.tcpports.length > 0
156
+ role.tcpports.each do |port|
157
+ details << "tcp"
158
+ details << port["LocalPort"]
159
+ details << port["Vip"]
160
+ details << port["PublicPort"]
161
+ end
162
+ end
163
+ if role.udpports.length > 0
164
+ role.udpports.each do |port|
165
+ details << "udp"
166
+ details << port["LocalPort"]
167
+ details << port["Vip"]
168
+ details << port["PublicPort"]
169
+ end
170
+ end
171
+ puts ui.list(details, :columns_across, 4)
172
+ end
173
+ else
174
+ puts "No VM found"
175
+ end
176
+
177
+ rescue => error
178
+ puts "#{error.class} and #{error.message}"
179
+ end
180
+
181
+ def list_internal_lb
182
+ lbs = connection.lbs.all
183
+ cols = %w{Name Service Subnet VIP}
184
+ rows = []
185
+ lbs.each do |lb|
186
+ cols.each { |col| rows << lb.send(col.downcase).to_s }
187
+ end
188
+ display_list(ui, cols, rows)
189
+ end
190
+
191
+ def create_internal_lb(params = {})
192
+ connection.lbs.create(params)
193
+ end
194
+
195
+ def list_vnets
196
+ vnets = connection.vnets.all
197
+ cols = ["Name", "Affinity Group", "State"]
198
+ rows = []
199
+ vnets.each do |vnet|
200
+ %w{name affinity_group state}.each { |col| rows << vnet.send(col).to_s }
201
+ end
202
+ display_list(ui, cols, rows)
203
+ end
204
+
205
+ def create_vnet(params = {})
206
+ connection.vnets.create(params)
207
+ end
208
+
209
+ def list_affinity_groups
210
+ affinity_groups = connection.ags.all
211
+ cols = %w{Name Location Description}
212
+ rows = []
213
+ affinity_groups.each do |affinity_group|
214
+ cols.each { |col| rows << affinity_group.send(col.downcase).to_s }
215
+ end
216
+ display_list(ui, cols, rows)
217
+ end
218
+
219
+ def create_affinity_group(params = {})
220
+ connection.ags.create(params)
221
+ end
222
+
223
+ def create_server(params = {})
224
+ remove_hosted_service_on_failure = params[:azure_dns_name]
225
+ if connection.hosts.exists?(params[:azure_dns_name])
226
+ remove_hosted_service_on_failure = nil
227
+ end
228
+
229
+ #If Storage Account is not specified, check if the geographic location has one to re-use
230
+ if not params[:azure_storage_account]
231
+ storage_accts = connection.storageaccounts.all
232
+ storage = storage_accts.find { |storage_acct| storage_acct.location.to_s == params[:azure_service_location] }
233
+ unless storage
234
+ params[:azure_storage_account] = [strip_non_ascii(params[:azure_vm_name]), random_string].join.downcase
235
+ remove_storage_service_on_failure = params[:azure_storage_account]
236
+ else
237
+ remove_storage_service_on_failure = nil
238
+ params[:azure_storage_account] = storage.name.to_s
239
+ end
240
+ else
241
+ if connection.storageaccounts.exists?(params[:azure_storage_account])
242
+ remove_storage_service_on_failure = nil
243
+ else
244
+ remove_storage_service_on_failure = params[:azure_storage_account]
245
+ end
246
+ end
247
+
248
+ begin
249
+ connection.deploys.create(params)
250
+ rescue Exception => e
251
+ Chef::Log.error("Failed to create the server -- exception being rescued: #{e}")
252
+ backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
253
+ Chef::Log.debug("#{backtrace_message}")
254
+ cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
255
+ end
256
+ end
257
+
258
+ def cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
259
+ Chef::Log.warn("Cleaning up resources...")
260
+
261
+ if remove_hosted_service_on_failure
262
+ ret_val = connection.hosts.delete(remove_hosted_service_on_failure)
263
+ ret_val.content.empty? ? Chef::Log.warn("Deleted created DNS: #{remove_hosted_service_on_failure}.") : Chef::Log.warn("Deletion failed for created DNS:#{remove_hosted_service_on_failure}. " + ret_val.text)
264
+ end
265
+
266
+ if remove_storage_service_on_failure
267
+ ret_val = connection.storageaccounts.delete(remove_storage_service_on_failure)
268
+ ret_val.content.empty? ? Chef::Log.warn("Deleted created Storage Account: #{remove_storage_service_on_failure}.") : Chef::Log.warn("Deletion failed for created Storage Account: #{remove_storage_service_on_failure}. " + ret_val.text)
269
+ end
270
+ exit 1
271
+ end
272
+
273
+ def get_role_server(dns_name, vm_name)
274
+ deploy = connection.deploys.queryDeploy(dns_name)
275
+ deploy.find_role(vm_name)
276
+ end
277
+
278
+ def get_extension(name, publisher)
279
+ connection.query_azure("resourceextensions/#{publisher}/#{name}")
280
+ end
281
+
282
+ def deployment_name(dns_name)
283
+ connection.deploys.get_deploy_name_for_hostedservice(dns_name)
284
+ end
285
+
286
+ def deployment(path)
287
+ connection.query_azure(path)
288
+ end
289
+
290
+ def valid_image?(name)
291
+ connection.images.exists?(name)
292
+ end
293
+
294
+ def vm_image?(name)
295
+ connection.images.is_vm_image(name)
296
+ end
297
+
298
+ def add_extension(name, params = {})
299
+ ui.info "Started with Chef Extension deployment on the server #{name}..."
300
+ connection.roles.update(name, params)
301
+ ui.info "\nSuccessfully deployed Chef Extension on the server #{name}."
302
+ rescue Exception => e
303
+ Chef::Log.error("Failed to add extension to the server -- exception being rescued: #{e}")
304
+ backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
305
+ Chef::Log.debug("#{backtrace_message}")
306
+ end
307
+ end
308
+ end
309
+ end