azure_mgmt_compute 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +3 -0
  5. data/Gemfile +17 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +139 -0
  8. data/Rakefile +5 -0
  9. data/azure_mgmt_compute.gemspec +39 -0
  10. data/lib/azure_mgmt_compute.rb +103 -0
  11. data/lib/azure_mgmt_compute/Models/additional_unattend_content.rb +108 -0
  12. data/lib/azure_mgmt_compute/Models/api_error.rb +121 -0
  13. data/lib/azure_mgmt_compute/Models/api_error_base.rb +76 -0
  14. data/lib/azure_mgmt_compute/Models/availability_set.rb +94 -0
  15. data/lib/azure_mgmt_compute/Models/availability_set_list_result.rb +79 -0
  16. data/lib/azure_mgmt_compute/Models/availability_set_properties.rb +130 -0
  17. data/lib/azure_mgmt_compute/Models/caching_types.rb +17 -0
  18. data/lib/azure_mgmt_compute/Models/component_names.rb +15 -0
  19. data/lib/azure_mgmt_compute/Models/compute_long_running_operation_properties.rb +58 -0
  20. data/lib/azure_mgmt_compute/Models/compute_long_running_operation_result.rb +126 -0
  21. data/lib/azure_mgmt_compute/Models/compute_operation_status.rb +18 -0
  22. data/lib/azure_mgmt_compute/Models/data_disk.rb +142 -0
  23. data/lib/azure_mgmt_compute/Models/data_disk_image.rb +62 -0
  24. data/lib/azure_mgmt_compute/Models/delete_operation_result.rb +109 -0
  25. data/lib/azure_mgmt_compute/Models/disk_create_option_types.rb +17 -0
  26. data/lib/azure_mgmt_compute/Models/disk_instance_view.rb +88 -0
  27. data/lib/azure_mgmt_compute/Models/hardware_profile.rb +67 -0
  28. data/lib/azure_mgmt_compute/Models/image_reference.rb +87 -0
  29. data/lib/azure_mgmt_compute/Models/inner_error.rb +68 -0
  30. data/lib/azure_mgmt_compute/Models/instance_view_status.rb +102 -0
  31. data/lib/azure_mgmt_compute/Models/linux_configuration.rb +75 -0
  32. data/lib/azure_mgmt_compute/Models/list_usages_result.rb +78 -0
  33. data/lib/azure_mgmt_compute/Models/network_interface_reference.rb +70 -0
  34. data/lib/azure_mgmt_compute/Models/network_interface_reference_properties.rb +59 -0
  35. data/lib/azure_mgmt_compute/Models/network_profile.rb +79 -0
  36. data/lib/azure_mgmt_compute/Models/operating_system_types.rb +16 -0
  37. data/lib/azure_mgmt_compute/Models/operation_status.rb +17 -0
  38. data/lib/azure_mgmt_compute/Models/osdisk.rb +135 -0
  39. data/lib/azure_mgmt_compute/Models/osdisk_image.rb +63 -0
  40. data/lib/azure_mgmt_compute/Models/osprofile.rb +149 -0
  41. data/lib/azure_mgmt_compute/Models/pass_names.rb +15 -0
  42. data/lib/azure_mgmt_compute/Models/plan.rb +85 -0
  43. data/lib/azure_mgmt_compute/Models/protocol_types.rb +16 -0
  44. data/lib/azure_mgmt_compute/Models/purchase_plan.rb +77 -0
  45. data/lib/azure_mgmt_compute/Models/setting_names.rb +16 -0
  46. data/lib/azure_mgmt_compute/Models/ssh_configuration.rb +79 -0
  47. data/lib/azure_mgmt_compute/Models/ssh_public_key.rb +72 -0
  48. data/lib/azure_mgmt_compute/Models/status_level_types.rb +17 -0
  49. data/lib/azure_mgmt_compute/Models/storage_profile.rb +110 -0
  50. data/lib/azure_mgmt_compute/Models/usage.rb +98 -0
  51. data/lib/azure_mgmt_compute/Models/usage_name.rb +68 -0
  52. data/lib/azure_mgmt_compute/Models/usage_unit.rb +15 -0
  53. data/lib/azure_mgmt_compute/Models/vault_certificate.rb +70 -0
  54. data/lib/azure_mgmt_compute/Models/vault_secret_group.rb +96 -0
  55. data/lib/azure_mgmt_compute/Models/virtual_hard_disk.rb +59 -0
  56. data/lib/azure_mgmt_compute/Models/virtual_machine.rb +142 -0
  57. data/lib/azure_mgmt_compute/Models/virtual_machine_agent_instance_view.rb +119 -0
  58. data/lib/azure_mgmt_compute/Models/virtual_machine_capture_parameters.rb +78 -0
  59. data/lib/azure_mgmt_compute/Models/virtual_machine_extension.rb +94 -0
  60. data/lib/azure_mgmt_compute/Models/virtual_machine_extension_handler_instance_view.rb +85 -0
  61. data/lib/azure_mgmt_compute/Models/virtual_machine_extension_image.rb +99 -0
  62. data/lib/azure_mgmt_compute/Models/virtual_machine_extension_image_properties.rb +102 -0
  63. data/lib/azure_mgmt_compute/Models/virtual_machine_extension_instance_view.rb +139 -0
  64. data/lib/azure_mgmt_compute/Models/virtual_machine_extension_properties.rb +133 -0
  65. data/lib/azure_mgmt_compute/Models/virtual_machine_image.rb +99 -0
  66. data/lib/azure_mgmt_compute/Models/virtual_machine_image_properties.rb +110 -0
  67. data/lib/azure_mgmt_compute/Models/virtual_machine_image_resource.rb +83 -0
  68. data/lib/azure_mgmt_compute/Models/virtual_machine_instance_view.rb +188 -0
  69. data/lib/azure_mgmt_compute/Models/virtual_machine_list_result.rb +89 -0
  70. data/lib/azure_mgmt_compute/Models/virtual_machine_properties.rb +156 -0
  71. data/lib/azure_mgmt_compute/Models/virtual_machine_size.rb +111 -0
  72. data/lib/azure_mgmt_compute/Models/virtual_machine_size_list_result.rb +79 -0
  73. data/lib/azure_mgmt_compute/Models/virtual_machine_size_types.rb +34 -0
  74. data/lib/azure_mgmt_compute/Models/win_rmconfiguration.rb +79 -0
  75. data/lib/azure_mgmt_compute/Models/win_rmlistener.rb +73 -0
  76. data/lib/azure_mgmt_compute/Models/windows_configuration.rb +126 -0
  77. data/lib/azure_mgmt_compute/availability_sets.rb +473 -0
  78. data/lib/azure_mgmt_compute/compute_management_client.rb +85 -0
  79. data/lib/azure_mgmt_compute/module_definition.rb +6 -0
  80. data/lib/azure_mgmt_compute/usage_operations.rb +113 -0
  81. data/lib/azure_mgmt_compute/version.rb +6 -0
  82. data/lib/azure_mgmt_compute/virtual_machine_extension_images.rb +325 -0
  83. data/lib/azure_mgmt_compute/virtual_machine_extensions.rb +384 -0
  84. data/lib/azure_mgmt_compute/virtual_machine_images.rb +525 -0
  85. data/lib/azure_mgmt_compute/virtual_machine_sizes.rb +114 -0
  86. data/lib/azure_mgmt_compute/virtual_machines.rb +1412 -0
  87. metadata +303 -0
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.11.0.0
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Compute
7
+ #
8
+ # VirtualMachineSizes
9
+ #
10
+ class VirtualMachineSizes
11
+ include Azure::ARM::Compute::Models
12
+ include MsRestAzure
13
+
14
+ #
15
+ # Creates and initializes a new instance of the VirtualMachineSizes class.
16
+ # @param client service class for accessing basic functionality.
17
+ #
18
+ def initialize(client)
19
+ @client = client
20
+ end
21
+
22
+ # @return reference to the ComputeManagementClient
23
+ attr_reader :client
24
+
25
+ #
26
+ # Lists virtual-machine-sizes available in a location for a subscription.
27
+ # @param location [String] The location upon which virtual-machine-sizes is
28
+ # queried.
29
+ # @param [Hash{String => String}] The hash of custom headers need to be
30
+ # applied to HTTP request.
31
+ #
32
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
33
+ # response.
34
+ #
35
+ def list(location, custom_headers = nil)
36
+ fail ArgumentError, 'location is nil' if location.nil?
37
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
38
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
39
+ # Construct URL
40
+ path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/vmSizes"
41
+ path['{location}'] = ERB::Util.url_encode(location) if path.include?('{location}')
42
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
43
+ url = URI.join(@client.base_url, path)
44
+ properties = {}
45
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
46
+ unless url.query.nil?
47
+ url.query.split('&').each do |url_item|
48
+ url_items_parts = url_item.split('=')
49
+ properties[url_items_parts[0]] = url_items_parts[1]
50
+ end
51
+ end
52
+ properties.reject!{ |key, value| value.nil? }
53
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
54
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
55
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
56
+ url = URI.parse(corrected_url)
57
+
58
+ connection = Faraday.new(:url => url) do |faraday|
59
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
60
+ faraday.use :cookie_jar
61
+ faraday.adapter Faraday.default_adapter
62
+ end
63
+ request_headers = Hash.new
64
+
65
+ # Set Headers
66
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
67
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
68
+
69
+ unless custom_headers.nil?
70
+ custom_headers.each do |key, value|
71
+ request_headers[key] = value
72
+ end
73
+ end
74
+
75
+ # Send Request
76
+ promise = Concurrent::Promise.new do
77
+ connection.get do |request|
78
+ request.headers = request_headers
79
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
80
+ end
81
+ end
82
+
83
+ promise = promise.then do |http_response|
84
+ status_code = http_response.status
85
+ response_content = http_response.body
86
+ unless (status_code == 200)
87
+ error_model = JSON.load(response_content)
88
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
89
+ end
90
+
91
+ # Create Result
92
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
93
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
94
+ # Deserialize Response
95
+ if status_code == 200
96
+ begin
97
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
98
+ unless parsed_response.nil?
99
+ parsed_response = VirtualMachineSizeListResult.deserialize_object(parsed_response)
100
+ end
101
+ result.body = parsed_response
102
+ rescue Exception => e
103
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
104
+ end
105
+ end
106
+
107
+ result
108
+ end
109
+
110
+ promise.execute
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,1412 @@
1
+ # encoding: utf-8
2
+ # Code generated by Microsoft (R) AutoRest Code Generator 0.11.0.0
3
+ # Changes may cause incorrect behavior and will be lost if the code is
4
+ # regenerated.
5
+
6
+ module Azure::ARM::Compute
7
+ #
8
+ # VirtualMachines
9
+ #
10
+ class VirtualMachines
11
+ include Azure::ARM::Compute::Models
12
+ include MsRestAzure
13
+
14
+ #
15
+ # Creates and initializes a new instance of the VirtualMachines class.
16
+ # @param client service class for accessing basic functionality.
17
+ #
18
+ def initialize(client)
19
+ @client = client
20
+ end
21
+
22
+ # @return reference to the ComputeManagementClient
23
+ attr_reader :client
24
+
25
+ #
26
+ # Captures the VM by copying VirtualHardDisks of the VM and outputs a template
27
+ # that can be used to create similar VMs.
28
+ # @param resource_group_name [String] The name of the resource group.
29
+ # @param vm_name [String] The name of the virtual machine.
30
+ # @param parameters [VirtualMachineCaptureParameters] Parameters supplied to
31
+ # the Capture Virtual Machine operation.
32
+ # @return [Concurrent::Promise] promise which provides async access to http
33
+ # response.
34
+ #
35
+ def capture(resource_group_name, vm_name, parameters, custom_headers = nil)
36
+ # Send request
37
+ promise = begin_capture(resource_group_name, vm_name, parameters, custom_headers)
38
+
39
+ promise = promise.then do |response|
40
+ # Defining deserialization method.
41
+ deserialize_method = lambda do |parsed_response|
42
+ unless parsed_response.nil?
43
+ parsed_response = ComputeLongRunningOperationResult.deserialize_object(parsed_response)
44
+ end
45
+ end
46
+
47
+ # Waiting for response.
48
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
49
+ end
50
+
51
+ promise
52
+ end
53
+
54
+ #
55
+ # Captures the VM by copying VirtualHardDisks of the VM and outputs a template
56
+ # that can be used to create similar VMs.
57
+ # @param resource_group_name [String] The name of the resource group.
58
+ # @param vm_name [String] The name of the virtual machine.
59
+ # @param parameters [VirtualMachineCaptureParameters] Parameters supplied to
60
+ # the Capture Virtual Machine operation.
61
+ # @param [Hash{String => String}] The hash of custom headers need to be
62
+ # applied to HTTP request.
63
+ #
64
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
65
+ # response.
66
+ #
67
+ def begin_capture(resource_group_name, vm_name, parameters, custom_headers = nil)
68
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
69
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
70
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
71
+ parameters.validate unless parameters.nil?
72
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
73
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
74
+ # Construct URL
75
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/capture"
76
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
77
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
78
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
79
+ url = URI.join(@client.base_url, path)
80
+ properties = {}
81
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
82
+ unless url.query.nil?
83
+ url.query.split('&').each do |url_item|
84
+ url_items_parts = url_item.split('=')
85
+ properties[url_items_parts[0]] = url_items_parts[1]
86
+ end
87
+ end
88
+ properties.reject!{ |key, value| value.nil? }
89
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
90
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
91
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
92
+ url = URI.parse(corrected_url)
93
+
94
+ connection = Faraday.new(:url => url) do |faraday|
95
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
96
+ faraday.use :cookie_jar
97
+ faraday.adapter Faraday.default_adapter
98
+ end
99
+ request_headers = Hash.new
100
+
101
+ # Set Headers
102
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
103
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
104
+
105
+ unless custom_headers.nil?
106
+ custom_headers.each do |key, value|
107
+ request_headers[key] = value
108
+ end
109
+ end
110
+
111
+ # Serialize Request
112
+ request_headers['Content-Type'] = 'application/json'
113
+ unless parameters.nil?
114
+ parameters = VirtualMachineCaptureParameters.serialize_object(parameters)
115
+ end
116
+ request_content = JSON.generate(parameters, quirks_mode: true)
117
+
118
+ # Send Request
119
+ promise = Concurrent::Promise.new do
120
+ connection.post do |request|
121
+ request.headers = request_headers
122
+ request.body = request_content
123
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
124
+ end
125
+ end
126
+
127
+ promise = promise.then do |http_response|
128
+ status_code = http_response.status
129
+ response_content = http_response.body
130
+ unless (status_code == 200 || status_code == 202)
131
+ error_model = JSON.load(response_content)
132
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
133
+ end
134
+
135
+ # Create Result
136
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
137
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
138
+ # Deserialize Response
139
+ if status_code == 200
140
+ begin
141
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
142
+ unless parsed_response.nil?
143
+ parsed_response = ComputeLongRunningOperationResult.deserialize_object(parsed_response)
144
+ end
145
+ result.body = parsed_response
146
+ rescue Exception => e
147
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
148
+ end
149
+ end
150
+
151
+ result
152
+ end
153
+
154
+ promise.execute
155
+ end
156
+
157
+ #
158
+ # The operation to create or update a virtual machine.
159
+ # @param resource_group_name [String] The name of the resource group.
160
+ # @param vm_name [String] The name of the virtual machine.
161
+ # @param parameters [VirtualMachine] Parameters supplied to the Create Virtual
162
+ # Machine operation.
163
+ # @param @client.api_version [String] Client Api Version.
164
+ # @param @client.subscription_id [String] Gets subscription credentials which
165
+ # uniquely identify Microsoft Azure subscription. The subscription ID forms
166
+ # part of the URI for every service call.
167
+ # @param @client.accept_language [String] Gets or sets the preferred language
168
+ # for the response.
169
+ #
170
+ # @return [Concurrent::Promise] promise which provides async access to http
171
+ # response.
172
+ #
173
+ def create_or_update(resource_group_name, vm_name, parameters, custom_headers = nil)
174
+ # Send request
175
+ promise = begin_create_or_update(resource_group_name, vm_name, parameters, custom_headers)
176
+
177
+ promise = promise.then do |response|
178
+ # Defining deserialization method.
179
+ deserialize_method = lambda do |parsed_response|
180
+ unless parsed_response.nil?
181
+ parsed_response = VirtualMachine.deserialize_object(parsed_response)
182
+ end
183
+ end
184
+
185
+ # Waiting for response.
186
+ @client.get_put_operation_result(response, custom_headers, deserialize_method)
187
+ end
188
+
189
+ promise
190
+ end
191
+
192
+ #
193
+ # The operation to create or update a virtual machine.
194
+ # @param resource_group_name [String] The name of the resource group.
195
+ # @param vm_name [String] The name of the virtual machine.
196
+ # @param parameters [VirtualMachine] Parameters supplied to the Create Virtual
197
+ # Machine operation.
198
+ # @param [Hash{String => String}] The hash of custom headers need to be
199
+ # applied to HTTP request.
200
+ #
201
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
202
+ # response.
203
+ #
204
+ def begin_create_or_update(resource_group_name, vm_name, parameters, custom_headers = nil)
205
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
206
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
207
+ fail ArgumentError, 'parameters is nil' if parameters.nil?
208
+ parameters.validate unless parameters.nil?
209
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
210
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
211
+ # Construct URL
212
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}"
213
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
214
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
215
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
216
+ url = URI.join(@client.base_url, path)
217
+ properties = {}
218
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
219
+ unless url.query.nil?
220
+ url.query.split('&').each do |url_item|
221
+ url_items_parts = url_item.split('=')
222
+ properties[url_items_parts[0]] = url_items_parts[1]
223
+ end
224
+ end
225
+ properties.reject!{ |key, value| value.nil? }
226
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
227
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
228
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
229
+ url = URI.parse(corrected_url)
230
+
231
+ connection = Faraday.new(:url => url) do |faraday|
232
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
233
+ faraday.use :cookie_jar
234
+ faraday.adapter Faraday.default_adapter
235
+ end
236
+ request_headers = Hash.new
237
+
238
+ # Set Headers
239
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
240
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
241
+
242
+ unless custom_headers.nil?
243
+ custom_headers.each do |key, value|
244
+ request_headers[key] = value
245
+ end
246
+ end
247
+
248
+ # Serialize Request
249
+ request_headers['Content-Type'] = 'application/json'
250
+ unless parameters.nil?
251
+ parameters = VirtualMachine.serialize_object(parameters)
252
+ end
253
+ request_content = JSON.generate(parameters, quirks_mode: true)
254
+
255
+ # Send Request
256
+ promise = Concurrent::Promise.new do
257
+ connection.put do |request|
258
+ request.headers = request_headers
259
+ request.body = request_content
260
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
261
+ end
262
+ end
263
+
264
+ promise = promise.then do |http_response|
265
+ status_code = http_response.status
266
+ response_content = http_response.body
267
+ unless (status_code == 201 || status_code == 200)
268
+ error_model = JSON.load(response_content)
269
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
270
+ end
271
+
272
+ # Create Result
273
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
274
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
275
+ # Deserialize Response
276
+ if status_code == 201
277
+ begin
278
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
279
+ unless parsed_response.nil?
280
+ parsed_response = VirtualMachine.deserialize_object(parsed_response)
281
+ end
282
+ result.body = parsed_response
283
+ rescue Exception => e
284
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
285
+ end
286
+ end
287
+ # Deserialize Response
288
+ if status_code == 200
289
+ begin
290
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
291
+ unless parsed_response.nil?
292
+ parsed_response = VirtualMachine.deserialize_object(parsed_response)
293
+ end
294
+ result.body = parsed_response
295
+ rescue Exception => e
296
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
297
+ end
298
+ end
299
+
300
+ result
301
+ end
302
+
303
+ promise.execute
304
+ end
305
+
306
+ #
307
+ # The operation to delete a virtual machine.
308
+ # @param resource_group_name [String] The name of the resource group.
309
+ # @param vm_name [String] The name of the virtual machine.
310
+ # @return [Concurrent::Promise] promise which provides async access to http
311
+ # response.
312
+ #
313
+ def delete(resource_group_name, vm_name, custom_headers = nil)
314
+ # Send request
315
+ promise = begin_delete(resource_group_name, vm_name, custom_headers)
316
+
317
+ promise = promise.then do |response|
318
+ # Defining deserialization method.
319
+ deserialize_method = lambda do |parsed_response|
320
+ end
321
+
322
+ # Waiting for response.
323
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
324
+ end
325
+
326
+ promise
327
+ end
328
+
329
+ #
330
+ # The operation to delete a virtual machine.
331
+ # @param resource_group_name [String] The name of the resource group.
332
+ # @param vm_name [String] The name of the virtual machine.
333
+ # @param [Hash{String => String}] The hash of custom headers need to be
334
+ # applied to HTTP request.
335
+ #
336
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
337
+ # response.
338
+ #
339
+ def begin_delete(resource_group_name, vm_name, custom_headers = nil)
340
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
341
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
342
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
343
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
344
+ # Construct URL
345
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}"
346
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
347
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
348
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
349
+ url = URI.join(@client.base_url, path)
350
+ properties = {}
351
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
352
+ unless url.query.nil?
353
+ url.query.split('&').each do |url_item|
354
+ url_items_parts = url_item.split('=')
355
+ properties[url_items_parts[0]] = url_items_parts[1]
356
+ end
357
+ end
358
+ properties.reject!{ |key, value| value.nil? }
359
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
360
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
361
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
362
+ url = URI.parse(corrected_url)
363
+
364
+ connection = Faraday.new(:url => url) do |faraday|
365
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
366
+ faraday.use :cookie_jar
367
+ faraday.adapter Faraday.default_adapter
368
+ end
369
+ request_headers = Hash.new
370
+
371
+ # Set Headers
372
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
373
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
374
+
375
+ unless custom_headers.nil?
376
+ custom_headers.each do |key, value|
377
+ request_headers[key] = value
378
+ end
379
+ end
380
+
381
+ # Send Request
382
+ promise = Concurrent::Promise.new do
383
+ connection.delete do |request|
384
+ request.headers = request_headers
385
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
386
+ end
387
+ end
388
+
389
+ promise = promise.then do |http_response|
390
+ status_code = http_response.status
391
+ response_content = http_response.body
392
+ unless (status_code == 200 || status_code == 204 || status_code == 202)
393
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
394
+ end
395
+
396
+ # Create Result
397
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
398
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
399
+
400
+ result
401
+ end
402
+
403
+ promise.execute
404
+ end
405
+
406
+ #
407
+ # The operation to get a virtual machine.
408
+ # @param resource_group_name [String] The name of the resource group.
409
+ # @param vm_name [String] The name of the virtual machine.
410
+ # @param expand [String] Name of the property to expand. Allowed value is null
411
+ # or 'instanceView'.
412
+ # @param [Hash{String => String}] The hash of custom headers need to be
413
+ # applied to HTTP request.
414
+ #
415
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
416
+ # response.
417
+ #
418
+ def get(resource_group_name, vm_name, expand = nil, custom_headers = nil)
419
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
420
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
421
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
422
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
423
+ # Construct URL
424
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}"
425
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
426
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
427
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
428
+ url = URI.join(@client.base_url, path)
429
+ properties = {}
430
+ properties['$expand'] = ERB::Util.url_encode(expand.to_s) unless expand.nil?
431
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
432
+ unless url.query.nil?
433
+ url.query.split('&').each do |url_item|
434
+ url_items_parts = url_item.split('=')
435
+ properties[url_items_parts[0]] = url_items_parts[1]
436
+ end
437
+ end
438
+ properties.reject!{ |key, value| value.nil? }
439
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
440
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
441
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
442
+ url = URI.parse(corrected_url)
443
+
444
+ connection = Faraday.new(:url => url) do |faraday|
445
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
446
+ faraday.use :cookie_jar
447
+ faraday.adapter Faraday.default_adapter
448
+ end
449
+ request_headers = Hash.new
450
+
451
+ # Set Headers
452
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
453
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
454
+
455
+ unless custom_headers.nil?
456
+ custom_headers.each do |key, value|
457
+ request_headers[key] = value
458
+ end
459
+ end
460
+
461
+ # Send Request
462
+ promise = Concurrent::Promise.new do
463
+ connection.get do |request|
464
+ request.headers = request_headers
465
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
466
+ end
467
+ end
468
+
469
+ promise = promise.then do |http_response|
470
+ status_code = http_response.status
471
+ response_content = http_response.body
472
+ unless (status_code == 200)
473
+ error_model = JSON.load(response_content)
474
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
475
+ end
476
+
477
+ # Create Result
478
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
479
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
480
+ # Deserialize Response
481
+ if status_code == 200
482
+ begin
483
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
484
+ unless parsed_response.nil?
485
+ parsed_response = VirtualMachine.deserialize_object(parsed_response)
486
+ end
487
+ result.body = parsed_response
488
+ rescue Exception => e
489
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
490
+ end
491
+ end
492
+
493
+ result
494
+ end
495
+
496
+ promise.execute
497
+ end
498
+
499
+ #
500
+ # Shuts down the Virtual Machine and releases the compute resources. You are
501
+ # not billed for the compute resources that this Virtual Machine uses.
502
+ # @param resource_group_name [String] The name of the resource group.
503
+ # @param vm_name [String] The name of the virtual machine.
504
+ # @return [Concurrent::Promise] promise which provides async access to http
505
+ # response.
506
+ #
507
+ def deallocate(resource_group_name, vm_name, custom_headers = nil)
508
+ # Send request
509
+ promise = begin_deallocate(resource_group_name, vm_name, custom_headers)
510
+
511
+ promise = promise.then do |response|
512
+ # Defining deserialization method.
513
+ deserialize_method = lambda do |parsed_response|
514
+ end
515
+
516
+ # Waiting for response.
517
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
518
+ end
519
+
520
+ promise
521
+ end
522
+
523
+ #
524
+ # Shuts down the Virtual Machine and releases the compute resources. You are
525
+ # not billed for the compute resources that this Virtual Machine uses.
526
+ # @param resource_group_name [String] The name of the resource group.
527
+ # @param vm_name [String] The name of the virtual machine.
528
+ # @param [Hash{String => String}] The hash of custom headers need to be
529
+ # applied to HTTP request.
530
+ #
531
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
532
+ # response.
533
+ #
534
+ def begin_deallocate(resource_group_name, vm_name, custom_headers = nil)
535
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
536
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
537
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
538
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
539
+ # Construct URL
540
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate"
541
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
542
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
543
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
544
+ url = URI.join(@client.base_url, path)
545
+ properties = {}
546
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
547
+ unless url.query.nil?
548
+ url.query.split('&').each do |url_item|
549
+ url_items_parts = url_item.split('=')
550
+ properties[url_items_parts[0]] = url_items_parts[1]
551
+ end
552
+ end
553
+ properties.reject!{ |key, value| value.nil? }
554
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
555
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
556
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
557
+ url = URI.parse(corrected_url)
558
+
559
+ connection = Faraday.new(:url => url) do |faraday|
560
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
561
+ faraday.use :cookie_jar
562
+ faraday.adapter Faraday.default_adapter
563
+ end
564
+ request_headers = Hash.new
565
+
566
+ # Set Headers
567
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
568
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
569
+
570
+ unless custom_headers.nil?
571
+ custom_headers.each do |key, value|
572
+ request_headers[key] = value
573
+ end
574
+ end
575
+
576
+ # Send Request
577
+ promise = Concurrent::Promise.new do
578
+ connection.post do |request|
579
+ request.headers = request_headers
580
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
581
+ end
582
+ end
583
+
584
+ promise = promise.then do |http_response|
585
+ status_code = http_response.status
586
+ response_content = http_response.body
587
+ unless (status_code == 202)
588
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
589
+ end
590
+
591
+ # Create Result
592
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
593
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
594
+
595
+ result
596
+ end
597
+
598
+ promise.execute
599
+ end
600
+
601
+ #
602
+ # Sets the state of the VM as Generalized.
603
+ # @param resource_group_name [String] The name of the resource group.
604
+ # @param vm_name [String] The name of the virtual machine.
605
+ # @param [Hash{String => String}] The hash of custom headers need to be
606
+ # applied to HTTP request.
607
+ #
608
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
609
+ # response.
610
+ #
611
+ def generalize(resource_group_name, vm_name, custom_headers = nil)
612
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
613
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
614
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
615
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
616
+ # Construct URL
617
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/generalize"
618
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
619
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
620
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
621
+ url = URI.join(@client.base_url, path)
622
+ properties = {}
623
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
624
+ unless url.query.nil?
625
+ url.query.split('&').each do |url_item|
626
+ url_items_parts = url_item.split('=')
627
+ properties[url_items_parts[0]] = url_items_parts[1]
628
+ end
629
+ end
630
+ properties.reject!{ |key, value| value.nil? }
631
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
632
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
633
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
634
+ url = URI.parse(corrected_url)
635
+
636
+ connection = Faraday.new(:url => url) do |faraday|
637
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
638
+ faraday.use :cookie_jar
639
+ faraday.adapter Faraday.default_adapter
640
+ end
641
+ request_headers = Hash.new
642
+
643
+ # Set Headers
644
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
645
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
646
+
647
+ unless custom_headers.nil?
648
+ custom_headers.each do |key, value|
649
+ request_headers[key] = value
650
+ end
651
+ end
652
+
653
+ # Send Request
654
+ promise = Concurrent::Promise.new do
655
+ connection.post do |request|
656
+ request.headers = request_headers
657
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
658
+ end
659
+ end
660
+
661
+ promise = promise.then do |http_response|
662
+ status_code = http_response.status
663
+ response_content = http_response.body
664
+ unless (status_code == 200)
665
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
666
+ end
667
+
668
+ # Create Result
669
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
670
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
671
+
672
+ result
673
+ end
674
+
675
+ promise.execute
676
+ end
677
+
678
+ #
679
+ # The operation to list virtual machines under a resource group.
680
+ # @param resource_group_name [String] The name of the resource group.
681
+ # @param [Hash{String => String}] The hash of custom headers need to be
682
+ # applied to HTTP request.
683
+ #
684
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
685
+ # response.
686
+ #
687
+ def list(resource_group_name, custom_headers = nil)
688
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
689
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
690
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
691
+ # Construct URL
692
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines"
693
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
694
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
695
+ url = URI.join(@client.base_url, path)
696
+ properties = {}
697
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
698
+ unless url.query.nil?
699
+ url.query.split('&').each do |url_item|
700
+ url_items_parts = url_item.split('=')
701
+ properties[url_items_parts[0]] = url_items_parts[1]
702
+ end
703
+ end
704
+ properties.reject!{ |key, value| value.nil? }
705
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
706
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
707
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
708
+ url = URI.parse(corrected_url)
709
+
710
+ connection = Faraday.new(:url => url) do |faraday|
711
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
712
+ faraday.use :cookie_jar
713
+ faraday.adapter Faraday.default_adapter
714
+ end
715
+ request_headers = Hash.new
716
+
717
+ # Set Headers
718
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
719
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
720
+
721
+ unless custom_headers.nil?
722
+ custom_headers.each do |key, value|
723
+ request_headers[key] = value
724
+ end
725
+ end
726
+
727
+ # Send Request
728
+ promise = Concurrent::Promise.new do
729
+ connection.get do |request|
730
+ request.headers = request_headers
731
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
732
+ end
733
+ end
734
+
735
+ promise = promise.then do |http_response|
736
+ status_code = http_response.status
737
+ response_content = http_response.body
738
+ unless (status_code == 200)
739
+ error_model = JSON.load(response_content)
740
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
741
+ end
742
+
743
+ # Create Result
744
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
745
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
746
+ # Deserialize Response
747
+ if status_code == 200
748
+ begin
749
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
750
+ unless parsed_response.nil?
751
+ parsed_response = VirtualMachineListResult.deserialize_object(parsed_response)
752
+ end
753
+ result.body = parsed_response
754
+ rescue Exception => e
755
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
756
+ end
757
+ end
758
+
759
+ result
760
+ end
761
+
762
+ promise.execute
763
+ end
764
+
765
+ #
766
+ # Gets the list of Virtual Machines in the subscription. Use nextLink property
767
+ # in the response to get the next page of Virtual Machines. Do this till
768
+ # nextLink is not null to fetch all the Virtual Machines.
769
+ # @param [Hash{String => String}] The hash of custom headers need to be
770
+ # applied to HTTP request.
771
+ #
772
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
773
+ # response.
774
+ #
775
+ def list_all(custom_headers = nil)
776
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
777
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
778
+ # Construct URL
779
+ path = "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/virtualMachines"
780
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
781
+ url = URI.join(@client.base_url, path)
782
+ properties = {}
783
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
784
+ unless url.query.nil?
785
+ url.query.split('&').each do |url_item|
786
+ url_items_parts = url_item.split('=')
787
+ properties[url_items_parts[0]] = url_items_parts[1]
788
+ end
789
+ end
790
+ properties.reject!{ |key, value| value.nil? }
791
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
792
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
793
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
794
+ url = URI.parse(corrected_url)
795
+
796
+ connection = Faraday.new(:url => url) do |faraday|
797
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
798
+ faraday.use :cookie_jar
799
+ faraday.adapter Faraday.default_adapter
800
+ end
801
+ request_headers = Hash.new
802
+
803
+ # Set Headers
804
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
805
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
806
+
807
+ unless custom_headers.nil?
808
+ custom_headers.each do |key, value|
809
+ request_headers[key] = value
810
+ end
811
+ end
812
+
813
+ # Send Request
814
+ promise = Concurrent::Promise.new do
815
+ connection.get do |request|
816
+ request.headers = request_headers
817
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
818
+ end
819
+ end
820
+
821
+ promise = promise.then do |http_response|
822
+ status_code = http_response.status
823
+ response_content = http_response.body
824
+ unless (status_code == 200)
825
+ error_model = JSON.load(response_content)
826
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
827
+ end
828
+
829
+ # Create Result
830
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
831
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
832
+ # Deserialize Response
833
+ if status_code == 200
834
+ begin
835
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
836
+ unless parsed_response.nil?
837
+ parsed_response = VirtualMachineListResult.deserialize_object(parsed_response)
838
+ end
839
+ result.body = parsed_response
840
+ rescue Exception => e
841
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
842
+ end
843
+ end
844
+
845
+ result
846
+ end
847
+
848
+ promise.execute
849
+ end
850
+
851
+ #
852
+ # Lists virtual-machine-sizes available to be used for a virtual machine.
853
+ # @param resource_group_name [String] The name of the resource group.
854
+ # @param vm_name [String] The name of the virtual machine.
855
+ # @param [Hash{String => String}] The hash of custom headers need to be
856
+ # applied to HTTP request.
857
+ #
858
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
859
+ # response.
860
+ #
861
+ def list_available_sizes(resource_group_name, vm_name, custom_headers = nil)
862
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
863
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
864
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
865
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
866
+ # Construct URL
867
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/vmSizes"
868
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
869
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
870
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
871
+ url = URI.join(@client.base_url, path)
872
+ properties = {}
873
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
874
+ unless url.query.nil?
875
+ url.query.split('&').each do |url_item|
876
+ url_items_parts = url_item.split('=')
877
+ properties[url_items_parts[0]] = url_items_parts[1]
878
+ end
879
+ end
880
+ properties.reject!{ |key, value| value.nil? }
881
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
882
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
883
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
884
+ url = URI.parse(corrected_url)
885
+
886
+ connection = Faraday.new(:url => url) do |faraday|
887
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
888
+ faraday.use :cookie_jar
889
+ faraday.adapter Faraday.default_adapter
890
+ end
891
+ request_headers = Hash.new
892
+
893
+ # Set Headers
894
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
895
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
896
+
897
+ unless custom_headers.nil?
898
+ custom_headers.each do |key, value|
899
+ request_headers[key] = value
900
+ end
901
+ end
902
+
903
+ # Send Request
904
+ promise = Concurrent::Promise.new do
905
+ connection.get do |request|
906
+ request.headers = request_headers
907
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
908
+ end
909
+ end
910
+
911
+ promise = promise.then do |http_response|
912
+ status_code = http_response.status
913
+ response_content = http_response.body
914
+ unless (status_code == 200)
915
+ error_model = JSON.load(response_content)
916
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
917
+ end
918
+
919
+ # Create Result
920
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
921
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
922
+ # Deserialize Response
923
+ if status_code == 200
924
+ begin
925
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
926
+ unless parsed_response.nil?
927
+ parsed_response = VirtualMachineSizeListResult.deserialize_object(parsed_response)
928
+ end
929
+ result.body = parsed_response
930
+ rescue Exception => e
931
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
932
+ end
933
+ end
934
+
935
+ result
936
+ end
937
+
938
+ promise.execute
939
+ end
940
+
941
+ #
942
+ # The operation to power off (stop) a virtual machine.
943
+ # @param resource_group_name [String] The name of the resource group.
944
+ # @param vm_name [String] The name of the virtual machine.
945
+ # @return [Concurrent::Promise] promise which provides async access to http
946
+ # response.
947
+ #
948
+ def power_off(resource_group_name, vm_name, custom_headers = nil)
949
+ # Send request
950
+ promise = begin_power_off(resource_group_name, vm_name, custom_headers)
951
+
952
+ promise = promise.then do |response|
953
+ # Defining deserialization method.
954
+ deserialize_method = lambda do |parsed_response|
955
+ end
956
+
957
+ # Waiting for response.
958
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
959
+ end
960
+
961
+ promise
962
+ end
963
+
964
+ #
965
+ # The operation to power off (stop) a virtual machine.
966
+ # @param resource_group_name [String] The name of the resource group.
967
+ # @param vm_name [String] The name of the virtual machine.
968
+ # @param [Hash{String => String}] The hash of custom headers need to be
969
+ # applied to HTTP request.
970
+ #
971
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
972
+ # response.
973
+ #
974
+ def begin_power_off(resource_group_name, vm_name, custom_headers = nil)
975
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
976
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
977
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
978
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
979
+ # Construct URL
980
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/powerOff"
981
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
982
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
983
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
984
+ url = URI.join(@client.base_url, path)
985
+ properties = {}
986
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
987
+ unless url.query.nil?
988
+ url.query.split('&').each do |url_item|
989
+ url_items_parts = url_item.split('=')
990
+ properties[url_items_parts[0]] = url_items_parts[1]
991
+ end
992
+ end
993
+ properties.reject!{ |key, value| value.nil? }
994
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
995
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
996
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
997
+ url = URI.parse(corrected_url)
998
+
999
+ connection = Faraday.new(:url => url) do |faraday|
1000
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
1001
+ faraday.use :cookie_jar
1002
+ faraday.adapter Faraday.default_adapter
1003
+ end
1004
+ request_headers = Hash.new
1005
+
1006
+ # Set Headers
1007
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1008
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
1009
+
1010
+ unless custom_headers.nil?
1011
+ custom_headers.each do |key, value|
1012
+ request_headers[key] = value
1013
+ end
1014
+ end
1015
+
1016
+ # Send Request
1017
+ promise = Concurrent::Promise.new do
1018
+ connection.post do |request|
1019
+ request.headers = request_headers
1020
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
1021
+ end
1022
+ end
1023
+
1024
+ promise = promise.then do |http_response|
1025
+ status_code = http_response.status
1026
+ response_content = http_response.body
1027
+ unless (status_code == 202)
1028
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
1029
+ end
1030
+
1031
+ # Create Result
1032
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
1033
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1034
+
1035
+ result
1036
+ end
1037
+
1038
+ promise.execute
1039
+ end
1040
+
1041
+ #
1042
+ # The operation to restart a virtual machine.
1043
+ # @param resource_group_name [String] The name of the resource group.
1044
+ # @param vm_name [String] The name of the virtual machine.
1045
+ # @return [Concurrent::Promise] promise which provides async access to http
1046
+ # response.
1047
+ #
1048
+ def restart(resource_group_name, vm_name, custom_headers = nil)
1049
+ # Send request
1050
+ promise = begin_restart(resource_group_name, vm_name, custom_headers)
1051
+
1052
+ promise = promise.then do |response|
1053
+ # Defining deserialization method.
1054
+ deserialize_method = lambda do |parsed_response|
1055
+ end
1056
+
1057
+ # Waiting for response.
1058
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
1059
+ end
1060
+
1061
+ promise
1062
+ end
1063
+
1064
+ #
1065
+ # The operation to restart a virtual machine.
1066
+ # @param resource_group_name [String] The name of the resource group.
1067
+ # @param vm_name [String] The name of the virtual machine.
1068
+ # @param [Hash{String => String}] The hash of custom headers need to be
1069
+ # applied to HTTP request.
1070
+ #
1071
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
1072
+ # response.
1073
+ #
1074
+ def begin_restart(resource_group_name, vm_name, custom_headers = nil)
1075
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
1076
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
1077
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
1078
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
1079
+ # Construct URL
1080
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/restart"
1081
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
1082
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
1083
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
1084
+ url = URI.join(@client.base_url, path)
1085
+ properties = {}
1086
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
1087
+ unless url.query.nil?
1088
+ url.query.split('&').each do |url_item|
1089
+ url_items_parts = url_item.split('=')
1090
+ properties[url_items_parts[0]] = url_items_parts[1]
1091
+ end
1092
+ end
1093
+ properties.reject!{ |key, value| value.nil? }
1094
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
1095
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
1096
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
1097
+ url = URI.parse(corrected_url)
1098
+
1099
+ connection = Faraday.new(:url => url) do |faraday|
1100
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
1101
+ faraday.use :cookie_jar
1102
+ faraday.adapter Faraday.default_adapter
1103
+ end
1104
+ request_headers = Hash.new
1105
+
1106
+ # Set Headers
1107
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1108
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
1109
+
1110
+ unless custom_headers.nil?
1111
+ custom_headers.each do |key, value|
1112
+ request_headers[key] = value
1113
+ end
1114
+ end
1115
+
1116
+ # Send Request
1117
+ promise = Concurrent::Promise.new do
1118
+ connection.post do |request|
1119
+ request.headers = request_headers
1120
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
1121
+ end
1122
+ end
1123
+
1124
+ promise = promise.then do |http_response|
1125
+ status_code = http_response.status
1126
+ response_content = http_response.body
1127
+ unless (status_code == 202)
1128
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
1129
+ end
1130
+
1131
+ # Create Result
1132
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
1133
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1134
+
1135
+ result
1136
+ end
1137
+
1138
+ promise.execute
1139
+ end
1140
+
1141
+ #
1142
+ # The operation to start a virtual machine.
1143
+ # @param resource_group_name [String] The name of the resource group.
1144
+ # @param vm_name [String] The name of the virtual machine.
1145
+ # @return [Concurrent::Promise] promise which provides async access to http
1146
+ # response.
1147
+ #
1148
+ def start(resource_group_name, vm_name, custom_headers = nil)
1149
+ # Send request
1150
+ promise = begin_start(resource_group_name, vm_name, custom_headers)
1151
+
1152
+ promise = promise.then do |response|
1153
+ # Defining deserialization method.
1154
+ deserialize_method = lambda do |parsed_response|
1155
+ end
1156
+
1157
+ # Waiting for response.
1158
+ @client.get_post_or_delete_operation_result(response, nil, deserialize_method)
1159
+ end
1160
+
1161
+ promise
1162
+ end
1163
+
1164
+ #
1165
+ # The operation to start a virtual machine.
1166
+ # @param resource_group_name [String] The name of the resource group.
1167
+ # @param vm_name [String] The name of the virtual machine.
1168
+ # @param [Hash{String => String}] The hash of custom headers need to be
1169
+ # applied to HTTP request.
1170
+ #
1171
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
1172
+ # response.
1173
+ #
1174
+ def begin_start(resource_group_name, vm_name, custom_headers = nil)
1175
+ fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
1176
+ fail ArgumentError, 'vm_name is nil' if vm_name.nil?
1177
+ fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
1178
+ fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
1179
+ # Construct URL
1180
+ path = "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start"
1181
+ path['{resourceGroupName}'] = ERB::Util.url_encode(resource_group_name) if path.include?('{resourceGroupName}')
1182
+ path['{vmName}'] = ERB::Util.url_encode(vm_name) if path.include?('{vmName}')
1183
+ path['{subscriptionId}'] = ERB::Util.url_encode(@client.subscription_id) if path.include?('{subscriptionId}')
1184
+ url = URI.join(@client.base_url, path)
1185
+ properties = {}
1186
+ properties['api-version'] = ERB::Util.url_encode(@client.api_version.to_s) unless @client.api_version.nil?
1187
+ unless url.query.nil?
1188
+ url.query.split('&').each do |url_item|
1189
+ url_items_parts = url_item.split('=')
1190
+ properties[url_items_parts[0]] = url_items_parts[1]
1191
+ end
1192
+ end
1193
+ properties.reject!{ |key, value| value.nil? }
1194
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
1195
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
1196
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
1197
+ url = URI.parse(corrected_url)
1198
+
1199
+ connection = Faraday.new(:url => url) do |faraday|
1200
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
1201
+ faraday.use :cookie_jar
1202
+ faraday.adapter Faraday.default_adapter
1203
+ end
1204
+ request_headers = Hash.new
1205
+
1206
+ # Set Headers
1207
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1208
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
1209
+
1210
+ unless custom_headers.nil?
1211
+ custom_headers.each do |key, value|
1212
+ request_headers[key] = value
1213
+ end
1214
+ end
1215
+
1216
+ # Send Request
1217
+ promise = Concurrent::Promise.new do
1218
+ connection.post do |request|
1219
+ request.headers = request_headers
1220
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
1221
+ end
1222
+ end
1223
+
1224
+ promise = promise.then do |http_response|
1225
+ status_code = http_response.status
1226
+ response_content = http_response.body
1227
+ unless (status_code == 202)
1228
+ fail MsRestAzure::AzureOperationError.new(connection, http_response)
1229
+ end
1230
+
1231
+ # Create Result
1232
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
1233
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1234
+
1235
+ result
1236
+ end
1237
+
1238
+ promise.execute
1239
+ end
1240
+
1241
+ #
1242
+ # The operation to list virtual machines under a resource group.
1243
+ # @param next_page_link [String] The NextLink from the previous successful
1244
+ # call to List operation.
1245
+ # @param [Hash{String => String}] The hash of custom headers need to be
1246
+ # applied to HTTP request.
1247
+ #
1248
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
1249
+ # response.
1250
+ #
1251
+ def list_next(next_page_link, custom_headers = nil)
1252
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1253
+ # Construct URL
1254
+ path = "{nextLink}"
1255
+ path['{nextLink}'] = next_page_link if path.include?('{nextLink}')
1256
+ url = URI.parse(path)
1257
+ properties = {}
1258
+ unless url.query.nil?
1259
+ url.query.split('&').each do |url_item|
1260
+ url_items_parts = url_item.split('=')
1261
+ properties[url_items_parts[0]] = url_items_parts[1]
1262
+ end
1263
+ end
1264
+ properties.reject!{ |key, value| value.nil? }
1265
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
1266
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
1267
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
1268
+ url = URI.parse(corrected_url)
1269
+
1270
+ connection = Faraday.new(:url => url) do |faraday|
1271
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
1272
+ faraday.use :cookie_jar
1273
+ faraday.adapter Faraday.default_adapter
1274
+ end
1275
+ request_headers = Hash.new
1276
+
1277
+ # Set Headers
1278
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1279
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
1280
+
1281
+ unless custom_headers.nil?
1282
+ custom_headers.each do |key, value|
1283
+ request_headers[key] = value
1284
+ end
1285
+ end
1286
+
1287
+ # Send Request
1288
+ promise = Concurrent::Promise.new do
1289
+ connection.get do |request|
1290
+ request.headers = request_headers
1291
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
1292
+ end
1293
+ end
1294
+
1295
+ promise = promise.then do |http_response|
1296
+ status_code = http_response.status
1297
+ response_content = http_response.body
1298
+ unless (status_code == 200)
1299
+ error_model = JSON.load(response_content)
1300
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
1301
+ end
1302
+
1303
+ # Create Result
1304
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
1305
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1306
+ # Deserialize Response
1307
+ if status_code == 200
1308
+ begin
1309
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
1310
+ unless parsed_response.nil?
1311
+ parsed_response = VirtualMachineListResult.deserialize_object(parsed_response)
1312
+ end
1313
+ result.body = parsed_response
1314
+ rescue Exception => e
1315
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
1316
+ end
1317
+ end
1318
+
1319
+ result
1320
+ end
1321
+
1322
+ promise.execute
1323
+ end
1324
+
1325
+ #
1326
+ # Gets the list of Virtual Machines in the subscription. Use nextLink property
1327
+ # in the response to get the next page of Virtual Machines. Do this till
1328
+ # nextLink is not null to fetch all the Virtual Machines.
1329
+ # @param next_page_link [String] The NextLink from the previous successful
1330
+ # call to List operation.
1331
+ # @param [Hash{String => String}] The hash of custom headers need to be
1332
+ # applied to HTTP request.
1333
+ #
1334
+ # @return [Concurrent::Promise] Promise object which allows to get HTTP
1335
+ # response.
1336
+ #
1337
+ def list_all_next(next_page_link, custom_headers = nil)
1338
+ fail ArgumentError, 'next_page_link is nil' if next_page_link.nil?
1339
+ # Construct URL
1340
+ path = "{nextLink}"
1341
+ path['{nextLink}'] = next_page_link if path.include?('{nextLink}')
1342
+ url = URI.parse(path)
1343
+ properties = {}
1344
+ unless url.query.nil?
1345
+ url.query.split('&').each do |url_item|
1346
+ url_items_parts = url_item.split('=')
1347
+ properties[url_items_parts[0]] = url_items_parts[1]
1348
+ end
1349
+ end
1350
+ properties.reject!{ |key, value| value.nil? }
1351
+ url.query = properties.map{ |key, value| "#{key}=#{value}" }.compact.join('&')
1352
+ fail URI::Error unless url.to_s =~ /\A#{URI::regexp}\z/
1353
+ corrected_url = url.to_s.gsub(/([^:])\/\//, '\1/')
1354
+ url = URI.parse(corrected_url)
1355
+
1356
+ connection = Faraday.new(:url => url) do |faraday|
1357
+ faraday.use MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02
1358
+ faraday.use :cookie_jar
1359
+ faraday.adapter Faraday.default_adapter
1360
+ end
1361
+ request_headers = Hash.new
1362
+
1363
+ # Set Headers
1364
+ request_headers['x-ms-client-request-id'] = SecureRandom.uuid
1365
+ request_headers["accept-language"] = @client.accept_language unless @client.accept_language.nil?
1366
+
1367
+ unless custom_headers.nil?
1368
+ custom_headers.each do |key, value|
1369
+ request_headers[key] = value
1370
+ end
1371
+ end
1372
+
1373
+ # Send Request
1374
+ promise = Concurrent::Promise.new do
1375
+ connection.get do |request|
1376
+ request.headers = request_headers
1377
+ @client.credentials.sign_request(request) unless @client.credentials.nil?
1378
+ end
1379
+ end
1380
+
1381
+ promise = promise.then do |http_response|
1382
+ status_code = http_response.status
1383
+ response_content = http_response.body
1384
+ unless (status_code == 200)
1385
+ error_model = JSON.load(response_content)
1386
+ fail MsRestAzure::AzureOperationError.new(connection, http_response, error_model)
1387
+ end
1388
+
1389
+ # Create Result
1390
+ result = MsRestAzure::AzureOperationResponse.new(connection, http_response)
1391
+ result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
1392
+ # Deserialize Response
1393
+ if status_code == 200
1394
+ begin
1395
+ parsed_response = JSON.load(response_content) unless response_content.to_s.empty?
1396
+ unless parsed_response.nil?
1397
+ parsed_response = VirtualMachineListResult.deserialize_object(parsed_response)
1398
+ end
1399
+ result.body = parsed_response
1400
+ rescue Exception => e
1401
+ fail MsRest::DeserializationError.new("Error occured in deserializing the response", e.message, e.backtrace, response_content)
1402
+ end
1403
+ end
1404
+
1405
+ result
1406
+ end
1407
+
1408
+ promise.execute
1409
+ end
1410
+
1411
+ end
1412
+ end