azure-armrest 0.2.10 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f25780e2f0499b060cbe8353a4eeb53f99272b14
4
- data.tar.gz: c66aa4e9aa32d682b61469019bc146814b5cafc1
3
+ metadata.gz: d6e051e8b1aafc0e56dead25b4b049a1db77991d
4
+ data.tar.gz: 6cd67f1ba82fc44da524373ae20f68b6e0a29737
5
5
  SHA512:
6
- metadata.gz: b4890375ae51f3cf07499f02b39c07966578a6aa7b1f6d3e5c26e97d8a6a239969032659625b9704ee6e2919961407cf0185852422f096fa497b2139d99d6199
7
- data.tar.gz: 3938fb8f7187ee9a613feb36dfa22df415eb36300dad9e8fbc7cef441bdeb758403252e5ff3d545c6c04c4258e7eda60f326d823f85c6cc57380c82edbc684ff
6
+ metadata.gz: 2243372f9f4b26501539f91db5d91be939454c7608a6feee25d9addd8aae16239c986b76555286a1f19e384ce4fc7d77511701f30ae5104145b8da3003671bc2
7
+ data.tar.gz: c139739090ad6fa30c5e86e61197db7cf09c7695d79ad4ee6aa728281294653234728cb782542f7a0633b1deede6d10258107211d51588ff1afcc2964aa7ee03
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.2.5"
4
- - "2.3.1"
3
+ - "2.0"
4
+ - "2.1"
5
+ - "2.2"
5
6
  - ruby-head
6
7
  - jruby-head
7
8
  matrix:
data/CHANGES CHANGED
@@ -1,15 +1,21 @@
1
- = 0.2.10 - 15-Sep-2016
2
- * Backported PR #213 (skip over storage accounts that don't have keys).
3
-
4
- = 0.2.9 - 25-Aug-2016
5
- * Backported PR #211 (exception class updates and specs).
6
-
7
- = 0.2.8 - 22-Jul-2016
8
- * Backported PR #188 (add list_all_private_images method).
9
- * Backported PR #194 (updated .travis.yml).
1
+ = 0.3.0 - 28-Jun-2016
2
+ * The configuration handling has been moved into its own class called
3
+ Azure::Armrest::Configuration. You can call this explicitly using :new,
4
+ or you can still use ArmrestService.configure.
5
+ * The :subscription_id option for configuration is no longer optional.
6
+ The logic for automatically fetching the first active subscription ID
7
+ that could be found has been dropped.
8
+ * Added the Billing::UsageService class.
9
+ * Added a TooManyRequests exception.
10
+ * Added support for pretty_print.
11
+ * Added the addressable gem as a dependency, as it internally replaces
12
+ the uri standard library. Calls to rest-client are still encoded, but
13
+ now using Addressable::URI.
14
+ * StorageAccountService no longer does account type validation.
15
+ * Added the StorageAccountService#list_all_private_images method.
10
16
 
11
17
  = 0.2.7 - 20-Jun-2016
12
- * All internal calls to rest-client are now explicitly URI.encode'd.
18
+ * All internal calls to rest-client are now explicitly URI.encoded.
13
19
 
14
20
  = 0.2.6 - 9-May-2016
15
21
  * If no subscription is provided, the internal method for fetching a default
data/README.md CHANGED
@@ -18,7 +18,7 @@ require 'azure/armrest'
18
18
  #
19
19
  # A token will be retrieved based on the information you provided
20
20
 
