fog-azure-rm 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/fog-azure-rm.gemspec +8 -8
  4. data/lib/fog/azurerm.rb +5 -0
  5. data/lib/fog/azurerm/async_response.rb +36 -0
  6. data/lib/fog/azurerm/compute.rb +15 -1
  7. data/lib/fog/azurerm/constants.rb +6 -0
  8. data/lib/fog/azurerm/docs/compute.md +145 -2
  9. data/lib/fog/azurerm/models/compute/creation_data.rb +21 -0
  10. data/lib/fog/azurerm/models/compute/disk_create_option.rb +16 -0
  11. data/lib/fog/azurerm/models/compute/encryption_settings.rb +29 -0
  12. data/lib/fog/azurerm/models/compute/image_disk_reference.rb +15 -0
  13. data/lib/fog/azurerm/models/compute/managed_disk.rb +77 -0
  14. data/lib/fog/azurerm/models/compute/managed_disks.rb +43 -0
  15. data/lib/fog/azurerm/models/compute/operation_status_response.rb +18 -0
  16. data/lib/fog/azurerm/models/compute/server.rb +12 -7
  17. data/lib/fog/azurerm/models/compute/servers.rb +6 -0
  18. data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +1 -0
  19. data/lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb +33 -0
  20. data/lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb +121 -0
  21. data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +24 -11
  22. data/lib/fog/azurerm/requests/compute/delete_managed_disk.rb +29 -0
  23. data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +1 -1
  24. data/lib/fog/azurerm/requests/compute/get_managed_disk.rb +64 -0
  25. data/lib/fog/azurerm/requests/compute/grant_access_to_managed_disk.rb +30 -0
  26. data/lib/fog/azurerm/requests/compute/list_managed_disks_by_rg.rb +66 -0
  27. data/lib/fog/azurerm/requests/compute/list_managed_disks_in_subscription.rb +66 -0
  28. data/lib/fog/azurerm/requests/compute/revoke_access_to_managed_disk.rb +33 -0
  29. data/lib/fog/azurerm/requests/dns/check_zone_exists.rb +5 -1
  30. data/lib/fog/azurerm/requests/network/check_net_sec_rule_exists.rb +1 -1
  31. data/lib/fog/azurerm/requests/network/check_subnet_exists.rb +1 -1
  32. data/lib/fog/azurerm/utilities/general.rb +13 -10
  33. data/lib/fog/azurerm/version.rb +1 -1
  34. data/test/api_stub.rb +2 -0
  35. data/test/api_stub/models/compute/managed_disk.rb +59 -0
  36. data/test/api_stub/requests/compute/managed_disk.rb +102 -0
  37. data/test/api_stub/requests/compute/virtual_machine.rb +6 -6
  38. data/test/integration/Virtual_network_gateway_connection.rb +0 -6
  39. data/test/integration/application_gateway.rb +1 -1
  40. data/test/integration/credentials/azure.yml +1 -1
  41. data/test/integration/managed_disk.rb +113 -0
  42. data/test/integration/server.rb +39 -1
  43. data/test/integration/traffic_manager.rb +2 -2
  44. data/test/models/compute/test_managed_disk.rb +61 -0
  45. data/test/models/compute/test_managed_disks.rb +68 -0
  46. data/test/models/compute/test_server.rb +7 -1
  47. data/test/models/compute/test_servers.rb +1 -0
  48. data/test/requests/compute/test_check_managed_disk_exists.rb +31 -0
  49. data/test/requests/compute/test_create_or_update_managed_disk.rb +38 -0
  50. data/test/requests/compute/test_create_virtual_machine.rb +27 -0
  51. data/test/requests/compute/test_delete_managed_disk.rb +23 -0
  52. data/test/requests/compute/test_get_managed_disk.rb +24 -0
  53. data/test/requests/compute/test_grant_access_to_managed_disk.rb +26 -0
  54. data/test/requests/compute/test_list_managed_disks_by_rg.rb +24 -0
  55. data/test/requests/compute/test_list_managed_disks_in_subscription.rb +24 -0
  56. data/test/requests/compute/test_revoke_access_to_managed_disk.rb +24 -0
  57. data/test/test_helper.rb +15 -1
  58. metadata +47 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: abba2750995255a81a2edf8cb5d51bf41331f5b3
