azure-armrest 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +19 -0
- data/azure-armrest.gemspec +10 -7
- data/lib/azure/armrest.rb +2 -1
- data/lib/azure/armrest/armrest_service.rb +84 -25
- data/lib/azure/armrest/availability_set_service.rb +6 -82
- data/lib/azure/armrest/exception.rb +45 -0
- data/lib/azure/armrest/model/base_model.rb +54 -31
- data/lib/azure/armrest/model/storage_account.rb +140 -0
- data/lib/azure/armrest/network/ip_address_service.rb +5 -82
- data/lib/azure/armrest/network/network_interface_service.rb +3 -110
- data/lib/azure/armrest/network/network_security_group_service.rb +3 -82
- data/lib/azure/armrest/network/subnet_service.rb +14 -29
- data/lib/azure/armrest/network/virtual_network_service.rb +3 -100
- data/lib/azure/armrest/resource_group_based_service.rb +94 -0
- data/lib/azure/armrest/resource_group_service.rb +3 -3
- data/lib/azure/armrest/resource_provider_service.rb +4 -4
- data/lib/azure/armrest/resource_service.rb +1 -1
- data/lib/azure/armrest/storage_account_service.rb +35 -139
- data/lib/azure/armrest/template_deployment_service.rb +34 -87
- data/lib/azure/armrest/version.rb +1 -1
- data/lib/azure/armrest/virtual_machine_extension_service.rb +109 -35
- data/lib/azure/armrest/virtual_machine_service.rb +30 -187
- metadata +51 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90de5f291ba5efea0f715c848e05dcaecf52110d
|
4
|
+
data.tar.gz: c30be8f74ef00dfe99f069eac51bbed61644ff00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1e1f5f15e417fe74e275bad5ca0becd7b762022bcab8eb5ad526c9cb6776760ee7d32fdc72cd6c6dbee9c11ff1c8a6dfab28c57e719db9ed97c70fb3b245646
|
7
|
+
data.tar.gz: 9cabb2b1274e5ff5474675cd18cb7ee959cd0508719bf553dd7944b498f3fb9eddc36728cab8b9ce7e7fe7f6349d6f281d331f263b20e33a72638299ed1956b9
|
data/CHANGES
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
= 0.0.4 - 19-Oct-2015
|
2
|
+
* All get/list/list_all methods now return wrapper class instances, e.g.
|
3
|
+
a call to VirtualMachineService#get will return a VirtualMachine instance.
|
4
|
+
These provide a nice OpenStruct wrapper so you can use methods instead
|
5
|
+
of hash references if desired.
|
6
|
+
* A custom StorageAccount class was added that implements methods for
|
7
|
+
gathering blob information.
|
8
|
+
* Most service classes now inherit from ResourceGroupBasedService, which
|
9
|
+
provides a common set of methods typically used for various services.
|
10
|
+
* Now re-raises RestClient exceptions as exceptions that we have defined.
|
11
|
+
* The VirtualMachineImage class was overhauled and is now working properly.
|
12
|
+
* The azure-signature, nokogiri and activesupport dependencies were added.
|
13
|
+
|
14
|
+
= 0.0.3 - 13-Oct-2015
|
15
|
+
* Bug fixes for VirtualMachineImageService class.
|
16
|
+
* Reorganized and updated SubnetService class.
|
17
|
+
* Some updates to the BaseModel in prep for JSON wrapper classes.
|
18
|
+
* Added NetworkSecurityGroupService and IpAddressService classes.
|
19
|
+
|
1
20
|
= 0.0.2 - 23-Sep-2015
|
2
21
|
* Revamped class names. Now use "Service" instead of "Manager".
|
3
22
|
* Several new service classes added, updated, and refactored.
|
data/azure-armrest.gemspec
CHANGED
@@ -20,12 +20,15 @@ behind the scenes.
|
|
20
20
|
EOF
|
21
21
|
|
22
22
|
spec.add_dependency 'json'
|
23
|
-
spec.add_dependency 'rest-client'
|
24
|
-
spec.add_dependency 'cache_method',
|
23
|
+
spec.add_dependency 'rest-client', '=2.0.0.rc1'
|
24
|
+
spec.add_dependency 'cache_method', '~> 0.2.7'
|
25
|
+
spec.add_dependency 'azure-signature', '~> 0.2.0'
|
26
|
+
spec.add_dependency 'activesupport', '>= 1.2.0'
|
27
|
+
spec.add_dependency 'nokogiri', '~> 1.6.0'
|
25
28
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
29
|
+
spec.add_development_dependency 'bundler'
|
30
|
+
spec.add_development_dependency 'rake'
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
33
|
+
spec.add_development_dependency 'timecop', '~> 0.7'
|
31
34
|
end
|
data/lib/azure/armrest.rb
CHANGED
@@ -18,11 +18,12 @@ module Azure
|
|
18
18
|
# A common URI for all subclasses
|
19
19
|
COMMON_URI = RESOURCE + "subscriptions/"
|
20
20
|
end
|
21
|
-
|
22
21
|
end
|
23
22
|
|
24
23
|
require 'azure/armrest/version'
|
24
|
+
require 'azure/armrest/exception'
|
25
25
|
require 'azure/armrest/armrest_service'
|
26
|
+
require 'azure/armrest/resource_group_based_service'
|
26
27
|
require 'azure/armrest/storage_account_service'
|
27
28
|
require 'azure/armrest/availability_set_service'
|
28
29
|
require 'azure/armrest/virtual_machine_service'
|
@@ -35,7 +35,7 @@ module Azure
|
|
35
35
|
def fetch_token
|
36
36
|
token_url = Azure::Armrest::AUTHORITY + tenant_id + "/oauth2/token"
|
37
37
|
|
38
|
-
response = JSON.parse(
|
38
|
+
response = JSON.parse(ArmrestService.rest_post(
|
39
39
|
token_url,
|
40
40
|
:grant_type => grant_type,
|
41
41
|
:client_id => client_id,
|
@@ -123,7 +123,7 @@ module Azure
|
|
123
123
|
|
124
124
|
url = File.join(Azure::Armrest::RESOURCE, "subscriptions?api-version=#{config.api_version}")
|
125
125
|
|
126
|
-
response =
|
126
|
+
response = rest_get(
|
127
127
|
url,
|
128
128
|
:content_type => config.content_type,
|
129
129
|
:authorization => config.token
|
@@ -157,7 +157,7 @@ module Azure
|
|
157
157
|
def providers
|
158
158
|
url = url_with_api_version(armrest_configuration.api_version, @base_url, 'providers')
|
159
159
|
resp = rest_get(url)
|
160
|
-
JSON.parse(resp.body)["value"]
|
160
|
+
JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::ResourceProvider.new(hash) }
|
161
161
|
end
|
162
162
|
|
163
163
|
# Returns information about the specific provider +namespace+.
|
@@ -165,7 +165,7 @@ module Azure
|
|
165
165
|
def provider_info(provider)
|
166
166
|
url = url_with_api_version(armrest_configuration.api_version, @base_url, 'providers', provider)
|
167
167
|
response = rest_get(url)
|
168
|
-
|
168
|
+
Azure::Armrest::ResourceProvider.new(response)
|
169
169
|
end
|
170
170
|
|
171
171
|
alias geo_locations provider_info
|
@@ -190,8 +190,8 @@ module Azure
|
|
190
190
|
#
|
191
191
|
def subscriptions
|
192
192
|
url = url_with_api_version(armrest_configuration.api_version, @base_url, 'subscriptions')
|
193
|
-
|
194
|
-
JSON.parse(
|
193
|
+
response = rest_get(url)
|
194
|
+
JSON.parse(response.body)["value"].map{ |hash| Azure::Armrest::Subscription.new(hash) }
|
195
195
|
end
|
196
196
|
|
197
197
|
# Return information for the specified subscription ID, or the
|
@@ -206,8 +206,8 @@ module Azure
|
|
206
206
|
armrest_configuration.subscription_id
|
207
207
|
)
|
208
208
|
|
209
|
-
|
210
|
-
|
209
|
+
response = rest_get(url)
|
210
|
+
Azure::Armrest::Subscription.new(response.body)
|
211
211
|
end
|
212
212
|
|
213
213
|
# Returns a list of resources for the current subscription. If a
|
@@ -222,7 +222,7 @@ module Azure
|
|
222
222
|
url = url_with_api_version(armrest_configuration.api_version, url_comps)
|
223
223
|
response = rest_get(url)
|
224
224
|
|
225
|
-
JSON.parse(response
|
225
|
+
JSON.parse(response)["value"].map{ |hash| Azure::Armrest::Resource.new(hash) }
|
226
226
|
end
|
227
227
|
|
228
228
|
# Returns a list of resource groups for the current subscription.
|
@@ -236,14 +236,14 @@ module Azure
|
|
236
236
|
'resourcegroups'
|
237
237
|
)
|
238
238
|
response = rest_get(url)
|
239
|
-
JSON.parse(response
|
239
|
+
JSON.parse(response)["value"].map{ |hash| Azure::Armrest::ResourceGroup.new(hash) }
|
240
240
|
end
|
241
241
|
|
242
242
|
# Returns information on the specified +resource_group+ for the current
|
243
243
|
# subscription, or the resource group specified in the constructor if
|
244
244
|
# none is provided.
|
245
245
|
#
|
246
|
-
def resource_group_info(resource_group)
|
246
|
+
def resource_group_info(resource_group = armrest_configuration.resource_group)
|
247
247
|
url = url_with_api_version(
|
248
248
|
armrest_configuration.api_version,
|
249
249
|
@base_url,
|
@@ -253,8 +253,8 @@ module Azure
|
|
253
253
|
resource_group
|
254
254
|
)
|
255
255
|
|
256
|
-
|
257
|
-
|
256
|
+
response = rest_get(url)
|
257
|
+
Azure::Armrest::ResourceGroup.new(response.body)
|
258
258
|
end
|
259
259
|
|
260
260
|
# Returns a list of tags for the current subscription.
|
@@ -268,7 +268,7 @@ module Azure
|
|
268
268
|
'tagNames'
|
269
269
|
)
|
270
270
|
resp = rest_get(url)
|
271
|
-
JSON.parse(resp.body)["value"]
|
271
|
+
JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::Tag.new(hash) }
|
272
272
|
end
|
273
273
|
|
274
274
|
# Returns a list of tenants that can be accessed.
|
@@ -276,15 +276,74 @@ module Azure
|
|
276
276
|
def tenants
|
277
277
|
url = url_with_api_version(armrest_configuration.api_version, @base_url, 'tenants')
|
278
278
|
resp = rest_get(url)
|
279
|
-
JSON.parse(resp.body)
|
279
|
+
JSON.parse(resp.body)['value'].map{ |hash| Azure::Armrest::Tenant.new(hash) }
|
280
|
+
end
|
281
|
+
|
282
|
+
def self.rest_get(url, headers = {})
|
283
|
+
RestClient.get(url, headers)
|
284
|
+
rescue RestClient::Exception => e
|
285
|
+
raise_api_exception(e)
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.rest_post(url, body, headers = {})
|
289
|
+
RestClient.post(url, body, headers)
|
290
|
+
rescue RestClient::Exception => e
|
291
|
+
raise_api_exception(e)
|
292
|
+
end
|
293
|
+
|
294
|
+
def self.rest_patch(url, body, headers = {})
|
295
|
+
RestClient.patch(url, body, headers)
|
296
|
+
rescue RestClient::Exception => e
|
297
|
+
raise_api_exception(e)
|
298
|
+
end
|
299
|
+
|
300
|
+
def self.rest_delete(url, headers = {})
|
301
|
+
RestClient.delete(url, headers)
|
302
|
+
rescue RestClient::Exception => e
|
303
|
+
raise_api_exception(e)
|
304
|
+
end
|
305
|
+
|
306
|
+
def self.rest_put(url, body, headers = {})
|
307
|
+
RestClient.put(url, body, headers)
|
308
|
+
rescue RestClient::Exception => e
|
309
|
+
raise_api_exception(e)
|
310
|
+
end
|
311
|
+
|
312
|
+
def self.raise_api_exception(e)
|
313
|
+
begin
|
314
|
+
response = JSON.parse(e.http_body)
|
315
|
+
code = response.fetch_path('error', 'code')
|
316
|
+
message = response.fetch_path('error', 'message')
|
317
|
+
rescue
|
318
|
+
message = e.http_body
|
319
|
+
end
|
320
|
+
message = e.http_body unless message
|
321
|
+
|
322
|
+
exception_type = case e
|
323
|
+
when RestClient::NotFound
|
324
|
+
ResourceNotFoundException
|
325
|
+
when RestClient::BadRequest
|
326
|
+
BadRequestException
|
327
|
+
when RestClient::GatewayTimeout
|
328
|
+
GatewayTimeoutException
|
329
|
+
when RestClient::BadGateway
|
330
|
+
BadGatewayException
|
331
|
+
when RestClient::Unauthorized
|
332
|
+
UnauthorizedException
|
333
|
+
else
|
334
|
+
ApiException
|
335
|
+
end
|
336
|
+
|
337
|
+
raise exception_type.new(code, message, e)
|
280
338
|
end
|
339
|
+
private_class_method :raise_api_exception
|
281
340
|
|
282
341
|
private
|
283
342
|
|
284
343
|
# REST verb methods
|
285
344
|
|
286
345
|
def rest_get(url)
|
287
|
-
|
346
|
+
self.class.rest_get(
|
288
347
|
url,
|
289
348
|
:accept => armrest_configuration.accept,
|
290
349
|
:content_type => armrest_configuration.content_type,
|
@@ -293,7 +352,7 @@ module Azure
|
|
293
352
|
end
|
294
353
|
|
295
354
|
def rest_put(url, body = '')
|
296
|
-
|
355
|
+
self.class.rest_put(
|
297
356
|
url,
|
298
357
|
body,
|
299
358
|
:accept => armrest_configuration.accept,
|
@@ -303,7 +362,7 @@ module Azure
|
|
303
362
|
end
|
304
363
|
|
305
364
|
def rest_post(url, body = '')
|
306
|
-
|
365
|
+
self.class.rest_post(
|
307
366
|
url,
|
308
367
|
body,
|
309
368
|
:accept => armrest_configuration.accept,
|
@@ -313,7 +372,7 @@ module Azure
|
|
313
372
|
end
|
314
373
|
|
315
374
|
def rest_patch(url, body = '')
|
316
|
-
|
375
|
+
self.class.rest_patch(
|
317
376
|
url,
|
318
377
|
body,
|
319
378
|
:accept => armrest_configuration.accept,
|
@@ -323,7 +382,7 @@ module Azure
|
|
323
382
|
end
|
324
383
|
|
325
384
|
def rest_delete(url)
|
326
|
-
|
385
|
+
self.class.rest_delete(
|
327
386
|
url,
|
328
387
|
:accept => armrest_configuration.accept,
|
329
388
|
:content_type => armrest_configuration.content_type,
|
@@ -350,13 +409,13 @@ module Azure
|
|
350
409
|
|
351
410
|
providers.each do |info|
|
352
411
|
provider_info = {}
|
353
|
-
info
|
354
|
-
provider_info[resource
|
355
|
-
'api_version' => resource
|
356
|
-
'locations' => resource
|
412
|
+
info.resource_types.each do |resource|
|
413
|
+
provider_info[resource.resource_type] = {
|
414
|
+
'api_version' => resource.api_versions.first,
|
415
|
+
'locations' => resource.locations - [''] # Ignore empty elements
|
357
416
|
}
|
358
417
|
end
|
359
|
-
@@providers_hash[info
|
418
|
+
@@providers_hash[info.namespace.downcase] = provider_info
|
360
419
|
end
|
361
420
|
end
|
362
421
|
|
@@ -3,97 +3,21 @@ module Azure
|
|
3
3
|
# Armrest namespace
|
4
4
|
module Armrest
|
5
5
|
# Base class for managing availability sets.
|
6
|
-
class AvailabilitySetService <
|
7
|
-
# The provider used in requests when gathering
|
6
|
+
class AvailabilitySetService < ResourceGroupBasedService
|
7
|
+
# The provider used in requests when gathering AvailabilitySet information.
|
8
8
|
attr_reader :provider
|
9
9
|
|
10
|
-
# Create and return a new AvailabilitySetService
|
10
|
+
# Create and return a new AvailabilitySetService instance.
|
11
11
|
#
|
12
12
|
def initialize(_armrest_configuration, options = {})
|
13
13
|
super
|
14
|
-
|
15
14
|
@provider = options[:provider] || 'Microsoft.Compute'
|
16
|
-
|
17
15
|
set_service_api_version(options, 'availabilitySets')
|
16
|
+
@service_name = 'availabilitySets'
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
23
|
-
def create(name, location, tags = nil, resource_group = armrest_configuration.resource_group)
|
24
|
-
raise ArgumentError, "No resource group specified" if resource_group.nil?
|
25
|
-
|
26
|
-
url = build_url(resource_group, name)
|
27
|
-
body = {:name => name, :location => location, :tags => tags}.to_json
|
28
|
-
response = rest_put(url, body)
|
29
|
-
response.return!
|
30
|
-
end
|
31
|
-
|
32
|
-
alias update create
|
33
|
-
|
34
|
-
# Deletes the +name+ availability set.
|
35
|
-
#
|
36
|
-
def delete(name, resource_group = armrest_configuration.resource_group)
|
37
|
-
raise ArgumentError, "No resource group specified" if resource_group.nil?
|
38
|
-
url = build_url(resource_group, name)
|
39
|
-
response = rest_delete(url)
|
40
|
-
response.return!
|
41
|
-
end
|
42
|
-
|
43
|
-
# Retrieves the options of an availability set +name+.
|
44
|
-
#
|
45
|
-
def get(name, resource_group = armrest_configuration.resource_group)
|
46
|
-
raise ArgumentError, "No resource group specified" if resource_group.nil?
|
47
|
-
url = build_url(resource_group, name)
|
48
|
-
response = rest_get(url)
|
49
|
-
JSON.parse(response.body)
|
50
|
-
end
|
51
|
-
|
52
|
-
# List availability sets.
|
53
|
-
#
|
54
|
-
def list(resource_group = armrest_configuration.resource_group)
|
55
|
-
array = []
|
56
|
-
|
57
|
-
if resource_group
|
58
|
-
url = build_url(resource_group)
|
59
|
-
response = rest_get(url)
|
60
|
-
array << JSON.parse(response.body)['value']
|
61
|
-
else
|
62
|
-
threads = []
|
63
|
-
mutex = Mutex.new
|
64
|
-
|
65
|
-
resource_groups.each do |group|
|
66
|
-
url = build_url(group['name'])
|
67
|
-
|
68
|
-
threads << Thread.new(url) do |thread_url|
|
69
|
-
response = rest_get(thread_url)
|
70
|
-
result = JSON.parse(response)['value']
|
71
|
-
mutex.synchronize{ array << result if result }
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
threads.each(&:join)
|
76
|
-
end
|
77
|
-
|
78
|
-
array.flatten
|
79
|
-
end
|
80
|
-
|
81
|
-
# Builds a URL based on subscription_id an resource_group and any other
|
82
|
-
# arguments provided, and appends it with the api_version.
|
83
|
-
#
|
84
|
-
def build_url(resource_group, *args)
|
85
|
-
url = File.join(
|
86
|
-
Azure::Armrest::COMMON_URI,
|
87
|
-
armrest_configuration.subscription_id,
|
88
|
-
'resourceGroups',
|
89
|
-
resource_group,
|
90
|
-
'providers',
|
91
|
-
@provider,
|
92
|
-
'availabilitySets',
|
93
|
-
)
|
94
|
-
|
95
|
-
url = File.join(url, *args) unless args.empty?
|
96
|
-
url << "?api-version=#{@api_version}"
|
19
|
+
def list_all
|
20
|
+
list_in_all_groups
|
97
21
|
end
|
98
22
|
end # AvailabilitySetService
|
99
23
|
end # Armrest
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Azure
|
2
|
+
module Armrest
|
3
|
+
class Exception < StandardError
|
4
|
+
attr_accessor :cause
|
5
|
+
attr_writer :message
|
6
|
+
|
7
|
+
def initialize(message = nil, cause_exception = nil)
|
8
|
+
@message = message
|
9
|
+
@cause = cause_exception
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
message
|
14
|
+
end
|
15
|
+
|
16
|
+
def message
|
17
|
+
@message || self.class.name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ApiException < Exception
|
22
|
+
attr_accessor :code
|
23
|
+
|
24
|
+
def initialize(code, message, cause_exception)
|
25
|
+
@code = code
|
26
|
+
super(message, cause_exception)
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"[#{code}] #{message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ResourceNotFoundException < ApiException; end
|
35
|
+
|
36
|
+
class BadRequestException < ApiException; end
|
37
|
+
|
38
|
+
class UnauthorizedException < ApiException; end
|
39
|
+
|
40
|
+
class BadGatewayException < ApiException; end
|
41
|
+
|
42
|
+
class GatewayTimeoutException < ApiException; end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|