azure-armrest 0.9.4 → 0.9.5

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
  SHA256:
3
- metadata.gz: 0c2605f1a0d6193e9bcd8f41512d64d29c70f12acbf56df23972c6c7659ee41c
4
- data.tar.gz: 747601d0bd5494f50b07473b86fddfdc20bc150b15906e7700f8438c638f30ce
3
+ metadata.gz: c36786918df641ad7cc61b96471a4fba6828c86af36751f3be841e2879111f1c
4
+ data.tar.gz: 28a4135e681858eeed8876c9e450faadc6f9d8b9a1eab97e16f1eee7d582fba6
5
5
  SHA512:
6
- metadata.gz: 998117ceb8031506e8569ec83988f880f9c3d841bd3b5a3ef8bd251f070554194eef8b10baa299b38cbd9b969b44f1dee3338aac0a8078975821cb184f86bb49
7
- data.tar.gz: 284cb6d3b7b30bce806784c424fe4fe7c89ed3d9fa1f9f63bbd69cc9b960835088b1a36451aabe0c0f25637b7d3d9b2482ed320a3b61756503355963340423f6
6
+ metadata.gz: 2fe855b4a36f5494538df99895e5022a0bca82ec42f3dbf06b906da516ba07bad27782aa986e6a545e151927c6f30933356c15e533e8b8954f31230b139a091b
7
+ data.tar.gz: a99277df03074b8169cf43c486b02f282c49888ec636a3ecb984dde9c21be6ed39a615b57d5ffc0ba1ff55dd189143d3e1340279e19f4a93982c61986c0f23b0
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ = 0.9.5 - 22-Jan-2018
2
+ * Fixed a bug in the exception handler for the StorageAccount#all_blobs
3
+ method and the StorageAccountService#get_private_images method.
4
+ * Added the Azure::Armrest::Storage::ManagedStorageHelper::ManagedDisk
5
+ class. This should now be the preferred approach for getting raw
6
+ blob information, as it is much more efficient.
7
+
1
8
  = 0.9.4 - 29-Nov-2017
2
9
  * Fixed the VirtualMachineService#delete_associated_resources to handle VM's
3
10
  backed by managed storage, as well as VM's with a private IP.
@@ -643,7 +643,7 @@ module Azure
643
643
  begin
644
644
  mutex.synchronize { array.concat(blobs(container.name_from_hash, key, options)) }
645
645
  rescue Errno::ECONNREFUSED, Azure::Armrest::TimeoutException => err
646
- msg = "Unable to gather blob information for #{container.name}: #{err}"
646
+ msg = "Unable to gather blob information for #{container.name_from_hash}: #{err}"
647
647
  Azure::Armrest::Configuration.log.try(:log, Logger::WARN, msg)
648
648
  next
649
649
  end
@@ -0,0 +1,43 @@
1
+ # Azure namespace
2
+ module Azure
3
+ # Armrest namespace
4
+ module Armrest
5
+ # Storage namespace
6
+ module Storage
7
+ # Base class for managing managed disks.
8
+ module ManagedStorageHelper
9
+ class ManagedDisk
10
+ def initialize(storage_service, disk_name, resource_group, options)
11
+ @storage_service = storage_service
12
+ @disk_name = disk_name
13
+ @resource_group = resource_group
14
+ @sas_url = storage_service.access_token(disk_name, resource_group, options)
15
+ end
16
+
17
+ def read(options = {})
18
+ retries = 0
19
+ begin
20
+ @storage_service.read(@sas_url, options)
21
+ rescue Azure::Armrest::ForbiddenException => err
22
+ raise err if retries.positive?
23
+ log('warn', "ManagedDisk.read: #{err} - getting new SAS URL")
24
+ begin
25
+ close
26
+ rescue => err
27
+ log('debug', "ManagedDisk.read: #{err} received on close ignored.")
28
+ end
29
+ @sas_url = @storage_service.access_token(@disk_name, @resource_group, options)
30
+ retries += 1
31
+ retry
32
+ end
33
+ end
34
+
35
+ def close
36
+ @storage_service.close(@disk_name, @resource_group)
37
+ @sas_url = nil
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,4 +1,5 @@
1
1
  module Azure::Armrest::Storage::ManagedStorageHelper
