azure-armrest 0.7.1 → 0.7.2

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: dfb476a69524cfa20ac1f7c335d51769690c70bf
4
- data.tar.gz: 7a510d8b6bde252f48c7093a5792b803e2f85c1e
3
+ metadata.gz: 39ae852a7c1d574a83dde09cd448745e2e881388
4
+ data.tar.gz: 48c5a7219743e3b5aea2c0ca8270c7a26d9c1be2
5
5
  SHA512:
6
- metadata.gz: aef27b70c4520effac1e4749557f00ddda5e49d799d3465a134a073e68e99a991449bc4859bc2eda0a417f5c74e27f6e6edcf01fb786833f41130a3cec81a29a
7
- data.tar.gz: 82350ce82f0663e53b5fe002274b662a0e6b009500c367ea2dec679e6d17f61e8b8f707257f05d996caa6651af9d681474e696c2a0889316b3cf61176fe50173
6
+ metadata.gz: b368e813ee681505fa2d3e5bf7d53fc86a14a410d72b00208645886e3b6c98c903d67ea5669ea96ef73dc574aa2c42ea349474eaee2e25cb482e16eb72e93884
7
+ data.tar.gz: 56abea12095d06f948eda3c6fae8bf778bede353ecdfa4df2d331d34b64e3a9b275c767bad45f7788b1c237edc44cafbd76aae837d0f881549a470c65fbd0cdf
data/CHANGES CHANGED
@@ -1,3 +1,9 @@
1
+ = 0.7.2 - 26-Apr-2017
2
+ * Added the Storage::DiskService#get_blob_raw method. This is similar to the
3
+ StorageAccount#get_blob_raw method, but works for managed disks.
4
+ * Added the :managed_disk?, :size (alias :flavor) and :operating_system
5
+ (alias :os) methods to the VirtualMachine model for convenience.
6
+
1
7
  = 0.7.1 - 11-Apr-2017
2
8
  * Fixed a bug in the BaseModel#to_json method. It now handles arrays of
3
9
  model objects properly.
@@ -196,6 +196,8 @@ module Azure
196
196
  class Usage < BaseModel; end
197
197
  end
198
198
 
199
+ class ResponseBody < BaseModel; end
200
+
199
201
  class ResponseHeaders < BaseModel
200
202
  undef_method :response_headers
201
203
  end
@@ -261,3 +263,4 @@ module Azure
261
263
  end
262
264
 
263
265
  require_relative 'storage_account'
266
+ require_relative 'virtual_machine'
@@ -0,0 +1,39 @@
1
+ module Azure
2
+ module Armrest
3
+ class VirtualMachine < BaseModel
4
+ # Indicates whether the VM is backed by a managed disk or a regular
5
+ # storage account.
6
+ #
7
+ def managed_disk?
8
+ check_for_model_view('managed_disk?')
9
+ properties.storage_profile.os_disk.try(:managed_disk) ? true : false
10
+ end
11
+
12
+ # Returns the size (aka series) for the VM, e.g. "Standard_A0".
13
+ #
14
+ def size
15
+ check_for_model_view('size')
16
+ properties.hardware_profile.vm_size
17
+ end
18
+
19
+ alias flavor size
20
+
21
+ # The operating system for the image, e.g. "Linux" or "Windows".
22
+ #
23
+ def operating_system
24
+ check_for_model_view('operating_sytem')
25
+ properties.storage_profile.os_disk.os_type
26
+ end
27
+
28
+ alias os operating_system
29
+
30
+ private
31
+
32
+ def check_for_model_view(method_name)
33
+ unless respond_to?(:properties)
34
+ raise NoMethodError, "The method '#{method_name}' is only valid for model view objects."
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -11,6 +11,114 @@ module Azure
11
11
  def initialize(configuration, options = {})
12
12
  super(configuration, 'disks', 'Microsoft.Compute', options)
13
13
  end
