fog-azure-rm 0.4.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 524c1f0c1c6c31d7d7fd46537968247958d85a5c34bd8d9a32b9999a40406058
4
- data.tar.gz: 876712ef9579847efccf838bd144680b196cc3d9fe526c7cd72b2ebb5e68ff5c
3
+ metadata.gz: 58bc4e9c11864f922ab1714a0fe2b86ec38a13de4c89462600168cff315704db
4
+ data.tar.gz: b7a07536a11d4959fcad7c0d27c9395500a05a95ea5c7112066ba612221f31dd
5
5
  SHA512:
6
- metadata.gz: 9f32d3d8d593db5306da3458bbc348ccb5824b5ea2a34661b721755531f9d9c5b853fa365d6d71540b51160f80eb771a22fbe0a164aa59add05fc6d2d8ee1bc8
7
- data.tar.gz: b4af7b5491fc177f1804a8a5078ffdd0ae93cfcc7bc3a4333eef1d179e74d22c64e87909901c96e081fdba9201c00bf36803e7896b55da6af82fde409822afeb
6
+ metadata.gz: b5026003c03125cf94f3653d6a0305a669109a18dd3ab274664e43195a9b0ae3b7e30249c10bed61cfcfedb2e50b6a7d3e5ae0f96a635faf777a451d984f24f1
7
+ data.tar.gz: 67cc8a80a8bebf498c3713a22e2d987141a98cbe728947a5fa8e689984e0ff946ffdccf8bd915e8ab3115150c6a09f435b0a747841f9118192548918d1f60086
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.4.3
2
+
3
+ **Fixed:**
4
+ - Compute Service - Fixed Server Update Scenario
5
+
1
6
  ## 0.4.2
2
7
 
3
8
  **Fixed:**
data/lib/fog/azurerm.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'ms_rest_azure'
2
+ require 'azure/core/http/http_error'
2
3
  require 'erb'
3
4
  require 'fog/azurerm/config'
4
5
  require 'fog/azurerm/constants'
@@ -61,7 +61,8 @@ fog_compute_service.servers.create(
61
61
  custom_data: '<Custom Data Value>', # [Optional], if you want to add custom data in this VM.
62
62
  os_disk_caching: '<Caching Type>', # [Optional], can be one of None, ReadOnly, ReadWrite
63
63
  managed_disk_storage_type: '<Storage Account Type>', # [Optional], if storage_account_name is passed, can be StandardLRS or PremiumLRS
64
- os_disk_size: <Disk Size> # [Optional], size of the os disk in GB (upto 1023)
64
+ os_disk_size: <Disk Size>, # [Optional], size of the os disk in GB (upto 1023)
65
+ os_disk_name: '<Disk Name>' # [Optional], name of the os disk
65
66
  )
66
67
  ```
67
68
 
@@ -97,7 +98,8 @@ fog_compute_service.servers.create(
97
98
  custom_data: '<Custom Data Value>', # [Optional], if you want to add custom data in this VM.
98
99
  os_disk_caching: '<Caching Type>', # [Optional], can be one of None, ReadOnly, ReadWrite
99
100
  managed_disk_storage_type: '<Storage Account Type>', # [Optional], if storage_account_name is passed, can be StandardLRS or PremiumLRS
100
- os_disk_size: <Disk Size> # [Optional], size of the os disk in GB (upto 1023)
101
+ os_disk_size: <Disk Size>, # [Optional], size of the os disk in GB (upto 1023)
102
+ os_disk_name: '<Disk Name>' # [Optional], name of the os disk
101
103
  )
102
104
  ```
103
105
 
@@ -123,7 +125,8 @@ fog_compute_service.servers.create(
123
125
  availability_set_id: '<Availability Set Id>', # [Optional]
124
126
  vhd_path: '<Path of VHD>', # [Optional], if you want to create the VM from a custom image.
125
127
  custom_data: '<Custom Data Value>', # [Optional], if you want to add custom data in this VM.
126
- os_disk_size: <Disk Size> # [Optional], size of the os disk in GB (upto 1023)
128
+ os_disk_size: <Disk Size>, # [Optional], size of the os disk in GB (upto 1023)
129
+ os_disk_name: '<Disk Name>' # [Optional], name of the os disk
127
130
  )
