knife-azure 3.0.6 → 4.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/custom_errors.rb +1 -1
- data/lib/azure/resource_management/ARM_deployment_template.rb +5 -5
- data/lib/azure/resource_management/ARM_interface.rb +4 -6
- data/lib/azure/resource_management/windows_credentials.rb +2 -2
- data/lib/chef/knife/azurerm_server_create.rb +1 -1
- data/lib/chef/knife/bootstrap/bootstrapper.rb +5 -10
- data/lib/chef/knife/helpers/azurerm_base.rb +4 -4
- data/lib/knife-azure/version.rb +1 -1
- metadata +30 -43
- data/lib/azure/service_management/ASM_interface.rb +0 -310
- data/lib/azure/service_management/ag.rb +0 -99
- data/lib/azure/service_management/certificate.rb +0 -235
- data/lib/azure/service_management/connection.rb +0 -102
- data/lib/azure/service_management/deploy.rb +0 -221
- data/lib/azure/service_management/disk.rb +0 -68
- data/lib/azure/service_management/host.rb +0 -184
- data/lib/azure/service_management/image.rb +0 -94
- data/lib/azure/service_management/loadbalancer.rb +0 -78
- data/lib/azure/service_management/rest.rb +0 -126
- data/lib/azure/service_management/role.rb +0 -717
- data/lib/azure/service_management/storageaccount.rb +0 -127
- data/lib/azure/service_management/utility.rb +0 -40
- data/lib/azure/service_management/vnet.rb +0 -134
- data/lib/chef/knife/azure_ag_create.rb +0 -73
- data/lib/chef/knife/azure_ag_list.rb +0 -35
- data/lib/chef/knife/azure_image_list.rb +0 -56
- data/lib/chef/knife/azure_internal-lb_create.rb +0 -74
- data/lib/chef/knife/azure_internal-lb_list.rb +0 -35
- data/lib/chef/knife/azure_server_create.rb +0 -531
- data/lib/chef/knife/azure_server_delete.rb +0 -136
- data/lib/chef/knife/azure_server_list.rb +0 -38
- data/lib/chef/knife/azure_server_show.rb +0 -41
- data/lib/chef/knife/azure_vnet_create.rb +0 -74
- data/lib/chef/knife/azure_vnet_list.rb +0 -35
- data/lib/chef/knife/bootstrap_azure.rb +0 -191
- data/lib/chef/knife/helpers/azure_base.rb +0 -392
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba6a2397f4641337ac1c0e35e060bdec8878111da9ca1d41d5207e15a0209b71
|
4
|
+
data.tar.gz: fb2691f81f0ba4c79d3dd86e7d04ff1ec92b85da1dfda35641b8b65d8b8f1025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9f8f4ba4b588eeca8037853e842cae06e7cb699fc758fbe83c3e0e7b6d05ae67319a65bb85e4a97fc34c28c5590dad65980856052883be1becf2bd4bbf7d9b9
|
7
|
+
data.tar.gz: c7f1e891b81df8dc594a349ddffb61b9fb0fb6d8cc90ff3d6a972b82b1e2a199fa2b8a89631f86cf41678d9ae5dd8949806d21a0c76365d1e57db6d7750f3d5c
|
data/lib/azure/custom_errors.rb
CHANGED
@@ -51,7 +51,7 @@ module Azure::ARM
|
|
51
51
|
# Security Rule priority can be set between 100 and 4096
|
52
52
|
rule_no = 300
|
53
53
|
incremental = 0
|
54
|
-
|
54
|
+
tcp_ports.each do |port|
|
55
55
|
rule_no += 2
|
56
56
|
sec_grp_json["properties"]["securityRules"].push(
|
57
57
|
"name" => vm_name + "_rule_" + incremental.to_s,
|
@@ -510,7 +510,7 @@ module Azure::ARM
|
|
510
510
|
}
|
511
511
|
|
512
512
|
length = template["resources"].length.to_i - 1
|
513
|
-
|
513
|
+
(0..length).each do |i|
|
514
514
|
if template["resources"][i]["type"] == "Microsoft.Compute/virtualMachines"
|
515
515
|
template["resources"][i]["dependsOn"] << "[concat('Microsoft.Compute/availabilitySets/', parameters('availabilitySetName'))]"
|
516
516
|
template["resources"][i]["properties"]["availabilitySet"] = { "id" => "[resourceId('Microsoft.Compute/availabilitySets', parameters('availabilitySetName'))]" }
|
@@ -523,7 +523,7 @@ module Azure::ARM
|
|
523
523
|
sec_grp_json = tcp_ports(params[:tcp_endpoints], params[:azure_vm_name])
|
524
524
|
template["resources"].insert(1, sec_grp_json)
|
525
525
|
length = template["resources"].length.to_i - 1
|
526
|
-
|
526
|
+
(0..length).each do |i|
|
527
527
|
if template["resources"][i]["type"] == "Microsoft.Network/virtualNetworks"
|
528
528
|
template["resources"][i] = template["resources"][i].merge({ "dependsOn" => [sec_grp] })
|
529
529
|
end
|
@@ -558,7 +558,7 @@ module Azure::ARM
|
|
558
558
|
end
|
559
559
|
if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
|
560
560
|
template["resources"].last["properties"]["protectedSettings"]["client_pem"] = "[parameters(concat('client_pem',copyIndex()))]"
|
561
|
-
0.upto
|
561
|
+
0.upto(params[:server_count].to_i - 1) do |count|
|
562
562
|
template["parameters"]["client_pem" + count.to_s] = {
|
563
563
|
"type" => "string",
|
564
564
|
"metadata" => {
|
@@ -658,7 +658,7 @@ module Azure::ARM
|
|
658
658
|
},
|
659
659
|
}
|
660
660
|
if params[:server_count].to_i > 1 && params[:chef_extension_private_param][:validation_key].nil?
|
661
|
-
0.upto
|
661
|
+
0.upto(params[:server_count].to_i - 1) do |count|
|
662
662
|
parameters["client_pem#{count}"] = {
|
663
663
|
"value" => "#{params[:chef_extension_private_param][("client_pem" + count.to_s).to_sym]}",
|
664
664
|
}
|
@@ -307,7 +307,7 @@ module Azure
|
|
307
307
|
## chef-client run did not complete within maximum timeout of 30 minutes ##
|
308
308
|
## fetch whatever logs available under the chef-client.log file ##
|
309
309
|
color = :yellow
|
310
|
-
|
310
|
+
end
|
311
311
|
puts ui.color(status, color, :bold).to_s
|
312
312
|
puts "----> chef-client run logs: "
|
313
313
|
puts "\n#{message}\n" ## message field of substatus contains the chef-client run logs ##
|
@@ -484,11 +484,9 @@ module Azure
|
|
484
484
|
err_details = err_json["error"]["details"] if err_json["error"]
|
485
485
|
if err_details
|
486
486
|
err_details.each do |err|
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
ui.error(err["message"])
|
491
|
-
end
|
487
|
+
ui.error(JSON.parse(err["message"])["error"]["message"])
|
488
|
+
rescue JSON::ParserError => e
|
489
|
+
ui.error(err["message"])
|
492
490
|
end
|
493
491
|
else
|
494
492
|
ui.error(err_json["error"]["message"])
|
@@ -66,7 +66,7 @@ module Azure
|
|
66
66
|
:Attributes, CREDENTIAL_ATTRIBUTE,
|
67
67
|
:TargetAlias, :LPTSTR,
|
68
68
|
:UserName, :LPTSTR
|
69
|
-
|
69
|
+
end
|
70
70
|
|
71
71
|
# Ref: https://msdn.microsoft.com/en-us/library/windows/desktop/aa374804(v=vs.85).aspx
|
72
72
|
safe_attach_function :CredReadW, %i{LPCTSTR DWORD DWORD pointer}, :BOOL
|
@@ -178,5 +178,5 @@ module Azure
|
|
178
178
|
end
|
179
179
|
end
|
180
180
|
end
|
181
|
-
end
|
181
|
+
end
|
182
182
|
end
|
@@ -292,7 +292,7 @@ class Chef
|
|
292
292
|
def set_os_image(publisher, img_offer, default_os_version)
|
293
293
|
config[:azure_image_reference_publisher] = publisher
|
294
294
|
config[:azure_image_reference_offer] = img_offer
|
295
|
-
config[:azure_image_reference_sku] = config[:azure_image_reference_sku]
|
295
|
+
config[:azure_image_reference_sku] = config[:azure_image_reference_sku] || default_os_version
|
296
296
|
end
|
297
297
|
|
298
298
|
def is_image_os_type?
|
@@ -49,16 +49,11 @@ class Chef
|
|
49
49
|
config[:azure_chef_extension_version]
|
50
50
|
else
|
51
51
|
chef_extension_name ||= get_chef_extension_name
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
)
|
58
|
-
elsif @service.instance_of? Azure::ServiceManagement::ASMInterface
|
59
|
-
extensions = service.get_extension(chef_extension_name, get_chef_extension_publisher)
|
60
|
-
extensions.css("Version").max.text.split(".").first + ".*"
|
61
|
-
end
|
52
|
+
service.get_latest_chef_extension_version(
|
53
|
+
azure_service_location: config[:azure_service_location],
|
54
|
+
chef_extension_publisher: get_chef_extension_publisher,
|
55
|
+
chef_extension: chef_extension_name
|
56
|
+
)
|
62
57
|
end
|
63
58
|
end
|
64
59
|
|
@@ -76,7 +76,7 @@ class Chef
|
|
76
76
|
errors = []
|
77
77
|
keys.each do |k|
|
78
78
|
if config[k].nil?
|
79
|
-
errors << "You did not provide a valid '#{pretty_key(k)}' value. Please set knife[:#{k}] in your knife.rb."
|
79
|
+
errors << "You did not provide a valid '#{pretty_key(k)}' value. Please set knife[:#{k}] in your config.rb (knife.rb)."
|
80
80
|
end
|
81
81
|
end
|
82
82
|
if errors.each { |e| ui.error(e) }.any?
|
@@ -275,10 +275,10 @@ class Chef
|
|
275
275
|
end
|
276
276
|
|
277
277
|
if !is_image_windows?
|
278
|
-
if (config[:azure_vm_name].match
|
278
|
+
if (config[:azure_vm_name].match(/^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,64})$/)).nil?
|
279
279
|
raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximum length cannot exceed 64 characters."
|
280
280
|
end
|
281
|
-
elsif (config[:azure_vm_name].match
|
281
|
+
elsif (config[:azure_vm_name].match(/^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,15})$/)).nil?
|
282
282
|
raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximum length cannot exceed 15 characters."
|
283
283
|
end
|
284
284
|
|
@@ -349,7 +349,7 @@ class Chef
|
|
349
349
|
## in Windows Credentails Manager (WCM).
|
350
350
|
## Newer versions use the same pattern across platforms where credentials gets
|
351
351
|
## stored in ~/.azure/accessTokens.json file.
|
352
|
-
"Please run XPLAT's '#{@azure_prefix} login' command OR specify azure_tenant_id, azure_subscription_id, azure_client_id, azure_client_secret in your knife.rb"
|
352
|
+
"Please run XPLAT's '#{@azure_prefix} login' command OR specify azure_tenant_id, azure_subscription_id, azure_client_id, azure_client_secret in your config.rb (knife.rb)."
|
353
353
|
end
|
354
354
|
end
|
355
355
|
end
|
data/lib/knife-azure/version.rb
CHANGED
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:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Barry Davis
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: knife
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '0'
|
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:
|
27
|
+
version: '0'
|
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.20.0
|
89
86
|
- - "~>"
|
90
87
|
- !ruby/object:Gem::Version
|
91
88
|
version: '0.20'
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.20.0
|
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.20.0
|
99
96
|
- - "~>"
|
100
97
|
- !ruby/object:Gem::Version
|
101
98
|
version: '0.20'
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.20.0
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: azure_mgmt_network
|
104
104
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,7 +161,21 @@ dependencies:
|
|
161
161
|
- - ">="
|
162
162
|
- !ruby/object:Gem::Version
|
163
163
|
version: '0'
|
164
|
-
|
164
|
+
- !ruby/object:Gem::Dependency
|
165
|
+
name: rb-readline
|
166
|
+
requirement: !ruby/object:Gem::Requirement
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
version: '0'
|
171
|
+
type: :runtime
|
172
|
+
prerelease: false
|
173
|
+
version_requirements: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
description: A plugin to the Chef Infra knife tool for creating instances on the Microsoft
|
165
179
|
Azure platform
|
166
180
|
email: oss@chef.io
|
167
181
|
executables: []
|
@@ -177,40 +191,13 @@ files:
|
|
177
191
|
- lib/azure/resource_management/ARM_interface.rb
|
178
192
|
- lib/azure/resource_management/vnet_config.rb
|
179
193
|
- lib/azure/resource_management/windows_credentials.rb
|
180
|
-
- lib/azure/service_management/ASM_interface.rb
|
181
|
-
- lib/azure/service_management/ag.rb
|
182
|
-
- lib/azure/service_management/certificate.rb
|
183
|
-
- lib/azure/service_management/connection.rb
|
184
|
-
- lib/azure/service_management/deploy.rb
|
185
|
-
- lib/azure/service_management/disk.rb
|
186
|
-
- lib/azure/service_management/host.rb
|
187
|
-
- lib/azure/service_management/image.rb
|
188
|
-
- lib/azure/service_management/loadbalancer.rb
|
189
|
-
- lib/azure/service_management/rest.rb
|
190
|
-
- lib/azure/service_management/role.rb
|
191
|
-
- lib/azure/service_management/storageaccount.rb
|
192
|
-
- lib/azure/service_management/utility.rb
|
193
|
-
- lib/azure/service_management/vnet.rb
|
194
|
-
- lib/chef/knife/azure_ag_create.rb
|
195
|
-
- lib/chef/knife/azure_ag_list.rb
|
196
|
-
- lib/chef/knife/azure_image_list.rb
|
197
|
-
- lib/chef/knife/azure_internal-lb_create.rb
|
198
|
-
- lib/chef/knife/azure_internal-lb_list.rb
|
199
|
-
- lib/chef/knife/azure_server_create.rb
|
200
|
-
- lib/chef/knife/azure_server_delete.rb
|
201
|
-
- lib/chef/knife/azure_server_list.rb
|
202
|
-
- lib/chef/knife/azure_server_show.rb
|
203
|
-
- lib/chef/knife/azure_vnet_create.rb
|
204
|
-
- lib/chef/knife/azure_vnet_list.rb
|
205
194
|
- lib/chef/knife/azurerm_server_create.rb
|
206
195
|
- lib/chef/knife/azurerm_server_delete.rb
|
207
196
|
- lib/chef/knife/azurerm_server_list.rb
|
208
197
|
- lib/chef/knife/azurerm_server_show.rb
|
209
198
|
- lib/chef/knife/bootstrap/bootstrapper.rb
|
210
199
|
- lib/chef/knife/bootstrap/common_bootstrap_options.rb
|
211
|
-
- lib/chef/knife/bootstrap_azure.rb
|
212
200
|
- lib/chef/knife/bootstrap_azurerm.rb
|
213
|
-
- lib/chef/knife/helpers/azure_base.rb
|
214
201
|
- lib/chef/knife/helpers/azurerm_base.rb
|
215
202
|
- lib/knife-azure/version.rb
|
216
203
|
homepage: https://github.com/chef/knife-azure
|
@@ -225,16 +212,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
212
|
requirements:
|
226
213
|
- - ">="
|
227
214
|
- !ruby/object:Gem::Version
|
228
|
-
version: '2.
|
215
|
+
version: '2.7'
|
229
216
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
217
|
requirements:
|
231
218
|
- - ">="
|
232
219
|
- !ruby/object:Gem::Version
|
233
220
|
version: '0'
|
234
221
|
requirements: []
|
235
|
-
rubygems_version: 3.
|
222
|
+
rubygems_version: 3.1.4
|
236
223
|
signing_key:
|
237
224
|
specification_version: 4
|
238
|
-
summary: A plugin to the Chef knife tool for creating instances on the Microsoft
|
239
|
-
platform
|
225
|
+
summary: A plugin to the Chef Infra knife tool for creating instances on the Microsoft
|
226
|
+
Azure platform
|
240
227
|
test_files: []
|
@@ -1,310 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 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_relative "../azure_interface"
|
19
|
-
require_relative "rest"
|
20
|
-
require_relative "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
|
-
unless arr_ports
|
68
|
-
return ""
|
69
|
-
end
|
70
|
-
|
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
|
-
""
|
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
|
-
role = connection.roles.find name
|
118
|
-
|
119
|
-
puts ""
|
120
|
-
if role
|
121
|
-
details = []
|
122
|
-
details << ui.color("Role name", :bold, :cyan)
|
123
|
-
details << role.name
|
124
|
-
details << ui.color("Status", :bold, :cyan)
|
125
|
-
details << role.status
|
126
|
-
details << ui.color("Size", :bold, :cyan)
|
127
|
-
details << role.size
|
128
|
-
details << ui.color("Hosted service name", :bold, :cyan)
|
129
|
-
details << role.hostedservicename
|
130
|
-
details << ui.color("Deployment name", :bold, :cyan)
|
131
|
-
details << role.deployname
|
132
|
-
details << ui.color("Host name", :bold, :cyan)
|
133
|
-
details << role.hostname
|
134
|
-
unless role.sshport.nil?
|
135
|
-
details << ui.color("SSH port", :bold, :cyan)
|
136
|
-
details << role.sshport
|
137
|
-
end
|
138
|
-
unless role.winrmport.nil?
|
139
|
-
details << ui.color("WinRM port", :bold, :cyan)
|
140
|
-
details << role.winrmport
|
141
|
-
end
|
142
|
-
details << ui.color("Public IP", :bold, :cyan)
|
143
|
-
details << role.publicipaddress.to_s
|
144
|
-
|
145
|
-
unless role.thumbprint.empty?
|
146
|
-
details << ui.color("Thumbprint", :bold, :cyan)
|
147
|
-
details << role.thumbprint
|
148
|
-
end
|
149
|
-
puts ui.list(details, :columns_across, 2)
|
150
|
-
if role.tcpports.length > 0 || role.udpports.length > 0
|
151
|
-
details.clear
|
152
|
-
details << ui.color("Ports open", :bold, :cyan)
|
153
|
-
details << ui.color("Local port", :bold, :cyan)
|
154
|
-
details << ui.color("IP", :bold, :cyan)
|
155
|
-
details << ui.color("Public port", :bold, :cyan)
|
156
|
-
if role.tcpports.length > 0
|
157
|
-
role.tcpports.each do |port|
|
158
|
-
details << "tcp"
|
159
|
-
details << port["LocalPort"]
|
160
|
-
details << port["Vip"]
|
161
|
-
details << port["PublicPort"]
|
162
|
-
end
|
163
|
-
end
|
164
|
-
if role.udpports.length > 0
|
165
|
-
role.udpports.each do |port|
|
166
|
-
details << "udp"
|
167
|
-
details << port["LocalPort"]
|
168
|
-
details << port["Vip"]
|
169
|
-
details << port["PublicPort"]
|
170
|
-
end
|
171
|
-
end
|
172
|
-
puts ui.list(details, :columns_across, 4)
|
173
|
-
end
|
174
|
-
else
|
175
|
-
puts "No VM found"
|
176
|
-
end
|
177
|
-
|
178
|
-
rescue => error
|
179
|
-
puts "#{error.class} and #{error.message}"
|
180
|
-
end
|
181
|
-
|
182
|
-
def list_internal_lb
|
183
|
-
lbs = connection.lbs.all
|
184
|
-
cols = %w{Name Service Subnet VIP}
|
185
|
-
rows = []
|
186
|
-
lbs.each do |lb|
|
187
|
-
cols.each { |col| rows << lb.send(col.downcase).to_s }
|
188
|
-
end
|
189
|
-
display_list(ui, cols, rows)
|
190
|
-
end
|
191
|
-
|
192
|
-
def create_internal_lb(params = {})
|
193
|
-
connection.lbs.create(params)
|
194
|
-
end
|
195
|
-
|
196
|
-
def list_vnets
|
197
|
-
vnets = connection.vnets.all
|
198
|
-
cols = ["Name", "Affinity Group", "State"]
|
199
|
-
rows = []
|
200
|
-
vnets.each do |vnet|
|
201
|
-
%w{name affinity_group state}.each { |col| rows << vnet.send(col).to_s }
|
202
|
-
end
|
203
|
-
display_list(ui, cols, rows)
|
204
|
-
end
|
205
|
-
|
206
|
-
def create_vnet(params = {})
|
207
|
-
connection.vnets.create(params)
|
208
|
-
end
|
209
|
-
|
210
|
-
def list_affinity_groups
|
211
|
-
affinity_groups = connection.ags.all
|
212
|
-
cols = %w{Name Location Description}
|
213
|
-
rows = []
|
214
|
-
affinity_groups.each do |affinity_group|
|
215
|
-
cols.each { |col| rows << affinity_group.send(col.downcase).to_s }
|
216
|
-
end
|
217
|
-
display_list(ui, cols, rows)
|
218
|
-
end
|
219
|
-
|
220
|
-
def create_affinity_group(params = {})
|
221
|
-
connection.ags.create(params)
|
222
|
-
end
|
223
|
-
|
224
|
-
def create_server(params = {})
|
225
|
-
remove_hosted_service_on_failure = params[:azure_dns_name]
|
226
|
-
if connection.hosts.exists?(params[:azure_dns_name])
|
227
|
-
remove_hosted_service_on_failure = nil
|
228
|
-
end
|
229
|
-
|
230
|
-
# If Storage Account is not specified, check if the geographic location has one to re-use
|
231
|
-
if not params[:azure_storage_account]
|
232
|
-
storage_accts = connection.storageaccounts.all
|
233
|
-
storage = storage_accts.find { |storage_acct| storage_acct.location.to_s == params[:azure_service_location] }
|
234
|
-
unless storage
|
235
|
-
params[:azure_storage_account] = [strip_non_ascii(params[:azure_vm_name]), random_string].join.downcase
|
236
|
-
remove_storage_service_on_failure = params[:azure_storage_account]
|
237
|
-
else
|
238
|
-
remove_storage_service_on_failure = nil
|
239
|
-
params[:azure_storage_account] = storage.name.to_s
|
240
|
-
end
|
241
|
-
else
|
242
|
-
if connection.storageaccounts.exists?(params[:azure_storage_account])
|
243
|
-
remove_storage_service_on_failure = nil
|
244
|
-
else
|
245
|
-
remove_storage_service_on_failure = params[:azure_storage_account]
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
begin
|
250
|
-
connection.deploys.create(params)
|
251
|
-
rescue Exception => e
|
252
|
-
Chef::Log.error("Failed to create the server -- exception being rescued: #{e}")
|
253
|
-
backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
|
254
|
-
Chef::Log.debug("#{backtrace_message}")
|
255
|
-
cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
def cleanup_and_exit(remove_hosted_service_on_failure, remove_storage_service_on_failure)
|
260
|
-
Chef::Log.warn("Cleaning up resources...")
|
261
|
-
|
262
|
-
if remove_hosted_service_on_failure
|
263
|
-
ret_val = connection.hosts.delete(remove_hosted_service_on_failure)
|
264
|
-
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)
|
265
|
-
end
|
266
|
-
|
267
|
-
if remove_storage_service_on_failure
|
268
|
-
ret_val = connection.storageaccounts.delete(remove_storage_service_on_failure)
|
269
|
-
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)
|
270
|
-
end
|
271
|
-
exit 1
|
272
|
-
end
|
273
|
-
|
274
|
-
def get_role_server(dns_name, vm_name)
|
275
|
-
deploy = connection.deploys.queryDeploy(dns_name)
|
276
|
-
deploy.find_role(vm_name)
|
277
|
-
end
|
278
|
-
|
279
|
-
def get_extension(name, publisher)
|
280
|
-
connection.query_azure("resourceextensions/#{publisher}/#{name}")
|
281
|
-
end
|
282
|
-
|
283
|
-
def deployment_name(dns_name)
|
284
|
-
connection.deploys.get_deploy_name_for_hostedservice(dns_name)
|
285
|
-
end
|
286
|
-
|
287
|
-
def deployment(path)
|
288
|
-
connection.query_azure(path)
|
289
|
-
end
|
290
|
-
|
291
|
-
def valid_image?(name)
|
292
|
-
connection.images.exists?(name)
|
293
|
-
end
|
294
|
-
|
295
|
-
def vm_image?(name)
|
296
|
-
connection.images.is_vm_image(name)
|
297
|
-
end
|
298
|
-
|
299
|
-
def add_extension(name, params = {})
|
300
|
-
ui.info "Started with Chef Extension deployment on the server #{name}..."
|
301
|
-
connection.roles.update(name, params)
|
302
|
-
ui.info "\nSuccessfully deployed Chef Extension on the server #{name}."
|
303
|
-
rescue Exception => e
|
304
|
-
Chef::Log.error("Failed to add extension to the server -- exception being rescued: #{e}")
|
305
|
-
backtrace_message = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
|
306
|
-
Chef::Log.debug("#{backtrace_message}")
|
307
|
-
end
|
308
|
-
end
|
309
|
-
end
|
310
|
-
end
|