azure-armrest 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/CHANGES +4 -0
- data/lib/azure/armrest/storage_account_service.rb +88 -43
- data/lib/azure/armrest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83cc9a600096d0ba6960803745720f3db623e035
|
4
|
+
data.tar.gz: 6dfc6c507bd13b8563c345c2c22a5076a0c4ab1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 622474a14751ccc15e669c3a0502e124fd3e2500d3e7889ef5f759b547852d78f0a14cd8bb6cc6977fd2936e40a2c72c4db82d438a32ddd7052df7fc55d692a3
|
7
|
+
data.tar.gz: 17440d8c5629a94c1f4e04a98046939537ffa8996a843dc7d2998796a6f76a3089434e79489b899d260589dc102c507188595bb937d233e80a3d010643f346be
|
data/.travis.yml
CHANGED
data/CHANGES
CHANGED
@@ -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
|
190
|
-
# storage accounts in the
|
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
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
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
|
-
|
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
|
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.
|
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-
|
14
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: json
|