4
- data.tar.gz: d883aa12233282ce91ce91ceb1ca895eb2ae2810
3
+ metadata.gz: 499bef52b07b1965693b2351d698143b41a8e63e
4
+ data.tar.gz: d609928c181f0d655a7b6c832a42f583f2a5c20e
5
5
  SHA512:
6
- metadata.gz: c17370ff19fd0e568d8309ca054b957e6affee602909e7fc102640eeab68a218ff1f2b47438fc4e015392e9d7d77c9cd4ea7e855fe440dcb35eca441f1d79e32
7
- data.tar.gz: 390a20c58f0321402dc6ebc7d6c789a7a5c8a484b76b14deec8ebf274a50cf09b908f4cfcc1efcc7c41041cdc4d88e734a788582d1afeade4cc49e1e4fda4f2c
6
+ metadata.gz: 55657900d7678d4fd9312f7a11ab4b5b486a674876d27742920b6cafd84879b4ace419fc55abb6d47af0d0dc791ebd80e85e947909a07e8cfd14c081b9b8bfd3
7
+ data.tar.gz: eb622b9ff7a636e64a5ee82ff6890f980be76a5553b00141211a972c2b609d0a06cf46047a3dd204b747a2fdce5e99230c5ba4725c42e4c2d4fb718672f9e280
@@ -1,3 +1,16 @@
1
+ ## 0.3.0
2
+
3
+ **Added**
4
+ - Compute Service - Added support for Managed Disk
5
+ - Compute Service - Added async method of creating server(virtual machine)
6
+
7
+ **Changed:**
8
+ - Compute Service - Changed create server method to take multiple NICs instead of one
9
+ - Updated Azure SDK gems to v0.9.0
10
+
11
+ **Fixed:**
12
+ - Integration tests
13
+
1
14
  ## 0.2.7
2
15
 
3
16
  **Changed:**
@@ -25,14 +25,14 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'fog-core', '~> 1.43.0'
26
26
  spec.add_dependency 'fog-json', '~> 1.0'
27
27
  spec.add_dependency 'rest-client', '~> 2.0.0'
28
- spec.add_dependency 'azure_mgmt_compute', '~> 0.8.0'
29
- spec.add_dependency 'azure_mgmt_resources', '~> 0.8.0'
30
- spec.add_dependency 'azure_mgmt_storage', '~> 0.8.0'
31
- spec.add_dependency 'azure_mgmt_network', '~> 0.8.0'
32
- spec.add_dependency 'azure_mgmt_dns', '~> 0.8.0'
33
- spec.add_dependency 'azure_mgmt_traffic_manager', '~> 0.8.0'
34
- spec.add_dependency 'azure_mgmt_sql', '~> 0.8.0'
35
- spec.add_dependency 'azure_mgmt_key_vault', '~> 0.8.0'
28
+ spec.add_dependency 'azure_mgmt_compute', '~> 0.9.0'
29
+ spec.add_dependency 'azure_mgmt_resources', '~> 0.9.0'
30
+ spec.add_dependency 'azure_mgmt_storage', '~> 0.9.0'
31
+ spec.add_dependency 'azure_mgmt_network', '~> 0.9.0'
32
+ spec.add_dependency 'azure_mgmt_dns', '~> 0.9.0'
33
+ spec.add_dependency 'azure_mgmt_traffic_manager', '~> 0.9.0'
34
+ spec.add_dependency 'azure_mgmt_sql', '~> 0.9.0'
35
+ spec.add_dependency 'azure_mgmt_key_vault', '~> 0.9.0'
36
36
  spec.add_dependency 'azure-storage', '~> 0.11.5.preview'
37
37
  spec.add_dependency 'vhd', '0.0.4'
38
38
  end
@@ -68,6 +68,11 @@ module Fog
68
68
  autoload :AzureRM, File.expand_path('azurerm/key_vault', __dir__)
69
69
  end
70
70
 
71
+ # Autoload Module for Response::Asynchronous
72
+ module AzureRM
73
+ autoload :AsyncResponse, File.expand_path('azurerm/async_response', __dir__)
74
+ end
75
+
71
76
  # Main AzureRM fog Provider Module
72
77
  module AzureRM
