azure-armrest 0.2.7 → 0.2.8

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: edf2ba291d6e30b9bbc4b1358d33fa0b0ab44203
4
- data.tar.gz: c4a444504dfe8e490a04166806d889d2b1a4426f
3
+ metadata.gz: 83cc9a600096d0ba6960803745720f3db623e035
4
+ data.tar.gz: 6dfc6c507bd13b8563c345c2c22a5076a0c4ab1e
5
5
  SHA512:
6
- metadata.gz: 8f3aefdf3b5d17a8e2226a8edbb4fa855f81c697038c5ea9b6d8f9e3df14a72fd93b99f9f6ef417e95455b2cab31572647d4443ae222a480ff41d28cac6a8211
7
- data.tar.gz: 977091814361c70170aca2bab6e8a889d0e8287ffd202285aa94cfb573cc2f92ab09d4ad8085d2eb4560073e37e009b8d787186c8235ff982db0464592a82e15
6
+ metadata.gz: 622474a14751ccc15e669c3a0502e124fd3e2500d3e7889ef5f759b547852d78f0a14cd8bb6cc6977fd2936e40a2c72c4db82d438a32ddd7052df7fc55d692a3
7
+ data.tar.gz: 17440d8c5629a94c1f4e04a98046939537ffa8996a843dc7d2998796a6f76a3089434e79489b899d260589dc102c507188595bb937d233e80a3d010643f346be
@@ -1,8 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "2.0"
4
- - "2.1"
5
- - "2.2"
3
+ - "2.2.5"
4
+ - "2.3.1"
6
5
  - ruby-head
7
6
  - jruby-head
8
7
  matrix:
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ = 0.2.8 - 22-Jul-2016
2
+ * Backported PR #188 (add list_all_private_images method).
3
+ * Backported PR #194 (updated .travis.yml).
4
+
1
5
  = 0.2.7 - 20-Jun-2016
2
6
  * All internal calls to rest-client are now explicitly URI.encode'd.
3
7
 
@@ -186,51 +186,35 @@ module Azure
186
186
 
187
187
  alias regenerate_storage_account_key_objects regenerate_account_key_objects
188
188
 
189
- # Returns a list of images that are available for provisioning for all
190
- # storage accounts in the provided resource group. The custom keys
191
- # :uri and :operating_system have been added for convenience.
189
+ # Returns a list of PrivateImage objects that are available for
190
+ # provisioning for all storage accounts in the current subscription.
192
191
  #
193
- def list_private_images(group = configuration.resource_group)
194
- results = []
195
- threads = []
196
- mutex = Mutex.new
197
-
198
- list(group).each do |lstorage_account|
199
- threads << Thread.new(lstorage_account) do |storage_account|
200
- if recent_api_version?
201
- key = list_account_key_objects(storage_account.name, group).first.key
202
- else
203
- key = list_account_keys(storage_account.name, group).fetch('key1')
204
- end
205
-
206
- storage_account.all_blobs(key).each do |blob|
207
- next unless File.extname(blob.name).downcase == '.vhd'
208
- next unless blob.properties.lease_state.downcase == 'available'
209
-
210
- blob_properties = storage_account.blob_properties(blob.container, blob.name, key)
211
- next unless blob_properties.respond_to?(:x_ms_meta_microsoftazurecompute_osstate)
212
- next unless blob_properties.x_ms_meta_microsoftazurecompute_osstate.downcase == 'generalized'
213
-
214
- mutex.synchronize do
215
- hash = blob.to_h.merge(
216
- :storage_account => storage_account.to_h,
217
- :blob_properties => blob_properties.to_h,
218
- :operating_system => blob_properties.try(:x_ms_meta_microsoftazurecompute_ostype),
219
- :uri => File.join(
220
- storage_account.properties.primary_endpoints.blob,
221
- blob.container,
222
- blob.name
223
- )
224
- )
225
- results << StorageAccount::PrivateImage.new(hash)
226
- end
227
- end
228
- end
229
- end
230
-
231
- threads.each(&:join)
192
+ # You may optionally reduce the set of storage accounts that will
193
+ # be scanned by providing a filter, where the keys are StorageAccount
194
+ # properties.
195
+ #
196
+ # Example:
197
+ #
198
+ # sas.list_all_private_images(:location => 'eastus', resource_group => 'some_group')
199
+ #
200
+ def list_all_private_images(filter = {})
201
+ storage_accounts = list_all.select { |acct| filter.all? { |k, v| acct.public_send(k) == v } }
202
+ get_private_images(storage_accounts)
203
+ end
232
204
 