128
131
  ```
129
132
 
@@ -153,7 +156,8 @@ async_response = fog_compute_service.servers.create_async(
153
156
  custom_data: '<Custom Data Value>', # [Optional], if you want to add custom data in this VM.
154
157
  os_disk_caching: '<Caching Type>', # [Optional], can be one of None, ReadOnly, ReadWrite
155
158
  managed_disk_storage_type: '<Storage Account Type>', # [Optional], can be StandardLRS or PremiumLRS
156
- os_disk_size: <Disk Size> # [Optional], size of the os disk in GB (upto 1023)
159
+ os_disk_size: <Disk Size>, # [Optional], size of the os disk in GB (upto 1023)
160
+ os_disk_name: '<Disk Name>' # [Optional], name of the os disk
157
161
  )
158
162
  ```
159
163
  Following methods are available to handle async respoonse:
@@ -228,7 +228,9 @@ module Fog
228
228
  managed_disk_storage_type: managed_disk_storage_type,
229
229
  os_disk_size: os_disk_size,
230
230
  tags: tags,
231
- image_ref: image_ref
231
+ image_ref: image_ref,
232
+ os_disk_name: os_disk_name,
233
+ os_disk_vhd_uri: os_disk_vhd_uri
232
234
  }
233
235
  end
234
236
 
@@ -11,6 +11,13 @@ module Fog
11
11
  vm_name = vm_config[:name]
12
12
  rg_name = vm_config[:resource_group]
13
13
 
14
+ # In case of updating the VM, we check if the user has passed any value for os_disk_name
15
+ # If the user has not passed any value, we try to retrieve the value of os_disk_name from the VM
16
+ # If the VM exists then the os_disk_name is retrieved; else it remains nil
17
+ os_disk_parameters = get_os_disk_parameters(rg_name, vm_name) if vm_config[:os_disk_name].nil? || vm_config[:os_disk_vhd_uri].nil?
18
+ vm_config[:os_disk_name] = os_disk_parameters[:os_disk_name] if vm_config[:os_disk_name].nil?
19
+ vm_config[:os_disk_vhd_uri] = os_disk_parameters[:os_disk_vhd_uri] if vm_config[:os_disk_vhd_uri].nil?
20
+
14
21
  msg = "Creating Virtual Machine '#{vm_name}' in Resource Group '#{rg_name}'..."
15
22
  Fog::Logger.debug msg
16
23
 
@@ -154,12 +161,14 @@ module Fog
154
161
  os_disk_size = vm_config[:os_disk_size]
155
162
  location = vm_config[:location]
156
163
  image_ref = vm_config[:image_ref]
164
+ os_disk_name = vm_config[:os_disk_name]
165
+ os_disk_vhd_uri = vm_config[:os_disk_vhd_uri]
157
166
 
158
167
  storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
159
168
  # Set OS disk VHD path
160
169
  os_disk = Azure::ARM::Compute::Models::OSDisk.new
161
170
  vhd = Azure::ARM::Compute::Models::VirtualHardDisk.new
162
- vhd.uri = get_blob_endpoint(storage_account_name) + "/vhds/#{vm_name}_os_disk.vhd"
171
+ vhd.uri = os_disk_vhd_uri.nil? ? get_blob_endpoint(storage_account_name) + "/vhds/#{vm_name}_os_disk.vhd" : os_disk_vhd_uri
163
172
  os_disk.vhd = vhd
164
173
 
165
174
  if vhd_path.nil? && image_ref.nil?
@@ -180,7 +189,7 @@ module Fog
180
189
  storage_profile.image_reference.id = image.id
181
190
  end
182
191
 
183
- storage_profile.os_disk = configure_os_disk_object(os_disk, os_disk_caching, os_disk_size, platform, vm_name)
192
+ storage_profile.os_disk = configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
184
193
  storage_profile
185
194
  end
186
195
 
@@ -200,6 +209,7 @@ module Fog
200
209
  platform = vm_config[:platform]
201
210
  vm_name = vm_config[:name]
202
211
  image_ref = vm_config[:image_ref]
212
+ os_disk_name = vm_config[:os_disk_name]
203
213
 
204
214
  # Build storage profile
205
215
  storage_profile = Azure::ARM::Compute::Models::StorageProfile.new
@@ -226,7 +236,7 @@ module Fog
226
236
  storage_profile.image_reference.id = image.id
227
237
  end
228
238
 