73
78
  extend Fog::Provider
@@ -0,0 +1,36 @@
1
+ module Fog
2
+ module AzureRM
3
+ # class for Async Response
4
+ class AsyncResponse
5
+ def initialize(model, promise)
6
+ @fog_model = model
7
+ @promise = promise
8
+ end
9
+
10
+ def value
11
+ response = @promise.value.body
12
+ @fog_model.merge_attributes(@fog_model.class.parse(response))
13
+ end
14
+
15
+ def state
16
+ @promise.state
17
+ end
18
+
19
+ def reason
20
+ @promise.reason
21
+ end
22
+
23
+ def pending?
24
+ @promise.pending?
25
+ end
26
+
27
+ def fulfilled?
28
+ @promise.fulfilled?
29
+ end
30
+
31
+ def rejected?
32
+ @promise.rejected?
33
+ end
34
+ end
35
+ end
36
+ end
@@ -33,6 +33,14 @@ module Fog
33
33
  request :delete_vm_extension
34
34
  request :get_vm_extension
35
35
  request :check_vm_extension_exists
36
+ request :create_or_update_managed_disk
37
+ request :delete_managed_disk
38
+ request :get_managed_disk
39
+ request :check_managed_disk_exists
40
+ request :list_managed_disks_by_rg
41
+ request :list_managed_disks_in_subscription
42
+ request :revoke_access_to_managed_disk
43
+ request :grant_access_to_managed_disk
36
44
 
37
45
  model_path 'fog/azurerm/models/compute'
38
46
  model :availability_set
@@ -41,6 +49,13 @@ module Fog
41
49
  collection :servers
42
50
  model :virtual_machine_extension
43
51
  collection :virtual_machine_extensions
52
+ model :managed_disk
53
+ collection :managed_disks
54
+ model :creation_data
55
+ model :disk_create_option
56
+ model :encryption_settings
57
+ model :image_disk_reference
58
+ model :operation_status_response
44
59
 
45
60
  # This class provides the mock implementation for unit tests.
46
61
  class Mock
@@ -65,7 +80,6 @@ module Fog
65
80
  raise e.message
66
81
  end
67
82
 
68
-
69
83
  options[:environment] = 'AzureCloud' if options[:environment].nil?
70
84
 
71
85
  telemetry = "fog-azure-rm/#{Fog::AzureRM::VERSION}"
@@ -17,18 +17,24 @@ RESOURCE_PROVIDER_NAMESPACE = 6
17
17
  RESOURCE_TYPE = 7
18
18
  RESOURCE_NAME = 8
19
19
  ENDPOINT_PREFIX = 'Microsoft.Network/trafficManagerProfiles'.freeze
20
+ DISK_PREFIX = 'Microsoft.Compute/disks'
20
21
  AZURE_ENDPOINTS = 'azureEndpoints'.freeze
21
22
  EXTERNAL_ENDPOINTS = 'externalEndpoints'.freeze
22
23
  NESTED_ENDPOINTS = 'nestedEndpoints'.freeze
23
24
  GLOBAL = 'global'.freeze
24
25
  UPLOAD_BLOB_WORKER_THREAD_COUNT = 8
25
26
  VM_NAME_POSITION = 8
27
+ PRIMARY_NIC_INDEX = 0
26
28
 
27
29
  ENVIRONMENT_AZURE_CLOUD = 'AzureCloud'.freeze
28
30
  ENVIRONMENT_AZURE_CHINA_CLOUD = 'AzureChinaCloud'.freeze
29
31
  ENVIRONMENT_AZURE_US_GOVERNMENT = 'AzureUSGovernment'.freeze
30
32
  ENVIRONMENT_AZURE_GERMAN_CLOUD = 'AzureGermanCloud'.freeze
31
33
 
34
+ # MsRestAzure::AzureOperationError class Error Codes
35
+ ERROR_CODE_RESOURCE_NOT_FOUND = 'ResourceNotFound'.freeze
36
+ ERROR_CODE_NOT_FOUND = 'NotFound'.freeze
37
+
32
38
  PLATFORM_LINUX = 'linux'.freeze
33
39
 
34
40
  # State of the copy operation
@@ -35,6 +35,9 @@ azure_compute_service.servers.check_vm_exists(<Resource Group name>, <VM Name>)
35
35
 