14
+
15
+ # Get the raw blob information for a managed disk. This is similar to
16
+ # the StorageAccount#get_blob_raw method, but applies only to a managed
17
+ # disk, whereas that method applies only to an individual storage
18
+ # account.
19
+ #
20
+ # As with the Storage#get_blob_raw method, you should pass a :range,
21
+ # :start_byte, :end_byte or :length option. If you want the entire
22
+ # image you must pass the :entire_image option, though this is generally
23
+ # not recommended. Unlike the Storage#get_blob_raw method, this method
24
+ # does not support the :date parameter.
25
+ #
26
+ # The +options+ are as follows:
27
+ #
28
+ # :range => A range of bytes you want, e.g. 0..1023 to get first 1k bytes
29
+ # :start_byte => The starting byte number that you want to collect bytes for. Use
30
+ # this in conjunction with :length or :end_byte.
31
+ # :end_byte => The ending byte that you want to collect bytes for. Use this
32
+ # in conjunction with :start_byte.
33
+ # :length => If given a :start_byte, specifies the number of bytes from the
34
+ # the :start_byte that you wish to collect.
35
+ # :entire_image => If set, returns the entire image in bytes. This will be a long
36
+ # running request that returns a large number of bytes.
37
+ #
38
+ # You may also pass a :duration parameter, which indicates how long, in
39
+ # seconds, that the privately generated SAS token should last. This token
40
+ # is used internally by requests that are used to access the requested
41
+ # information. By default it lasts for 1 hour.
42
+ #
43
+ # Get the information you need using:
44
+ #
45
+ # * response.body - blob data (the raw bytes).
46
+ # * response.headers - blob metadata (a hash).
47
+ #
48
+ # Example:
49
+ #
50
+ # vms = Azure::Armrest::VirtualMachineService.new(conf)
51
+ # sds = Azure::Armrest::Storage::DiskService.new(conf)
52
+ #
53
+ # vm = vms.get(vm_name, vm_resource_group)
54
+ # os_disk = vm.properties.storage_profile.os_disk
55
+ #
56
+ # disk_id = os_disk.managed_disk.id
57
+ # disk = sds.get_by_id(disk_id)
58
+ #
59
+ # # Get the first 1024 bytes
60
+ # data = sds.get_blob_raw(disk.name, disk.resource_group, :range => 0..1023)
61
+ #
62
+ # p data.headers
63
+ # File.open('vm.vhd', 'a'){ |fh| fh.write(data.body) }
64
+ #
65
+ def get_blob_raw(disk_name, resource_group = configuration.resource_group, options = {})
66
+ validate_resource_group(resource_group)
67
+
68
+ post_options = {
69
+ :access => 'read', # Must be 'read'
70
+ :durationInSeconds => options[:duration] || 3600 # 1 hour default
71
+ }
72
+
73
+ # This call will give us an operations URL in the headers.
74
+ initial_url = build_url(resource_group, disk_name, 'BeginGetAccess')
75
+ response = rest_post(initial_url, post_options.to_json)
76
+ headers = ResponseHeaders.new(response.headers)
77
+
78
+ # Using the URL returned from the above call, make another call that
79
+ # will return the URL + SAS token.
80
+ op_url = headers.try(:azure_asyncoperation) || headers.location
81
+
82
+ unless op_url
83
+ msg = "Unable to find an operations URL for #{disk_name}/#{resource_group}"
84
+ raise Azure::Armrest::NotFoundException.new(response.code, msg, response.body)
85
+ end
86
+
87
+ # Dig the URL + SAS token URL out of the response
88
+ response = rest_get(op_url)
89
+ body = ResponseBody.new(response.body)
90
+ sas_url = body.try(:properties).try(:output).try(:access_sas)
91
+
92
+ unless sas_url
93
+ msg = "Unable to find an SAS URL for #{disk_name}/#{resource_group}"
94
+ raise Azure::Armrest::NotFoundException.new(response.code, msg, response.body)
95
+ end
96
+
97
+ # The same restrictions that apply to the StorageAccont method also apply here.
98
+ range = options[:range] if options[:range]
99
+ range ||= options[:start_byte]..options[:end_byte] if options[:start_byte] && options[:end_byte]
100
+ range ||= options[:start_byte]..options[:length]-1 if options[:start_byte] && options[:length]
101
+
102
+ range_str = range ? "bytes=#{range.min}-#{range.max}" : nil
103
+
104
+ unless range_str || options[:entire_image]
105
+ raise ArgumentError, "must specify byte range or :entire_image flag"
106
+ end
107
+
108
+ headers = {}
109
+ headers['x-ms-range'] = range_str if range_str
110
+
111
+ # Need to make a raw call since we need to explicitly pass headers,
112
+ # but without encoding the URL or passing our configuration token.
113
+ RestClient::Request.execute(
114
+ :method => :get,
115
+ :url => sas_url,
116
+ :headers => headers,
117
+ :proxy => configuration.proxy,
118
+ :ssl_version => configuration.ssl_version,
119
+ :ssl_verify => configuration.ssl_verify
120
+ )
121
+ end
14
122
  end # DiskService
15
123
  end # Storage
16
124
  end # Armrest
@@ -1,6 +1,6 @@
1
1
  module Azure
2
2
  module Armrest
3
3
  # The version of the azure-armrest library.
4
- VERSION = '0.7.1'.freeze
4
+ VERSION = '0.7.2'.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.7.1
4
+ version: 0.7.2
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-04-11 00:00:00.000000000 Z
14
+ date: 2017-04-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: json
@@ -248,6 +248,7 @@ files:
248
248
  - lib/azure/armrest/insights/metrics_service.rb
249
249
  - lib/azure/armrest/model/base_model.rb
250
250
  - lib/azure/armrest/model/storage_account.rb
251
+ - lib/azure/armrest/model/virtual_machine.rb
251
252
  - lib/azure/armrest/network/inbound_nat_service.rb
252
253
  - lib/azure/armrest/network/ip_address_service.rb
253
254
  - lib/azure/armrest/network/load_balancer_service.rb
@@ -298,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
298
299
  version: '0'
299
300
  requirements: []
300
301
  rubyforge_project:
301
- rubygems_version: 2.6.8
302
+ rubygems_version: 2.6.11
302
303
  signing_key:
303
304
  specification_version: 4
304
305
  summary: An interface for ARM/JSON Azure REST API