229
- storage_profile.os_disk = configure_os_disk_object(os_disk, os_disk_caching, os_disk_size, platform, vm_name)
239
+ storage_profile.os_disk = configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
230
240
  storage_profile
231
241
  end
232
242
 
@@ -249,8 +259,9 @@ module Fog
249
259
  }
250
260
  end
251
261
 
252
- def configure_os_disk_object(os_disk, os_disk_caching, os_disk_size, platform, vm_name)
253
- os_disk.name = "#{vm_name}_os_disk"
262
+ def configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
263
+ # It will use the os_disk_name provided or it will generate a name for itself if it is nil
264
+ os_disk.name = os_disk_name.nil? ? "#{vm_name}_os_disk" : os_disk_name
254
265
  os_disk.os_type = platform
255
266
  os_disk.disk_size_gb = os_disk_size unless os_disk_size.nil?
256
267
  os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
@@ -332,6 +343,23 @@ module Fog
332
343
  TEMPORARY_STORAGE_ACCOUNT_TAG_KEY,
333
344
  TEMPORARY_STORAGE_ACCOUNT_TAG_VALUE)
334
345
  end
346
+
347
+ def get_os_disk_parameters(resource_group, virtual_machine_name)
348
+ os_disk_parameters = {}
349
+
350
+ begin
351
+ vm = get_virtual_machine(resource_group, virtual_machine_name, false)
352
+ rescue
353
+ return os_disk_parameters
354
+ end
355
+
356
+ unless vm.storage_profile.nil?
357
+ os_disk_parameters[:os_disk_name] = vm.storage_profile.os_disk.name
358
+ os_disk_parameters[:os_disk_vhd_uri] = vm.storage_profile.os_disk.vhd.uri unless vm.storage_profile.os_disk.vhd.nil?
359
+ end
360
+
361
+ os_disk_parameters
362
+ end
335
363
  end
336
364
 
337
365
  # This class provides the mock implementation for unit tests.
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module AzureRM
3
- VERSION = '0.4.2'.freeze
3
+ VERSION = '0.4.3'.freeze
4
4
  end
5
5
  end
@@ -10,80 +10,104 @@ class TestCreateVirtualMachine < Minitest::Test
10
10
  @custom_data_response = ApiStub::Requests::Compute::VirtualMachine.create_virtual_machine_with_custom_data_response(compute_client)
11
11
  @linux_virtual_machine_hash = ApiStub::Requests::Compute::VirtualMachine.linux_virtual_machine_params
12
12
  @windows_virtual_machine_hash = ApiStub::Requests::Compute::VirtualMachine.windows_virtual_machine_params
13
+ @error_response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
13
14
  end
14
15
 
15
16
  def test_create_linux_virtual_machine_success
16
17
  @virtual_machines.stub :create_or_update, @response do
17
- assert_equal @service.create_virtual_machine(@linux_virtual_machine_hash), @response
18
+ @virtual_machines.stub :get, @error_response do
19
+ assert_equal @service.create_virtual_machine(@linux_virtual_machine_hash), @response
20
+ end
18
21
  end
19
22
 
20
23
  # Async
21
24
  @virtual_machines.stub :create_or_update_async, @response do
22
- assert_equal @service.create_virtual_machine(@linux_virtual_machine_hash, true), @response
25
+ @virtual_machines.stub :get, @error_response do
26
+ assert_equal @service.create_virtual_machine(@linux_virtual_machine_hash, true), @response
27
+ end
23
28
  end
24
29
  end
25
30
 
26
31
  def test_create_windows_virtual_machine_success
27
32
  @virtual_machines.stub :create_or_update, @response do
28
- assert_equal @service.create_virtual_machine(@windows_virtual_machine_hash), @response
33
+ @virtual_machines.stub :get, @error_response do
34
+ assert_equal @service.create_virtual_machine(@windows_virtual_machine_hash), @response
35
+ end
29
36
  end
30
37
 
31
38
  # Async
32
39
  @virtual_machines.stub :create_or_update_async, @response do
33
- assert_equal @service.create_virtual_machine(@windows_virtual_machine_hash, true), @response
40
+ @virtual_machines.stub :get, @error_response do
41
+ assert_equal @service.create_virtual_machine(@windows_virtual_machine_hash, true), @response
42
+ end
34
43
  end
35
44
  end
36
45
 