36
36
  Create a new linux server
37
37
 
38
+ **Info:**
39
+ Attribute **network_interface_card_ids** is an array of NICs ids. The NIC id at index zero will become primary NIC of this server(virtual machine) by default.
40
+
38
41
  ```ruby
39
42
  azure_compute_service.servers.create(
40
43
  name: '<VM Name>',
@@ -45,7 +48,7 @@ Create a new linux server
45
48
  username: '<Username for VM>',
46
49
  password: '<Password for VM>', # Optional, if 'platform' partameter is 'Linux'.
47
50
  disable_password_authentication: false,
48
- network_interface_card_id: '/subscriptions/{Subscription-Id}/resourceGroups/{Resource-Group-Name}/providers/Microsoft.Network/networkInterfaces/{Network-Interface-Id}',
51
+ network_interface_card_ids: ['/subscriptions/{Subscription-Id}/resourceGroups/{Resource-Group-Name}/providers/Microsoft.Network/networkInterfaces/{Network-Interface-Id}'],
49
52
  publisher: 'Canonical', # Not required if custom image is being used
50
53
  offer: 'UbuntuServer', # Not required if custom image is being used
51
54
  sku: '14.04.2-LTS', # Not required if custom image is being used
@@ -69,7 +72,7 @@ Create a new windows server
69
72
  username: '<Username for VM>',
70
73
  password: '<Password for VM>',
71
74
  disable_password_authentication: false,
72
- network_interface_card_id: '/subscriptions/{Subscription-Id}/resourceGroups/{Resource-Group-Name}/providers/Microsoft.Network/networkInterfaces/{Network-Interface-Id}',
75
+ network_interface_card_ids: ['/subscriptions/{Subscription-Id}/resourceGroups/{Resource-Group-Name}/providers/Microsoft.Network/networkInterfaces/{Network-Interface-Id}'],
73
76
  publisher: 'MicrosoftWindowsServerEssentials', # Not required if custom image is being used
74
77
  offer: 'WindowsServerEssentials', # Not required if custom image is being used
75
78
  sku: 'WindowsServerEssentials', # Not required if custom image is being used
@@ -79,6 +82,61 @@ Create a new windows server
79
82
  custom_data: 'echo customData' # Optional, if you want to add custom data in this VM.
80
83
  )
81
84
  ```
85
+
86
+ ## Create Server Asynchronously
87
+
88
+ Create a new linux server asynchronously
89
+
90
+ ```ruby
91
+ async_response = azure_compute_service.servers.create_async(
92
+ name: '<VM Name>',
93
+ location: 'West US',
94
+ resource_group: '<Resource Group Name>',
95
+ vm_size: 'Basic_A0',
96
+ storage_account_name: '<Storage Account Name>',
97
+ username: '<Username for VM>',
98
+ password: '<Password for VM>', # Optional, if 'platform' partameter is 'Linux'.
99
+ disable_password_authentication: false,
100
+ network_interface_card_ids: ['/subscriptions/{Subscription-Id}/resourceGroups/{Resource-Group-Name}/providers/Microsoft.Network/networkInterfaces/{Network-Interface-Id}'],
101
+ publisher: 'Canonical', # Not required if custom image is being used
102
+ offer: 'UbuntuServer', # Not required if custom image is being used
103
+ sku: '14.04.2-LTS', # Not required if custom image is being used
104
+ version: 'latest', # Not required if custom image is being used
105
+ platform: 'Linux',
106
+ vhd_path: '<Path of VHD>', # Optional, if you want to create the VM from a custom image.
107
+ custom_data: 'echo customData', # Optional, if you want to add custom data in this VM.
108
+ os_disk_caching: Fog::ARM::Compute::Models::CachingTypes::None # Optional, can be one of None, ReadOnly, ReadWrite
109
+ )
110
+ ```
111
+ Following methods are available to handle async respoonse:
112
+ - state
113
+ - pending?
114
+ - rejected?
115
+ - reason
116
+ - fulfilled?
117
+ - value
118
+
119
+ An example of handling async response is given below:
120
+
121
+ ```ruby
122
+ while 1
123
+ puts async_response.state
124
+
125
+ if async_response.pending?
126
+ sleep(2)
127
+ end
128
+
129
+ if async_response.fulfilled?
130
+ puts async_response.value.inspect
131
+ break
132
+ end
133
+
134
+ if async_response.rejected?
135
+ puts async_response.reason.inspect
136
+ break
137
+ end
138
+ end
139
+ ```
82
140
 