233
- results.flatten
205
+ # Returns a list of PrivateImage objects that are available for
206
+ # provisioning for all storage accounts in the provided resource group.
207
+ #
208
+ # The custom keys :uri and :operating_system have been added to the
209
+ # resulting PrivateImage objects for convenience.
210
+ #
211
+ # Example:
212
+ #
213
+ # sas.list_private_images(your_resource_group)
214
+ #
215
+ def list_private_images(group = configuration.resource_group)
216
+ storage_accounts = list(group)
217
+ get_private_images(storage_accounts)
234
218
  end
235
219
 
236
220
  def accounts_by_name
@@ -267,6 +251,67 @@ module Azure
267
251
 
268
252
  private
269
253
 
254
+ # Given a list of StorageAccount objects, returns all private images
255
+ # within those accounts.
256
+ #
257
+ def get_private_images(storage_accounts)
258
+ results = []
259
+ threads = []
260
+ mutex = Mutex.new
261
+
262
+ storage_accounts.each do |lstorage_account|
263
+ threads << Thread.new(lstorage_account) do |storage_account|
264
+ key = get_account_key(storage_account)
265
+
266
+ storage_account.all_blobs(key).each do |blob|
267
+ next unless File.extname(blob.name).casecmp('.vhd') == 0
268
+ next unless blob.properties.lease_state.casecmp('available') == 0
269
+
270
+ blob_properties = storage_account.blob_properties(blob.container, blob.name, key)
271
+ next unless blob_properties.respond_to?(:x_ms_meta_microsoftazurecompute_osstate)
272
+ next unless blob_properties.x_ms_meta_microsoftazurecompute_osstate.casecmp('generalized') == 0
273
+
274
+ mutex.synchronize do
275
+ results << blob_to_private_image_object(storage_account, blob, blob_properties)
276
+ end
277
+ end
278
+ end
279
+ end
280
+
281
+ threads.each(&:join)
282
+
283
+ results
284
+ end
285
+
286
+ # Converts a StorageAccount::Blob object into a StorageAccount::PrivateImage
287
+ # object, which is a mix of Blob and StorageAccount properties.
288
+ #
289
+ def blob_to_private_image_object(storage_account, blob, blob_properties)
290
+ hash = blob.to_h.merge(
291
+ :storage_account => storage_account.to_h,
292
+ :blob_properties => blob_properties.to_h,
293
+ :operating_system => blob_properties.try(:x_ms_meta_microsoftazurecompute_ostype),
294
+ :uri => File.join(
295
+ storage_account.properties.primary_endpoints.blob,
296
+ blob.container,
297
+ blob.name
298
+ )
299
+ )
300
+
301
+ StorageAccount::PrivateImage.new(hash)
302
+ end
303
+
304
+ # Get the key for the given +storage_acct+ using the appropriate method
305
+ # depending on the api-version.
306
+ #
307
+ def get_account_key(storage_acct)
308
+ if recent_api_version?
309
+ list_account_key_objects(storage_acct.name, storage_acct.resource_group).first.key
310
+ else
311
+ list_account_keys(storage_acct.name, storage_acct.resource_group).fetch('key1')
312
+ end
313
+ end
314
+
270
315
  # Check to see if the api-version string is 2016-01-01 or later.
271
316
  def recent_api_version?
272
317
  Time.parse(api_version).utc >= Time.parse('2016-01-01').utc
@@ -1,5 +1,5 @@
1
1
  module Azure
2
2
  module Armrest
3
- VERSION = '0.2.7'.freeze
3
+ VERSION = '0.2.8'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: azure-armrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2016-06-20 00:00:00.000000000 Z
14
+ date: 2016-07-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json