37
46
  def test_create_linux_virtual_machine_from_custom_image_success
38
47
  linux_virtual_machine_with_custom_image_hash = ApiStub::Requests::Compute::VirtualMachine.linux_virtual_machine_with_custom_image_params
39
48
  @virtual_machines.stub :create_or_update, @response do
40
- assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_image_hash), @response
49
+ @virtual_machines.stub :get, @error_response do
50
+ assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_image_hash), @response
51
+ end
41
52
  end
42
53
 
43
54
  # Async
44
55
  @virtual_machines.stub :create_or_update_async, @response do
45
- assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_image_hash, true), @response
56
+ @virtual_machines.stub :get, @error_response do
57
+ assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_image_hash, true), @response
58
+ end
46
59
  end
47
60
  end
48
61
 
49
62
  def test_create_windows_virtual_machine_from_custom_image_success
50
63
  windows_virtual_machine_with_custom_image_hash = ApiStub::Requests::Compute::VirtualMachine.windows_virtual_machine_with_custom_image_params
51
64
  @virtual_machines.stub :create_or_update, @response do
52
- assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_image_hash), @response
65
+ @virtual_machines.stub :get, @error_response do
66
+ assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_image_hash), @response
67
+ end
53
68
  end
54
69
 
55
70
  # Async
56
71
  @virtual_machines.stub :create_or_update_async, @response do
57
- assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_image_hash, true), @response
72
+ @virtual_machines.stub :get, @error_response do
73
+ assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_image_hash, true), @response
74
+ end
58
75
  end
59
76
  end
60
77
 
61
78
  def test_create_linux_virtual_machine_with_custom_data_success
62
79
  linux_virtual_machine_with_custom_data_hash = ApiStub::Requests::Compute::VirtualMachine.linux_virtual_machine_with_custom_data_params
63
80
  @virtual_machines.stub :create_or_update, @custom_data_response do
64
- assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_data_hash), @custom_data_response
81
+ @virtual_machines.stub :get, @error_response do
82
+ assert_equal @service.create_virtual_machine(linux_virtual_machine_with_custom_data_hash), @custom_data_response
83
+ end
65
84
  end
66
85
  end
67
86
 
68
87
  def test_create_windows_virtual_machine_with_custom_data_success
69
88
  windows_virtual_machine_with_custom_data_hash = ApiStub::Requests::Compute::VirtualMachine.windows_virtual_machine_with_custom_data_params
70
89
  @virtual_machines.stub :create_or_update, @custom_data_response do
71
- assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_data_hash), @custom_data_response
90
+ @virtual_machines.stub :get, @error_response do
91
+ assert_equal @service.create_virtual_machine(windows_virtual_machine_with_custom_data_hash), @custom_data_response
92
+ end
72
93
  end
73
94
  end
74
95
 
75
96
  def test_create_virtual_machine_failure
76
- response = proc { raise MsRestAzure::AzureOperationError.new(nil, nil, 'error' => { 'message' => 'mocked exception' }) }
77
- @virtual_machines.stub :create_or_update, response do
78
- assert_raises RuntimeError do
79
- @service.create_virtual_machine(@linux_virtual_machine_hash)
97
+ @virtual_machines.stub :create_or_update, @error_response do
98
+ @virtual_machines.stub :get, @error_response do
99
+ assert_raises RuntimeError do
100
+ @service.create_virtual_machine(@linux_virtual_machine_hash)
101
+ end
80
102
  end
81
103
  end
82
104
 
83
105
  # Async
84
- @virtual_machines.stub :create_or_update_async, response do
85
- assert_raises RuntimeError do
86
- @service.create_virtual_machine(@linux_virtual_machine_hash, true)
106
+ @virtual_machines.stub :create_or_update_async, @error_response do
107
+ @virtual_machines.stub :get, @error_response do
108
+ assert_raises RuntimeError do
109
+ @service.create_virtual_machine(@linux_virtual_machine_hash, true)
110
+ end
87
111
  end
88
112
  end
89
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-azure-rm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shaffan Chaudhry
@@ -18,7 +18,7 @@ authors:
18
18
  autorequire:
19
19
  bindir: bin
20
20
  cert_chain: []
21
- date: 2018-01-03 00:00:00.000000000 Z
21
+ date: 2018-01-10 00:00:00.000000000 Z
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
24
24
  name: rake