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
@@ -1,68 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Barry Davis (barryd@jetstreamsoftware.com)
|
3
|
-
# Copyright:: Copyright (c) Chef Software 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
|
-
module Azure
|
20
|
-
class Disks
|
21
|
-
def initialize(connection)
|
22
|
-
@connection = connection
|
23
|
-
end
|
24
|
-
|
25
|
-
def all
|
26
|
-
disks = []
|
27
|
-
response = @connection.query_azure("disks")
|
28
|
-
founddisks = response.css("Disk")
|
29
|
-
founddisks.each do |disk|
|
30
|
-
item = Disk.new(disk)
|
31
|
-
disks << item
|
32
|
-
end
|
33
|
-
disks
|
34
|
-
end
|
35
|
-
|
36
|
-
def find(name)
|
37
|
-
founddisk = nil
|
38
|
-
all.each do |disk|
|
39
|
-
next unless disk.name == name
|
40
|
-
|
41
|
-
founddisk = disk
|
42
|
-
end
|
43
|
-
founddisk
|
44
|
-
end
|
45
|
-
|
46
|
-
def exists(name)
|
47
|
-
!find(name).nil?
|
48
|
-
end
|
49
|
-
|
50
|
-
def clear_unattached
|
51
|
-
all.each do |disk|
|
52
|
-
next unless disk.attached == false
|
53
|
-
|
54
|
-
@connection.query_azure("disks/" + disk.name, "delete")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
module Azure
|
61
|
-
class Disk
|
62
|
-
attr_accessor :name, :attached
|
63
|
-
def initialize(disk)
|
64
|
-
@name = disk.at_css("Name").content
|
65
|
-
@attached = !disk.at_css("AttachedTo").nil?
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Barry Davis (barryd@jetstreamsoftware.com)
|
3
|
-
# Copyright:: Copyright (c) Chef Software 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
|
-
module Azure
|
20
|
-
class Hosts
|
21
|
-
include AzureUtility
|
22
|
-
def initialize(connection)
|
23
|
-
@connection = connection
|
24
|
-
end
|
25
|
-
|
26
|
-
# force_load should be true when there is something in local cache and we want to reload
|
27
|
-
# first call is always load.
|
28
|
-
def load(force_load = false)
|
29
|
-
unless @hosted_services || force_load
|
30
|
-
@hosted_services = begin
|
31
|
-
hosted_services = {}
|
32
|
-
responseXML = @connection.query_azure("hostedservices")
|
33
|
-
servicesXML = responseXML.css("HostedServices HostedService")
|
34
|
-
servicesXML.each do |serviceXML|
|
35
|
-
host = Host.new(@connection).parse(serviceXML)
|
36
|
-
hosted_services[host.name] = host
|
37
|
-
end
|
38
|
-
hosted_services
|
39
|
-
end
|
40
|
-
end
|
41
|
-
@hosted_services
|
42
|
-
end
|
43
|
-
|
44
|
-
def all
|
45
|
-
load.values
|
46
|
-
end
|
47
|
-
|
48
|
-
# first look up local cache if we have already loaded list.
|
49
|
-
def exists?(name)
|
50
|
-
return @hosted_services.key?(name) if @hosted_services
|
51
|
-
|
52
|
-
exists_on_cloud?(name)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Look up on cloud and not local cache
|
56
|
-
def exists_on_cloud?(name)
|
57
|
-
ret_val = @connection.query_azure("hostedservices/#{name}")
|
58
|
-
error_code, error_message = error_from_response_xml(ret_val) if ret_val
|
59
|
-
if ret_val.nil? || error_code.length > 0
|
60
|
-
Chef::Log.debug("Unable to find hosted(cloud) service:" + error_code + " : " + error_message) if ret_val
|
61
|
-
false
|
62
|
-
else
|
63
|
-
true
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
# first look up local cache if we have already loaded list.
|
68
|
-
def find(name)
|
69
|
-
return @hosted_services[name] if @hosted_services && @hosted_services.key?(name)
|
70
|
-
|
71
|
-
fetch_from_cloud(name)
|
72
|
-
end
|
73
|
-
|
74
|
-
# Look up hosted service on cloud and not local cache
|
75
|
-
def fetch_from_cloud(name)
|
76
|
-
ret_val = @connection.query_azure("hostedservices/#{name}")
|
77
|
-
error_code, error_message = error_from_response_xml(ret_val) if ret_val
|
78
|
-
if ret_val.nil? || error_code.length > 0
|
79
|
-
Chef::Log.warn("Unable to find hosted(cloud) service:" + error_code + " : " + error_message) if ret_val
|
80
|
-
nil
|
81
|
-
else
|
82
|
-
Host.new(@connection).parse(ret_val)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def create(params)
|
87
|
-
host = Host.new(@connection)
|
88
|
-
host.create(params)
|
89
|
-
end
|
90
|
-
|
91
|
-
def delete(name)
|
92
|
-
if exists?(name)
|
93
|
-
servicecall = "hostedservices/" + name
|
94
|
-
@connection.query_azure(servicecall, "delete")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
module Azure
|
101
|
-
class Host
|
102
|
-
include AzureUtility
|
103
|
-
attr_accessor :connection, :name, :url, :label
|
104
|
-
attr_accessor :dateCreated, :description, :location
|
105
|
-
attr_accessor :dateModified, :status
|
106
|
-
|
107
|
-
def initialize(connection)
|
108
|
-
@connection = connection
|
109
|
-
@deploys_loaded = false
|
110
|
-
@deploys = {}
|
111
|
-
end
|
112
|
-
|
113
|
-
def parse(serviceXML)
|
114
|
-
@name = xml_content(serviceXML, "ServiceName")
|
115
|
-
@url = xml_content(serviceXML, "Url")
|
116
|
-
@label = xml_content(serviceXML, "HostedServiceProperties Label")
|
117
|
-
@dateCreated = xml_content(serviceXML, "HostedServiceProperties DateCreated")
|
118
|
-
@description = xml_content(serviceXML, "HostedServiceProperties Description")
|
119
|
-
@location = xml_content(serviceXML, "HostedServiceProperties Location")
|
120
|
-
@dateModified = xml_content(serviceXML, "HostedServiceProperties DateLastModified")
|
121
|
-
@status = xml_content(serviceXML, "HostedServiceProperties Status")
|
122
|
-
self
|
123
|
-
end
|
124
|
-
|
125
|
-
def create(params)
|
126
|
-
builder = Nokogiri::XML::Builder.new do |xml|
|
127
|
-
xml.CreateHostedService("xmlns" => "http://schemas.microsoft.com/windowsazure") do
|
128
|
-
xml.ServiceName params[:azure_dns_name]
|
129
|
-
xml.Label Base64.encode64(params[:azure_dns_name])
|
130
|
-
xml.Description "Explicitly created hosted service"
|
131
|
-
unless params[:azure_service_location].nil?
|
132
|
-
xml.Location params[:azure_service_location]
|
133
|
-
end
|
134
|
-
unless params[:azure_affinity_group].nil?
|
135
|
-
xml.AffinityGroup params[:azure_affinity_group]
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
@connection.query_azure("hostedservices", "post", builder.to_xml)
|
140
|
-
end
|
141
|
-
|
142
|
-
def details
|
143
|
-
response = @connection.query_azure("hostedservices/" + @name + "?embed-detail=true")
|
144
|
-
end
|
145
|
-
|
146
|
-
# Deployments within this hostedservice
|
147
|
-
def add_deploy(deploy)
|
148
|
-
@deploys[deploy.name] = deploy
|
149
|
-
end
|
150
|
-
|
151
|
-
def delete_role(role)
|
152
|
-
deploys.each { |d| d.delete_role_if_present(role) }
|
153
|
-
end
|
154
|
-
|
155
|
-
def deploys
|
156
|
-
# check if we have deploys loaded, else load.
|
157
|
-
if (@deploys.length == 0) && !@deploys_loaded
|
158
|
-
deploy = Deploy.new(@connection)
|
159
|
-
deploy.retrieve(@name)
|
160
|
-
@deploys[deploy.name] = deploy
|
161
|
-
@deploys_loaded = true
|
162
|
-
end
|
163
|
-
@deploys.values
|
164
|
-
end
|
165
|
-
|
166
|
-
def roles
|
167
|
-
roles = []
|
168
|
-
deploys.each do |deploy|
|
169
|
-
roles.concat(deploy.roles) if deploy.roles
|
170
|
-
end
|
171
|
-
roles
|
172
|
-
end
|
173
|
-
|
174
|
-
def find_role(role_name, deploy_name = nil)
|
175
|
-
return @deploys[deploy_name].find_role(role_name) if deploy_name && deploys
|
176
|
-
|
177
|
-
# else lookup all deploys within hostedservice
|
178
|
-
deploys.each do |deploy|
|
179
|
-
role = deploy.find_role(role_name)
|
180
|
-
return role if role
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Barry Davis (barryd@jetstreamsoftware.com)
|
3
|
-
# Copyright:: Copyright (c) Chef Software 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
|
-
module Azure
|
20
|
-
class Images
|
21
|
-
def initialize(connection)
|
22
|
-
@connection = connection
|
23
|
-
end
|
24
|
-
|
25
|
-
def load
|
26
|
-
@images ||= begin
|
27
|
-
osimages = get_images("OSImage") # get OSImages
|
28
|
-
vmimages = get_images("VMImage") # get VMImages
|
29
|
-
|
30
|
-
all_images = osimages.merge(vmimages)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def all
|
35
|
-
load.values
|
36
|
-
end
|
37
|
-
|
38
|
-
# img_type = OSImages or VMImage
|
39
|
-
def get_images(img_type)
|
40
|
-
images = {}
|
41
|
-
|
42
|
-
if img_type == "OSImage"
|
43
|
-
response = @connection.query_azure("images")
|
44
|
-
elsif img_type == "VMImage"
|
45
|
-
response = @connection.query_azure("vmimages")
|
46
|
-
end
|
47
|
-
|
48
|
-
unless response.to_s.empty?
|
49
|
-
osimages = response.css(img_type)
|
50
|
-
|
51
|
-
osimages.each do |image|
|
52
|
-
item = Image.new(image)
|
53
|
-
images[item.name] = item
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
images
|
58
|
-
end
|
59
|
-
|
60
|
-
def is_os_image(image_name)
|
61
|
-
os_images = get_images("OSImage").values
|
62
|
-
os_images.detect { |img| img.name == image_name } ? true : false
|
63
|
-
end
|
64
|
-
|
65
|
-
def is_vm_image(image_name)
|
66
|
-
vm_images = get_images("VMImage").values
|
67
|
-
vm_images.detect { |img| img.name == image_name } ? true : false
|
68
|
-
end
|
69
|
-
|
70
|
-
def exists?(name)
|
71
|
-
all.detect { |img| img.name == name } ? true : false
|
72
|
-
end
|
73
|
-
|
74
|
-
def find(name)
|
75
|
-
load[name]
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
module Azure
|
81
|
-
class Image
|
82
|
-
attr_accessor :category, :label
|
83
|
-
attr_accessor :name, :os, :eula, :description, :location
|
84
|
-
def initialize(image)
|
85
|
-
@category = image.at_css("Category").content
|
86
|
-
@label = image.at_css("Label").content
|
87
|
-
@name = image.at_css("Name").content
|
88
|
-
@os = image.at_css("OS").content
|
89
|
-
@location = image.at_css("Location").content.gsub(";", ", ") if image.at_css("Location")
|
90
|
-
@eula = image.at_css("Eula").content if image.at_css("Eula")
|
91
|
-
@description = image.at_css("Description").content if image.at_css("Description")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Aiman Alsari (aiman.alsari@gmail.com)
|
3
|
-
# Copyright:: Copyright (c) Chef Software 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
|
-
module Azure
|
20
|
-
class Loadbalancer
|
21
|
-
include AzureUtility
|
22
|
-
attr_accessor :name, :service, :subnet, :vip
|
23
|
-
|
24
|
-
def initialize(connection)
|
25
|
-
@connection = connection
|
26
|
-
end
|
27
|
-
|
28
|
-
def load
|
29
|
-
@lbs ||= begin
|
30
|
-
@lbs = {}
|
31
|
-
@connection.deploys.all.each do |deploy|
|
32
|
-
@lbs.merge!(deploy.loadbalancers)
|
33
|
-
end
|
34
|
-
@lbs
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def all
|
39
|
-
load.values
|
40
|
-
end
|
41
|
-
|
42
|
-
def exists?(name)
|
43
|
-
load.key?(name)
|
44
|
-
end
|
45
|
-
|
46
|
-
def find(name)
|
47
|
-
load[name]
|
48
|
-
end
|
49
|
-
|
50
|
-
def parse(lbXML, hostedservicename)
|
51
|
-
@name = xml_content(lbXML, "Name")
|
52
|
-
ip_configXML = lbXML.css("FrontendIpConfiguration")
|
53
|
-
@subnet = xml_content(ip_configXML, "SubnetName")
|
54
|
-
@vip = xml_content(ip_configXML, "StaticVirtualNetworkIPAddress")
|
55
|
-
@service = hostedservicename
|
56
|
-
self
|
57
|
-
end
|
58
|
-
|
59
|
-
def create(params)
|
60
|
-
if params[:azure_lb_static_vip] && !params[:azure_subnet_name]
|
61
|
-
Chef::Log.fatal "Unable to create Loadbalancer, :azure_subnet_name needs to be set if :azure_lb_static_vip is set"
|
62
|
-
end
|
63
|
-
builder = Nokogiri::XML::Builder.new(encoding: "utf-8") do |xml|
|
64
|
-
xml.LoadBalancer(xmlns: "http://schemas.microsoft.com/windowsazure") do
|
65
|
-
xml.Name params[:azure_load_balancer]
|
66
|
-
xml.FrontendIpConfiguration do
|
67
|
-
xml.Type "Private"
|
68
|
-
xml.SubnetName params[:azure_subnet_name] if params[:azure_subnet_name]
|
69
|
-
xml.StaticVirtualNetworkIPAddress params[:azure_lb_static_vip] if params[:azure_lb_static_vip]
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
deploy_name = @connection.deploys.get_deploy_name_for_hostedservice(params[:azure_dns_name])
|
74
|
-
servicecall = "hostedservices/#{params[:azure_dns_name]}/deployments/#{deploy_name}/loadbalancers"
|
75
|
-
@connection.query_azure(servicecall, "post", builder.doc.to_xml)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Barry Davis (barryd@jetstreamsoftware.com)
|
3
|
-
# Copyright:: Copyright (c) Chef Software 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 "net/http" unless defined?(Net::HTTP)
|
20
|
-
require "openssl" unless defined?(OpenSSL)
|
21
|
-
require "uri" unless defined?(URI)
|
22
|
-
require "nokogiri" unless defined?(Nokogiri)
|
23
|
-
|
24
|
-
module AzureAPI
|
25
|
-
|
26
|
-
class Rest
|
27
|
-
def initialize(params)
|
28
|
-
@subscription_id = params[:azure_subscription_id]
|
29
|
-
@pem_file = params[:azure_mgmt_cert]
|
30
|
-
@host_name = params[:azure_api_host_name]
|
31
|
-
@verify_ssl = params[:verify_ssl_cert]
|
32
|
-
end
|
33
|
-
|
34
|
-
def query_azure(service_name,
|
35
|
-
verb = "get",
|
36
|
-
body = "",
|
37
|
-
params = "",
|
38
|
-
services = true,
|
39
|
-
content_type = nil)
|
40
|
-
svc_str = services ? "/services" : ""
|
41
|
-
uri = URI.parse("#{@host_name}/#{@subscription_id}#{svc_str}/#{service_name}")
|
42
|
-
scheme = !uri.scheme ? "https://" : ""
|
43
|
-
request_url = "#{scheme}#{@host_name}/#{@subscription_id}#{svc_str}/#{service_name}"
|
44
|
-
print "."
|
45
|
-
response = http_query(request_url, verb, body, params, content_type)
|
46
|
-
if response.code.to_i == 307
|
47
|
-
Chef::Log.debug "Redirect to #{response["Location"]}"
|
48
|
-
response = http_query(response["Location"], verb, body, params, content_type)
|
49
|
-
end
|
50
|
-
@last_request_id = response["x-ms-request-id"]
|
51
|
-
response
|
52
|
-
end
|
53
|
-
|
54
|
-
def http_query(request_url, verb, body, params, content_type = nil)
|
55
|
-
uri = URI.parse(request_url)
|
56
|
-
uri.query = params
|
57
|
-
http = http_setup(uri)
|
58
|
-
request = request_setup(uri, verb, body, content_type)
|
59
|
-
response = http.request(request)
|
60
|
-
@last_request_id = response["x-ms-request-id"]
|
61
|
-
response
|
62
|
-
end
|
63
|
-
|
64
|
-
def query_for_completion
|
65
|
-
uri = URI.parse("#{@host_name}/#{@subscription_id}/operations/#{@last_request_id}")
|
66
|
-
scheme = !uri.scheme ? "https://" : ""
|
67
|
-
request_url = "#{scheme}#{@host_name}/#{@subscription_id}/operations/#{@last_request_id}"
|
68
|
-
response = http_query(request_url, "get", "", "")
|
69
|
-
if response.code.to_i == 307
|
70
|
-
Chef::Log.debug "Redirect to #{response["Location"]}"
|
71
|
-
response = http_query(response["Location"], "get", "", "")
|
72
|
-
end
|
73
|
-
response
|
74
|
-
end
|
75
|
-
|
76
|
-
def http_setup(uri)
|
77
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
78
|
-
store = OpenSSL::X509::Store.new
|
79
|
-
store.set_default_paths
|
80
|
-
http.cert_store = store
|
81
|
-
if @verify_ssl
|
82
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
83
|
-
else
|
84
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
85
|
-
end
|
86
|
-
http.use_ssl = true
|
87
|
-
begin
|
88
|
-
http.cert = OpenSSL::X509::Certificate.new(@pem_file)
|
89
|
-
rescue OpenSSL::X509::CertificateError => err
|
90
|
-
raise "Invalid Azure Certificate pem file. Error: #{err}"
|
91
|
-
end
|
92
|
-
http.key = OpenSSL::PKey::RSA.new(@pem_file)
|
93
|
-
http
|
94
|
-
end
|
95
|
-
|
96
|
-
def request_setup(uri, verb, body, content_type)
|
97
|
-
if verb == "get"
|
98
|
-
request = Net::HTTP::Get.new(uri.request_uri)
|
99
|
-
elsif verb == "post"
|
100
|
-
request = Net::HTTP::Post.new(uri.request_uri)
|
101
|
-
elsif verb == "delete"
|
102
|
-
request = Net::HTTP::Delete.new(uri.request_uri)
|
103
|
-
elsif verb == "put"
|
104
|
-
request = Net::HTTP::Put.new(uri.request_uri)
|
105
|
-
end
|
106
|
-
text = verb == "put" && content_type.nil?
|
107
|
-
request["x-ms-version"] = "2014-05-01"
|
108
|
-
request["content-type"] = text ? "text/plain" : "application/xml"
|
109
|
-
request["accept"] = "application/xml"
|
110
|
-
request["accept-charset"] = "utf-8"
|
111
|
-
request.body = body
|
112
|
-
request
|
113
|
-
end
|
114
|
-
|
115
|
-
def showResponse(response)
|
116
|
-
puts "=== response body ==="
|
117
|
-
puts response.body
|
118
|
-
puts "=== response.code ==="
|
119
|
-
puts response.code
|
120
|
-
puts "=== response.inspect ==="
|
121
|
-
puts response.inspect
|
122
|
-
puts "=== all of the headers ==="
|
123
|
-
puts response.each_header { |h, j| puts h.inspect + " : " + j.inspect }
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|