83
141
  For more information about custom_data; see link: https://msdn.microsoft.com/en-us/library/azure/mt163591.aspx
84
142
 
@@ -247,5 +305,90 @@ Destroy the given extension from the virtual machine
247
305
  vm_extension.destroy
248
306
  ```
249
307
 
308
+
309
+ ## Create Managed Disk
310
+
311
+ Create a new Managed Disk
312
+
313
+ ```ruby
314
+ azure_compute_service.managed_disks.create(
315
+ name: 'disk_name',
316
+ location: 'east us',
317
+ resource_group_name: 'resource_group_name',
318
+ account_type: 'Premium_LRS',
319
+ disk_size_gb: 1023,
320
+ creation_data: {
321
+ create_option: 'Empty'
322
+ }
323
+ )
324
+ ```
325
+
326
+ ## List Managed Disks in a Resource Group
327
+
328
+ List managed disks in a resource group
329
+
330
+ ```ruby
331
+ managed_disks = azure_compute_service.managed_disks(resource_group: '<Resource Group name>')
332
+ mnaged_disks.each do |disk|
333
+ puts "#{disk.name}"
334
+ puts "#{disk.location}"
335
+ end
336
+ ```
337
+
338
+ ## List Managed Disks in a Subscription
339
+
340
+ List managed disks in a subscription
341
+
342
+ ```ruby
343
+ azure_compute_service.managed_disks.each do |disk|
344
+ puts "#{disk.name}"
345
+ puts "#{disk.location}"
346
+ end
347
+ ```
348
+
349
+ ## Grant Access to a Managed Disk
350
+
351
+ Grant access to a managed disk
352
+
353
+ ```ruby
354
+ access_sas = azure_compute_service.managed_disks.grant_access('<resource_group_name>', '<disk_name>', 'Read', 1000)
355
+ puts "Access SAS: #{access_sas}"
356
+ ```
357
+
358
+ ## Revoke Access from a Managed Disk
359
+
360
+ Revoke access from a managed disk
361
+
362
+ ```ruby
363
+ response = azure_compute_service.managed_disks.revoke_access('<resource_group_name>', '<disk_name>')
364
+ puts "Revoke Access response status: #{response.status}"
365
+ ```
366
+
367
+ ## Check Managed Disk Existence
368
+
369
+ ```ruby
370
+ azure_compute_service.managed_disks.check_managed_disk_exists(<Resource Group name>, <Disk name>)
371
+ ```
372
+
373
+ ## Retrieve a single Managed Disk
374
+
375
+ Get a single record of managed disks
376
+
377
+ ```ruby
378
+ managed_disk = azure_compute_service
379
+ .managed_disks
380
+ .get('<Resource Group name>','<Disk name>')
381
+ puts "#{managed_disk.name}"
382
+ ```
383
+
384
+ ## Destroy a single Managed Disk
385
+
386
+ Get an managed disk object from the get method and then destroy that managed disk.
387
+
388
+ ```ruby
389
+ managed_disk.destroy
390
+ ```
391
+
392
+
250
393
  ## Support and Feedback
251
394
  Your feedback is appreciated! If you have specific issues with the fog ARM, you should file an issue via Github.
@@ -0,0 +1,21 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # CreationData model for Compute Service
5
+ class CreationData < Fog::Model
6
+ attribute :create_option
7
+ attribute :storage_account_id
8
+ attribute :source_uri
9
+ attribute :source_resource_id
10
+ attribute :image_reference
11
+
12
+ def self.parse(creation_data)
13
+ data = get_hash_from_object(creation_data)
14
+ image_reference = Fog::Compute::AzureRM::ImageDiskReference.new
15
+ data['image_reference'] = image_reference.merge_attributes(Fog::Compute::AzureRM::ImageDiskReference.parse(creation_data.image_reference))
16
+ data
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ module Fog
2
+ module ARM
3
+ module Compute
4
+ module Models
5
+ module DiskCreateOption
6
+ FromImage = 'fromImage'.freeze
7
+ Empty = 'empty'.freeze
8
+ Attach = 'attach'.freeze
9
+ Import = 'Import'.freeze
10
+ Copy = 'Copy'.freeze
11
+ Restore = 'Restore'.freeze
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # EncryptionSettings model for Compute Service
5
+ class EncryptionSettings < Fog::Model
6
+ attribute :key_url
7
+ attribute :secret_url
8
+ attribute :enabled
9
+ attribute :key_source_vault_id
10
+ attribute :disk_source_vault_id
11
+
12
+ def self.parse(encryption_settings)
13
+ settings = {}
14
+ settings['enabled'] = encryption_settings.enabled
15
+
16
+ if encryption_settings.disk_encryption_key
17
+ settings['secret_url'] = encryption_settings.disk_encryption_key.secret_url
18
+ settings['disk_source_vault_id'] = encryption_settings.disk_encryption_key.source_vault.id
19
+ end
20
+ if encryption_settings.key_encryption_key
21
+ settings['key_url'] = encryption_settings.key_encryption_key.key_url
22
+ settings['key_source_vault_id'] = encryption_settings.key_encryption_key.source_vault.id
23
+ end
24
+ settings
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # ImageReference model for Compute Service
5
+ class ImageDiskReference < Fog::Model
6
+ attribute :id
7
+ attribute :lun
8
+
9
+ def self.parse(image_reference)
10
+ get_hash_from_object(image_reference)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,77 @@
1
+ module Fog
2
+ module Compute
3
+ class AzureRM
4
+ # This class is giving implementation of create/save and
5
+ # delete/destroy for Managed Disk.
6
+ class ManagedDisk < Fog::Model
7
+ attribute :id
8
+ identity :name
9
+ attribute :resource_group_name
10
+ attribute :type
11
+ attribute :location
12
+ attribute :account_type
13
+ attribute :time_created
14
+ attribute :os_type
15
+ attribute :disk_size_gb
16
+ attribute :owner_id
17
+ attribute :provisioning_state
18
+ attribute :tags
19
+ attribute :creation_data
20
+ attribute :encryption_settings
21
+
22
+ def self.parse(managed_disk)
23
+ disk = get_hash_from_object(managed_disk)
24
+
25
+ unless managed_disk.creation_data.nil?
26
+ creation_data = Fog::Compute::AzureRM::CreationData.new
27
+ disk['creation_data'] = creation_data.merge_attributes(Fog::Compute::AzureRM::CreationData.parse(managed_disk.creation_data))
28
+ end
29
+
30
+ unless managed_disk.encryption_settings.nil?
31
+ encryption_settings = Fog::Compute::AzureRM::EncryptionSettings.new
32
+ disk['encryption_settings'] = encryption_settings.merge_attributes(Fog::Compute::AzureRM::EncryptionSettings.parse(managed_disk.encryption_settings))
33
+ end
34
+
35
+ disk['resource_group_name'] = get_resource_group_from_id(managed_disk.id)
36
+
37
+ disk
38
+ end
39
+
40
+ def save
41
+ requires :name, :location, :resource_group_name, :creation_data
42
+ requires :disk_size_gb if creation_data[:create_option] == 'Empty'
43
+ validate_creation_data_params(creation_data)
44
+
45
+ disk = service.create_or_update_managed_disk(managed_disk_params)
46
+ merge_attributes(Fog::Compute::AzureRM::ManagedDisk.parse(disk))
47
+ end
48
+
49
+ def destroy
50
+ service.delete_managed_disk(resource_group_name, name)
51
+ end
52
+
53
+ private
54
+
55
+ def validate_creation_data_params(creation_data)
56
+ unless creation_data.key?(:create_option)
57
+ raise(ArgumentError, ':create_option is required for this operation')
58
+ end
59
+ end
60
+
61
+ def managed_disk_params
62
+ {
63
+ name: name,
64
+ location: location,
65
+ resource_group_name: resource_group_name,
66
+ account_type: account_type,
67
+ os_type: os_type,
68
+ disk_size_gb: disk_size_gb,
69
+ tags: tags,
70
+ creation_data: creation_data,
71
+ encryption_settings: encryption_settings
72
+ }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end