21
- conf = Azure::Armrest::ArmrestService.configure(
21
+ conf = Azure::Armrest::Configuration.new(
22
22
  :client_id => 'XXXXX',
23
23
  :client_key => 'YYYYY',
24
24
  :tenant_id => 'ZZZZZ',
@@ -40,8 +40,9 @@ end
40
40
 
41
41
  ## Subscriptions
42
42
 
43
- If you do not provide a subscription ID in your configuration object, then the
44
- first subscription ID returned from a REST call will be used.
43
+ As of version 0.3.0 you must provide a subscription ID. In previous versions,
44
+ if you did not provide a subscription ID in your configuration object, then the
45
+ first subscription ID returned from a REST call would be used.
45
46
 
46
47
  ## Notes
47
48
 
@@ -25,6 +25,7 @@ behind the scenes.
25
25
  spec.add_dependency 'azure-signature', '~> 0.2.0'
26
26
  spec.add_dependency 'activesupport', '>= 1.2.0'
27
27
  spec.add_dependency 'nokogiri', '~> 1.6.0'
28
+ spec.add_dependency 'addressable', '~> 2.4.0'
28
29
 
29
30
  spec.add_development_dependency 'bundler'
30
31
  spec.add_development_dependency 'rake'
data/lib/azure/armrest.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rest-client'
2
2
  require 'json'
3
3
  require 'thread'
4
- require 'uri'
4
+ require 'addressable'
5
5
 
6
6
  # The Azure module serves as a namespace.
7
7
  module Azure
@@ -21,6 +21,7 @@ module Azure
21
21
  end
22
22
 
23
23
  require 'azure/armrest/version'
24
+ require 'azure/armrest/configuration'
24
25
  require 'azure/armrest/exception'
25
26
  require 'azure/armrest/armrest_collection'
26
27
  require 'azure/armrest/armrest_service'
@@ -48,6 +49,7 @@ require 'azure/armrest/role/assignment_service'
48
49
  require 'azure/armrest/role/definition_service'
49
50
  require 'azure/armrest/sql/sql_server_service'
50
51
  require 'azure/armrest/sql/sql_database_service'
52
+ require 'azure/armrest/billing/usage_service'
51
53
 
52
54
  # JSON wrapper classes. The service classes should require their own
53
55
  # wrappers from this point on.
@@ -5,61 +5,7 @@ module Azure
5
5
  module Armrest
6
6
  # Abstract base class for the other service classes.
7
7
  class ArmrestService
8
- ArmrestConfiguration = Struct.new(
9
- :client_id,
10
- :client_key,
11
- :tenant_id,
12
- :subscription_id,
13
- :resource_group,
14
- :api_version,
15
- :grant_type,
16
- :content_type,
17
- :accept,
18
- :token,
19
- :token_expiration, # token expiration local system date
20
- :proxy,
21
- :ssl_verify,
22
- :ssl_version
23
- ) do
24
- @@tokens = Hash.new([])
25
-
26
- def as_cache_key
27
- "#{grant_type}_#{tenant_id}_#{client_id}_#{client_key}"
28
- end
29
-
30
- def token
31
- self[:token], self[:token_expiration] = @@tokens[as_cache_key] if self[:token].nil?
32
-
33
- if self[:token].nil? || Time.now > (self[:token_expiration] || Time.new(0))
34
- self[:token], self[:token_expiration] = fetch_token
35
- end
36
- self[:token]
37
- end
38
-
39
- def fetch_token
40
- token_url = Azure::Armrest::AUTHORITY + tenant_id + "/oauth2/token"
41
-
42
- response = JSON.parse(
43
- ArmrestService.rest_post(
44
- :url => token_url,
45
- :proxy => proxy,
46
- :ssl_version => ssl_version,
47
- :ssl_verify => ssl_verify,
48
- :payload => {
49
- :grant_type => grant_type,
50
- :client_id => client_id,
51
- :client_secret => client_key,
52
- :resource => Azure::Armrest::RESOURCE
53
- }
54
- )
55
- )
56
-
57
- token = 'Bearer ' + response['access_token']
58
- @@tokens[as_cache_key] = [token, Time.now + response['expires_in'].to_i]
59
- end
60
-
61
- private :fetch_token
62
- end
8
+ extend Gem::Deprecate
63
9
 
64
10
  # Configuration to access azure APIs
65
11
  attr_accessor :armrest_configuration
@@ -69,161 +15,20 @@ module Azure
69
15
  # Base url used for REST calls.
70
16
  attr_accessor :base_url
71
17
 
72
- # provider for service specific API calls
18
+ # Provider for service specific API calls
73
19
  attr_accessor :provider
74
20
 
75
- # The api-version string used for each request.
21
+ # The api-version string for this particular service
76
22
  attr_accessor :api_version
77
23
 
78
- # The http proxy used for each request. Uses ENV['http_proxy'] if set.
79
- attr_accessor :proxy
80
-
81
- # The SSL verification method used for each request. The default is VERIFY_PEER.
82
- attr_accessor :ssl_verify
83
-
84
- # The SSL version used for each request. The default is TLSv1.
85
- attr_accessor :ssl_version
86
-
87
- # Clear class level caches.
88
- def self.clear_caches
89
- @@providers_hash = {} # Set in constructor
90
- @@tokens = {} # token caches
91
- @@subscriptions = {} # subscription caches
92
- end
93
-
94
- clear_caches
95
-
96
- # Create a configuration object based on input options.
97
- # This object can be used to create service objects.
98
- #
99
- # Possible options are:
100
- #
101
- # - client_id
102
- # - client_key
103
- # - tenant_id
104
- # - subscription_id
105
- # - resource_group
106
- # - api_version
107
- # - grant_type
108
- # - content_type
109
- # - accept
110
- # - token,
111
- # - token_expiration
112
- # - proxy
113
- # - ssl_verify
114
- # - ssl_version
115
- #
116
- # Of these, you should include a :client_id, :client_key and :tenant_id.
117
- # The resource_group can be specified here, but many methods allow you
118
- # to specify a resource group if you prefer flexibility.
119
- #
120
- # If no :subscription_id is provided then this method will attempt to find
121
- # a list of associated subscriptions and use the first one it finds as
122
- # the default. If no associated subscriptions are found, an ArgumentError
123
- # is raised.
124
- #
125
- # The other options (:grant_type, :content_type, :accept, :token,
126
- # :token_expiration and :api_version) should generally NOT be set by you
127
- # except in specific circumstances. Setting them explicitly will likely
128
- # cause breakage.
129
- #
130
- # The :token and :token_expiration options must be set in pair. The
131
- # :token_expiration should be set in local system time.
24
+ # Returns a new Armrest::Configuration object.
132
25
  #
133
- # The :api_version will typically be overridden on a per-provider/resource
134
- # basis within subclasses anyway.
135
- #
136
- # You may need to associate your application with a subscription using
137
- # the new portal or the New-AzureRoleAssignment powershell command.
26
+ # This method is deprecated, but is provided for backwards compatibility.
138
27
  #
139
28
  def self.configure(options)
140
- configuration = ArmrestConfiguration.new
141
-
142
- options.each do |k,v|
143
- configuration[k] = v
144
- end
145
-
146
- unless configuration.client_id && configuration.client_key
147
- raise ArgumentError, "client_id and client_key must be specified"
148
- end
149
-
150
- # Set default values for certain configuration items.
151
- configuration.api_version ||= '2015-01-01'
152
- configuration.grant_type ||= 'client_credentials'
153
- configuration.content_type ||= 'application/json'
154
- configuration.accept ||= 'application/json'
155
- configuration.proxy ||= ENV['http_proxy']
156
- configuration.ssl_version ||= 'TLSv1'
157
-
158
- # Allows for URI objects or Strings.
159
- configuration.proxy = configuration.proxy.to_s if configuration.proxy
160
-
161
- # After all other config options have been set, look for default subscription.
162
- configuration.subscription_id ||= fetch_subscription_id(configuration)
163
-
164
- configuration
165
- end
166
-
167
- # Find the first enabled subscription if one isn't provided or cached.
168
- #
169
- def self.fetch_subscription_id(config)
170
- return @@subscriptions[config.as_cache_key] if @@subscriptions.has_key?(config.as_cache_key)
171
-
172
- url = File.join(Azure::Armrest::RESOURCE, "subscriptions?api-version=#{config.api_version}")
173
-
174
- options = {
175
- :url => url,
176
- :proxy => config.proxy,
177
- :ssl_version => config.ssl_version,
178
- :ssl_verify => config.ssl_verify,
179
- :headers => {
180
- :content_type => config.content_type,
181
- :authorization => config.token
182
- }
183
- }
184
-
185
- response = rest_get(options)
186
- array = JSON.parse(response)['value']
187
-
188
- if array.nil? || array.empty?
189
- raise ArgumentError, "No associated subscription found"
190
- end
191
-
192
- results = []
193
-
194
- # Skip over any invalid subscriptions
195
- array.each do |sub_hash|
196
- sub_id = sub_hash['subscriptionId']
197
-
198
- # Use tagNames as a test URL
199
- test_url = File.join(
200
- Azure::Armrest::RESOURCE, 'subscriptions', sub_id,
201
- "tagNames?api-version=#{config.api_version}"
202
- )
203
-
204
- begin
205
- options[:url] = test_url
206
- rest_get(options)
207
- rescue Azure::Armrest::UnauthorizedException, Azure::Armrest::BadRequestException
208
- next
209
- else
210
- results << sub_hash
211
- break if sub_hash['state'] == 'Enabled'
212
- end
213
- end
214
-
215
- # Look for the first enabled subscription, otherwise just take the first subscription found.
216
- hash = results.find { |h| h['state'] == 'Enabled' } || results.first
217
-
218
- id = hash.fetch('subscriptionId')
219
-
220
- warn "Warning: subscription #{id} is not enabled" unless hash['state'] == 'Enabled'
221
-
222
- @@subscriptions[config.as_cache_key] = id
29
+ Azure::Armrest::Configuration.new(options)
223
30
  end
224
31
 
225
- private_class_method :fetch_subscription_id
226
-
227
32
  # Do not instantiate directly. This is an abstract base class from which
228
33
  # all other service classes should subclass, and call super within their
229
34
  # own constructors.
@@ -239,23 +44,27 @@ module Azure
239
44
  set_service_api_version(options, service_name)
240
45
  end
241
46
 
242
- # Returns a list of the available resource providers.
47
+ # Returns a list of the available resource providers. This is really
48
+ # just a wrapper for Azure::Armrest::Configuration#providers.
243
49
  #
244
- def providers
245
- url = url_with_api_version(configuration.api_version, @base_url, 'providers')
246
- resp = rest_get(url)
247
- JSON.parse(resp.body)["value"].map{ |hash| Azure::Armrest::ResourceProvider.new(hash) }
248
- end
50
+ delegate :providers, :to => :configuration, :prefix => :list
51
+
52
+ alias providers list_providers
53
+ deprecate :providers, :list_providers, 2018, 1
54
+
55
+ # Need an "as_cache_key" method for the cache_method library interface.
56
+ delegate :hash, :to => :configuration
57
+ alias as_cache_key hash
249
58
 
250
59
  # Returns information about the specific provider +namespace+.
251
60
  #
252
- def provider_info(provider)
253
- url = url_with_api_version(configuration.api_version, @base_url, 'providers', provider)
254
- response = rest_get(url)
255
- Azure::Armrest::ResourceProvider.new(response)
61
+ def get_provider(provider)
62
+ configuration.providers.find { |rp| rp.namespace.casecmp(provider) == 0 }
256
63
  end
257
64
 
258
- alias geo_locations provider_info
65
+ alias geo_locations get_provider
66
+ alias provider_info get_provider
67
+ deprecate :provider_info, :get_provider, 2018, 1
259
68
 
260
69
  # Returns a list of all locations for all resource types of the given
261
70
  # +provider+. If you do not specify a provider, then the locations for
@@ -266,26 +75,28 @@ module Azure
266
75
  #--
267
76
  #
268
77
  def locations(provider = nil)
269
- hash = provider.nil? ? @@providers_hash : {provider => @@providers_hash[provider.downcase]}
78
+ list = configuration.providers
79
+ list = list.select { |rp| rp.namespace.casecmp(provider) == 0 } if provider
270
80
 
271
- hash.collect do |_provider, provider_data|
272
- provider_data.collect { |_resource, resource_data| resource_data['locations'] }
273
- end.flatten.uniq
81
+ list.collect { |rp| rp.resource_types.map(&:locations) }.flatten.uniq.sort
274
82
  end
275
83
 
276
- # Returns a list of subscriptions for the tenant.
84
+ # Returns a list of Subscription objects for the tenant.
277
85
  #
278
- def subscriptions
86
+ def list_subscriptions
279
87
  url = url_with_api_version(configuration.api_version, @base_url, 'subscriptions')
280
88
  response = rest_get(url)
281
- JSON.parse(response.body)["value"].map{ |hash| Azure::Armrest::Subscription.new(hash) }
89
+ JSON.parse(response.body)['value'].map { |hash| Azure::Armrest::Subscription.new(hash) }
282
90
  end
283
91
 
92
+ alias subscriptions list_subscriptions
93
+ deprecate :subscriptions, :list_subscriptions, 2018, 1
94
+
284
95
  # Return information for the specified subscription ID, or the
285
96
  # subscription ID that was provided in the constructor if none is
286
97
  # specified.
287
98
  #
288
- def subscription_info(subscription_id = configuration.subscription_id)
99
+ def get_subscription(subscription_id = configuration.subscription_id)
289
100
  url = url_with_api_version(
290
101
  configuration.api_version,
291
102
  @base_url,
@@ -297,53 +108,33 @@ module Azure
297
108
  Azure::Armrest::Subscription.new(response.body)
298
109
  end
299
110
 
300
- # Returns a list of resources for the current subscription. If a
111
+ alias subscription_info get_subscription
112
+ deprecate :subscription_info, :get_subscription, 2018, 1
113
+
114
+ # Returns an array of Resource objects for the current subscription. If a
301
115
  # +resource_group+ is provided, only list resources for that
302
116
  # resource group.
303
117
  #
304
- def resources(resource_group = nil)
305
- url_comps = [@base_url, 'subscriptions', configuration.subscription_id]
306
- url_comps += ['resourcegroups', resource_group] if resource_group
307
- url_comps << 'resources'
308
-
309
- url = url_with_api_version(configuration.api_version, url_comps)
310
- response = rest_get(url)
311
-
312
- JSON.parse(response)["value"].map{ |hash| Azure::Armrest::Resource.new(hash) }
118
+ def list_resources(resource_group = nil)
119
+ if resource_group
120
+ Azure::Armrest::ResourceService.new(configuration).list(resource_group)
121
+ else
122
+ Azure::Armrest::ResourceService.new(configuration).list_all
123
+ end
313
124
  end
314
125
 
315
- # Returns a list of resource groups for the current subscription.
316
- #
317
- def resource_groups
318
- url = url_with_api_version(
319
- configuration.api_version,
320
- @base_url,
321
- 'subscriptions',
322
- configuration.subscription_id,
323
- 'resourcegroups'
324
- )
325
- response = rest_get(url)
326
- JSON.parse(response)["value"].map{ |hash| Azure::Armrest::ResourceGroup.new(hash) }
327
- end
126
+ alias resources list_resources
127
+ deprecate :resources, :list_resources, 2018, 1
328
128
 
329
- # Returns information on the specified +resource_group+ for the current
330
- # subscription, or the resource group specified in the constructor if
331
- # none is provided.
129
+ # Returns an array of ResourceGroup objects for the current subscription.
332
130
  #
333
- def resource_group_info(resource_group = configuration.resource_group)
334
- url = url_with_api_version(
335
- configuration.api_version,
336
- @base_url,
337
- 'subscriptions',
338
- configuration.subscription_id,
339
- 'resourcegroups',
340
- resource_group
341
- )
342
-
343
- response = rest_get(url)
344
- Azure::Armrest::ResourceGroup.new(response.body)
131
+ def list_resource_groups
132
+ Azure::Armrest::ResourceGroupService.new(configuration).list
345
133
  end
346
134
 
135
+ alias resource_groups list_resource_groups
136
+ deprecate :resource_groups, :list_resource_groups, 2018, 1
137
+
347
138
  # Returns a list of tags for the current subscription.
348
139
  #
349
140
  def tags
@@ -366,84 +157,74 @@ module Azure
366
157
  JSON.parse(resp.body)['value'].map{ |hash| Azure::Armrest::Tenant.new(hash) }
367
158
  end
368
159
 
369
- # The name of the file or handle used to log requests.
370
- #
371
- def self.log
372
- file = RestClient.log.instance_variable_get("@target_file")
373
- file || RestClient.log
374
- end
160
+ class << self
161
+ private
375
162
 
376
- # Sets the log to +output+, which can be a file or a handle.
377
- #
378
- def self.log=(output)
379
- RestClient.log = output
380
- end
381
-
382
- def self.rest_execute(options, http_method = :get)
383
- options = options.merge(
384
- :method => http_method,
385
- :url => URI.escape(options[:url])
386
- )
387
-
388
- RestClient::Request.execute(options)
389
- rescue RestClient::Exception => e
390
- raise_api_exception(e)
391
- end
163
+ def rest_execute(options, http_method = :get)
164
+ options = options.merge(
165
+ :method => http_method,
166
+ :url => Addressable::URI.escape(options[:url])
167
+ )
168
+ RestClient::Request.execute(options)
169
+ rescue RestClient::Exception => e
170
+ raise_api_exception(e)
171
+ end
392
172
 
393
- def self.rest_get(options)
394
- rest_execute(options, :get)
395
- end
173
+ def rest_get(options)
174
+ rest_execute(options, :get)
175
+ end
396
176
 
397
- def self.rest_post(options)
398
- rest_execute(options, :post)
399
- end
177
+ def rest_post(options)
178
+ rest_execute(options, :post)
179
+ end
400
180
 
401
- def self.rest_patch(options)
402
- rest_execute(options, :patch)
403
- end
181
+ def rest_patch(options)
182
+ rest_execute(options, :patch)
183
+ end
404
184
 
405
- def self.rest_delete(options)
406
- rest_execute(options, :delete)
407
- end
185
+ def rest_delete(options)
186
+ rest_execute(options, :delete)
187
+ end
408
188
 
409
- def self.rest_put(options)
410
- rest_execute(options, :put)
411
- end
189
+ def rest_put(options)
190
+ rest_execute(options, :put)
191
+ end
412
192
 
413
- def self.rest_head(options)
414
- rest_execute(options, :head)
415
- end
193
+ def rest_head(options)
194
+ rest_execute(options, :head)
195
+ end
416
196
 
417
- def self.raise_api_exception(e)
418
- begin
419
- response = JSON.parse(e.http_body)
420
- code = response['error']['code']
421
- message = response['error']['message']
422
- rescue
423
- message = e.http_body
197
+ def raise_api_exception(e)
198
+ begin
199
+ response = JSON.parse(e.http_body)
200
+ code = response['error']['code']
201
+ message = response['error']['message']
202
+ rescue
203
+ message = e.http_body
204
+ end
205
+ message = e.http_body unless message
206
+
207
+ exception_type = case e
208
+ when RestClient::NotFound
209
+ ResourceNotFoundException
210
+ when RestClient::BadRequest
211
+ BadRequestException
212
+ when RestClient::GatewayTimeout
213
+ GatewayTimeoutException
214
+ when RestClient::BadGateway
215
+ BadGatewayException
216
+ when RestClient::Unauthorized, RestClient::Forbidden
217
+ UnauthorizedException
218
+ when RestClient::TooManyRequests
219
+ TooManyRequestsException
220
+ else
221
+ ApiException
222
+ end
223
+
224
+ raise exception_type.new(code, message, e)
424
225
  end
425
- message = e.http_body unless message
426
-
427
- exception_type = case e
428
- when RestClient::NotFound
429
- ResourceNotFoundException
430
- when RestClient::BadRequest
431
- BadRequestException
432
- when RestClient::GatewayTimeout
433
- GatewayTimeoutException
434
- when RestClient::BadGateway
435
- BadGatewayException
436
- when RestClient::Unauthorized, RestClient::Forbidden
437
- UnauthorizedException
438
- else
439
- ApiException
440
- end
441
-
442
- raise exception_type.new(code, message, e)
443
226
  end
444
227
 
445
- private_class_method :raise_api_exception
446
-
447
228
  private
448
229
 
449
230
  # REST verb methods
@@ -463,7 +244,7 @@ module Azure
463
244
 
464
245
  options[:payload] = body if body
465
246
 
466
- self.class.rest_execute(options, http_method)
247
+ self.class.send(:rest_execute, options, http_method)
467
248
  end
468
249
 
469
250
  def rest_get(url)
@@ -495,35 +276,6 @@ module Azure
495
276
  File.join(*paths) << "?api-version=#{api_version}"
496
277
  end
497
278
 
498
- # Build a one-time lookup table for each provider & resource. This
499
- # lets subclasses set api-version strings properly for each method
500
- # depending on whichever provider they're using.
501
- #
502
- # e.g. @@providers_hash['Microsoft.Compute']['virtualMachines']['api_version']
503
- #
504
- # Note that for methods that don't depend on a resource type should use
505
- # armrest_configuration.api_version instead or set it explicitly as needed.
506
- #
507
- def set_providers_info
508
- return unless @@providers_hash.empty?
509
-
510
- providers.each do |info|
511
- provider_info = {}
512
- info.resource_types.each do |resource|
513
- provider_info[resource.resource_type.downcase] = {
514
- 'api_version' => resource.api_versions.reject{ |version|
515
- version =~ /preview/i || Time.parse(version) > Time.now
516
- }.first,
517
- 'locations' => resource.locations - [''] # Ignore empty elements
518
- }
519
- end
520
- # TODO: how does base model handle method naming collision?
521
- # rename or access through hash?
522
- # namespace is a method introduced by more_core_extensions
523
- @@providers_hash[info['namespace'].downcase] = provider_info
524
- end
525
- end
526
-
527
279
  # Each Azure API call may require different api_version.
528
280
  # The api_version in armrest_configuration is used for common methods provided
529
281
  # by ArmrestService
@@ -532,20 +284,15 @@ module Azure
532
284
  # api_version => version
533
285
  # This version will be used for the service specific API calls
534
286
  #
535
- # Otherwise the service specific api_version is looked up from @@providers_hash
287
+ # Otherwise the service specific api_version is looked up from configuration.providers
536
288
  #
537
289
  # Finally api_version in armrest_configuration is used if service specific version
538
290
  # cannot be determined
539
291
  def set_service_api_version(options, service)
540
- set_providers_info
541
292
  @api_version =
542
- if options.has_key?('api_version')
543
- options['api_version']
544
- elsif @@providers_hash.has_key?(provider.downcase)
545
- @@providers_hash[provider.downcase][service.downcase]['api_version']
546
- else
547
- configuration.api_version
548
- end
293
+ options['api_version'] ||
294
+ configuration.provider_default_api_version(provider, service) ||
295
+ configuration.api_version
549
296
  end
550
297
 
551
298
  # Parse the skip token value out of the nextLink attribute from a response.