2
+ require_relative 'managed_disk'
2
3
  # Get the raw blob information for a managed disk. This is similar to
3
4
  # the StorageAccount#get_blob_raw method, but applies only to a managed
4
5
  # disk or its snapshot, whereas that method applies only to an individual storage
@@ -49,37 +50,12 @@ module Azure::Armrest::Storage::ManagedStorageHelper
49
50
  # p data.headers
50
51
  # File.open('vm.vhd', 'a'){ |fh| fh.write(data.body) }
51
52
  #
52
- def get_blob_raw(disk_name, resource_group = configuration.resource_group, options = {})
53
- validate_resource_group(resource_group)
54
-
55
- post_options = {
56
- :access => 'read', # Must be 'read'
57
- :durationInSeconds => options[:duration] || 3600 # 1 hour default
58
- }
59
-
60
- # This call will give us an operations URL in the headers.
61
- begin_get_access_url = build_url(resource_group, disk_name, 'BeginGetAccess')
62
- begin_get_access_response = rest_post(begin_get_access_url, post_options.to_json)
63
-
64
- headers = Azure::Armrest::ResponseHeaders.new(begin_get_access_response.headers)
65
- status = wait(headers, 120, 5)
66
-
67
- unless status.casecmp('succeeded').zero?
68
- msg = "Unable to obtain an operations URL for #{disk_name}/#{resource_group}"
69
- log('debug', "#{msg}: #{begin_get_access_response.headers}")
70
- raise Azure::Armrest::NotFoundException.new(begin_get_access_response.code, msg, begin_get_access_response.body)
71
- end
72
-
73
- # Get the SAS URL from the BeginGetAccess call
74
- op_url = headers.try(:azure_asyncoperation) || headers.location
75
-
76
- # Dig the URL + SAS token URL out of the response
77
- response = rest_get(op_url)
78
-
79
- body = Azure::Armrest::ResponseBody.new(response.body)
80
- sas_url = body.properties.output.access_sas
53
+ def open(disk_name, resource_group = configuration.resource_group, options = {})
54
+ ManagedDisk.new(self, disk_name, resource_group, options)
55
+ end
81
56
 
82
- # The same restrictions that apply to the StorageAccont method also apply here.
57
+ def read(sas_url, options = {})
58
+ # The same restrictions that apply to the StorageAccount method also apply here.
83
59
  range = options[:range] if options[:range]
84
60
  range ||= options[:start_byte]..options[:end_byte] if options[:start_byte] && options[:end_byte]
85
61
  range ||= options[:start_byte]..options[:start_byte] + options[:length] - 1 if options[:start_byte] && options[:length]
@@ -95,8 +71,8 @@ module Azure::Armrest::Storage::ManagedStorageHelper
95
71
 
96
72
  # Need to make a raw call since we need to explicitly pass headers,
97
73
  # but without encoding the URL or passing our configuration token.
98
- max_retries = 5
99
- retries = 0
74
+ max_retries = 5
75
+ retries = 0
100
76
 
101
77
  begin
102
78
  RestClient::Request.execute(
@@ -107,17 +83,59 @@ module Azure::Armrest::Storage::ManagedStorageHelper
107
83
  :ssl_version => configuration.ssl_version,
108
84
  :ssl_verify => configuration.ssl_verify
109
85
  )
86
+ rescue Azure::Armrest::ForbiddenException => err
87
+ log('warn', "ManagedStorageHelper.read: #{err}")
88
+ raise err
110
89
  rescue RestClient::Exception, Azure::Armrest::ForbiddenException => err
111
- retries += 1
112
90
  raise err unless retries < max_retries
113
- log('warn', "get_blob_raw: #{err} - retry number #{retries}")
91
+ log('warn', "ManagedStorageHelper.read: #{err} - retry number #{retries}")
92
+ retries += 1
114
93
  sleep 5
115
94
  retry
116
95
  end
117
- ensure
118
- if begin_get_access_response && status.casecmp('succeeded').zero?
119
- end_url = build_url(resource_group, disk_name, 'EndGetAccess')
120
- rest_post(end_url)
96
+ end
97
+
98
+ def close(disk_name, resource_group)
99
+ end_url = build_url(resource_group, disk_name, 'EndGetAccess')
100
+ rest_post(end_url)
101
+ end
102
+
103
+ def get_blob_raw(disk_name, resource_group = configuration.resource_group, options = {})
104
+ managed_disk = open(disk_name, resource_group, options)
105
+ begin
106
+ managed_disk.read(options)
107
+ ensure
108
+ managed_disk.close
109
+ end
110
+ end
111
+
112
+ def access_token(disk_name, resource_group = configuration.resource_group, options = {})
113
+ validate_resource_group(resource_group)
114
+
115
+ post_options = {
116
+ :access => 'read', # Must be 'read'
117
+ :durationInSeconds => options[:duration] || 3600 # 1 hour default
118
+ }
119
+
120
+ # This call will give us an operations URL in the headers.
121
+ begin_get_access_url = build_url(resource_group, disk_name, 'BeginGetAccess')
122
+ begin_get_access_response = rest_post(begin_get_access_url, post_options.to_json)
123
+
124
+ headers = Azure::Armrest::ResponseHeaders.new(begin_get_access_response.headers)
125
+ status = wait(headers, 120, 1)
126
+
127
+ unless status.casecmp('succeeded').zero?
128
+ msg = "Unable to obtain an operations URL for #{disk_name}/#{resource_group}"
129
+ log('debug', "#{msg}: #{begin_get_access_response.headers}")
130
+ raise Azure::Armrest::NotFoundException.new(begin_get_access_response.code, msg, begin_get_access_response.body)
121
131
  end
132
+
133
+ # Get the SAS URL from the BeginGetAccess call
134
+ op_url = headers.try(:azure_asyncoperation) || headers.location
135
+
136
+ # Dig the URL + SAS token URL out of the response
137
+ response = rest_get(op_url)
138
+ body = Azure::Armrest::ResponseBody.new(response.body)
139
+ body.properties.output.access_sas
122
140
  end
123
141
  end
@@ -296,7 +296,7 @@ module Azure
296
296
  :skip_accessors_definition => true
297
297
  )
298
298
  rescue Errno::ECONNREFUSED, Azure::Armrest::TimeoutException => err
299
- msg = "Unable to collect blob properties for #{blob.name}/#{blob.container}: #{err}"
299
+ msg = "Unable to collect blob properties for #{blob.name_from_hash}/#{blob.container_from_hash}: #{err}"
300
300
  log('warn', msg)
301
301
  next
302
302
  end
@@ -1,6 +1,6 @@
1
1
  module Azure
2
2
  module Armrest
3
3
  # The version of the azure-armrest library.
4
- VERSION = '0.9.4'.freeze
4
+ VERSION = '0.9.5'.freeze
5
5
  end
6
6
  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.9.4
4
+ version: 0.9.5
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: 2017-11-29 00:00:00.000000000 Z
14
+ date: 2018-01-22 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -261,6 +261,7 @@ files:
261
261
  - lib/azure/armrest/sql/sql_server_service.rb
262
262
  - lib/azure/armrest/storage/disk_service.rb
263
263
  - lib/azure/armrest/storage/image_service.rb
264
+ - lib/azure/armrest/storage/managed_disk.rb
264
265
  - lib/azure/armrest/storage/managed_storage_helper.rb
265
266
  - lib/azure/armrest/storage/snapshot_service.rb
266
267
  - lib/azure/armrest/storage_account_service.rb