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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/fog-azure-rm.gemspec +8 -8
- data/lib/fog/azurerm.rb +5 -0
- data/lib/fog/azurerm/async_response.rb +36 -0
- data/lib/fog/azurerm/compute.rb +15 -1
- data/lib/fog/azurerm/constants.rb +6 -0
- data/lib/fog/azurerm/docs/compute.md +145 -2
- data/lib/fog/azurerm/models/compute/creation_data.rb +21 -0
- data/lib/fog/azurerm/models/compute/disk_create_option.rb +16 -0
- data/lib/fog/azurerm/models/compute/encryption_settings.rb +29 -0
- data/lib/fog/azurerm/models/compute/image_disk_reference.rb +15 -0
- data/lib/fog/azurerm/models/compute/managed_disk.rb +77 -0
- data/lib/fog/azurerm/models/compute/managed_disks.rb +43 -0
- data/lib/fog/azurerm/models/compute/operation_status_response.rb +18 -0
- data/lib/fog/azurerm/models/compute/server.rb +12 -7
- data/lib/fog/azurerm/models/compute/servers.rb +6 -0
- data/lib/fog/azurerm/models/traffic_manager/traffic_manager_profile.rb +1 -0
- data/lib/fog/azurerm/requests/compute/check_managed_disk_exists.rb +33 -0
- data/lib/fog/azurerm/requests/compute/create_or_update_managed_disk.rb +121 -0
- data/lib/fog/azurerm/requests/compute/create_virtual_machine.rb +24 -11
- data/lib/fog/azurerm/requests/compute/delete_managed_disk.rb +29 -0
- data/lib/fog/azurerm/requests/compute/delete_virtual_machine.rb +1 -1
- data/lib/fog/azurerm/requests/compute/get_managed_disk.rb +64 -0
- data/lib/fog/azurerm/requests/compute/grant_access_to_managed_disk.rb +30 -0
- data/lib/fog/azurerm/requests/compute/list_managed_disks_by_rg.rb +66 -0
- data/lib/fog/azurerm/requests/compute/list_managed_disks_in_subscription.rb +66 -0
- data/lib/fog/azurerm/requests/compute/revoke_access_to_managed_disk.rb +33 -0
- data/lib/fog/azurerm/requests/dns/check_zone_exists.rb +5 -1
- data/lib/fog/azurerm/requests/network/check_net_sec_rule_exists.rb +1 -1
- data/lib/fog/azurerm/requests/network/check_subnet_exists.rb +1 -1
- data/lib/fog/azurerm/utilities/general.rb +13 -10
- data/lib/fog/azurerm/version.rb +1 -1
- data/test/api_stub.rb +2 -0
- data/test/api_stub/models/compute/managed_disk.rb +59 -0
- data/test/api_stub/requests/compute/managed_disk.rb +102 -0
- data/test/api_stub/requests/compute/virtual_machine.rb +6 -6
- data/test/integration/Virtual_network_gateway_connection.rb +0 -6
- data/test/integration/application_gateway.rb +1 -1
- data/test/integration/credentials/azure.yml +1 -1
- data/test/integration/managed_disk.rb +113 -0
- data/test/integration/server.rb +39 -1
- data/test/integration/traffic_manager.rb +2 -2
- data/test/models/compute/test_managed_disk.rb +61 -0
- data/test/models/compute/test_managed_disks.rb +68 -0
- data/test/models/compute/test_server.rb +7 -1
- data/test/models/compute/test_servers.rb +1 -0
- data/test/requests/compute/test_check_managed_disk_exists.rb +31 -0
- data/test/requests/compute/test_create_or_update_managed_disk.rb +38 -0
- data/test/requests/compute/test_create_virtual_machine.rb +27 -0
- data/test/requests/compute/test_delete_managed_disk.rb +23 -0
- data/test/requests/compute/test_get_managed_disk.rb +24 -0
- data/test/requests/compute/test_grant_access_to_managed_disk.rb +26 -0
- data/test/requests/compute/test_list_managed_disks_by_rg.rb +24 -0
- data/test/requests/compute/test_list_managed_disks_in_subscription.rb +24 -0
- data/test/requests/compute/test_revoke_access_to_managed_disk.rb +24 -0
- data/test/test_helper.rb +15 -1
- metadata +47 -18
@@ -0,0 +1,43 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# This class is giving implementation of all/list, get and
|
5
|
+
# check existence for managed disk.
|
6
|
+
class ManagedDisks < Fog::Collection
|
7
|
+
model Fog::Compute::AzureRM::ManagedDisk
|
8
|
+
attribute :resource_group
|
9
|
+
def all
|
10
|
+
if !resource_group.nil?
|
11
|
+
requires :resource_group
|
12
|
+
disks = service.list_managed_disks_by_rg(resource_group)
|
13
|
+
else
|
14
|
+
disks = service.list_managed_disks_in_subscription
|
15
|
+
end
|
16
|
+
managed_disks = disks.map { |disk| Fog::Compute::AzureRM::ManagedDisk.parse(disk) }
|
17
|
+
|
18
|
+
load(managed_disks)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get(resource_group_name, disk_name)
|
22
|
+
disk = service.get_managed_disk(resource_group_name, disk_name)
|
23
|
+
managed_disk_fog = Fog::Compute::AzureRM::ManagedDisk.new(service: service)
|
24
|
+
managed_disk_fog.merge_attributes(Fog::Compute::AzureRM::ManagedDisk.parse(disk))
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_managed_disk_exists(resource_group, disk_name)
|
28
|
+
service.check_managed_disk_exists(resource_group, disk_name)
|
29
|
+
end
|
30
|
+
|
31
|
+
def grant_access(resource_group_name, disk_name, access_type, duration_in_sec)
|
32
|
+
service.grant_access_to_managed_disk(resource_group_name, disk_name, access_type, duration_in_sec)
|
33
|
+
end
|
34
|
+
|
35
|
+
def revoke_access(resource_group_name, disk_name)
|
36
|
+
response = service.revoke_access_to_managed_disk(resource_group_name, disk_name)
|
37
|
+
operation_status_response = Fog::Compute::AzureRM::OperationStatusResponse.new(service: service)
|
38
|
+
operation_status_response.merge_attributes(Fog::Compute::AzureRM::OperationStatusResponse.parse(response))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# OperationStatusResponse model for Compute Service
|
5
|
+
class OperationStatusResponse < Fog::Model
|
6
|
+
attribute :name
|
7
|
+
attribute :status
|
8
|
+
attribute :start_time
|
9
|
+
attribute :end_time
|
10
|
+
attribute :error
|
11
|
+
|
12
|
+
def self.parse(operation_status_response)
|
13
|
+
get_hash_from_object(operation_status_response)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -26,7 +26,7 @@ module Fog
|
|
26
26
|
attribute :platform
|
27
27
|
attribute :provision_vm_agent
|
28
28
|
attribute :enable_automatic_updates
|
29
|
-
attribute :
|
29
|
+
attribute :network_interface_card_ids
|
30
30
|
attribute :availability_set_id
|
31
31
|
attribute :custom_data
|
32
32
|
attribute :vhd_path
|
@@ -67,15 +67,15 @@ module Fog
|
|
67
67
|
hash['provision_vm_agent'] = vm.os_profile.windows_configuration.provision_vmagent
|
68
68
|
hash['enable_automatic_updates'] = vm.os_profile.windows_configuration.enable_automatic_updates
|
69
69
|
end
|
70
|
-
hash['
|
70
|
+
hash['network_interface_card_ids'] = vm.network_profile.network_interfaces.map(&:id)
|
71
71
|
hash['availability_set_id'] = vm.availability_set.id unless vm.availability_set.nil?
|
72
72
|
|
73
73
|
hash
|
74
74
|
end
|
75
75
|
|
76
|
-
def save
|
76
|
+
def save(async = false)
|
77
77
|
requires :name, :location, :resource_group, :vm_size, :storage_account_name,
|
78
|
-
:username, :
|
78
|
+
:username, :network_interface_card_ids
|
79
79
|
requires :publisher, :offer, :sku, :version if vhd_path.nil?
|
80
80
|
|
81
81
|
if platform_is_linux?(platform)
|
@@ -85,8 +85,13 @@ module Fog
|
|
85
85
|
end
|
86
86
|
|
87
87
|
ssh_key_path = "/home/#{username}/.ssh/authorized_keys" unless ssh_key_data.nil?
|
88
|
-
|
89
|
-
|
88
|
+
|
89
|
+
if async
|
90
|
+
service.create_virtual_machine(virtual_machine_params(ssh_key_path), true)
|
91
|
+
else
|
92
|
+
vm = service.create_virtual_machine(virtual_machine_params(ssh_key_path))
|
93
|
+
merge_attributes(Fog::Compute::AzureRM::Server.parse(vm))
|
94
|
+
end
|
90
95
|
end
|
91
96
|
|
92
97
|
def destroy
|
@@ -153,7 +158,7 @@ module Fog
|
|
153
158
|
disable_password_authentication: disable_password_authentication,
|
154
159
|
ssh_key_path: ssh_key_path,
|
155
160
|
ssh_key_data: ssh_key_data,
|
156
|
-
|
161
|
+
network_interface_card_ids: network_interface_card_ids,
|
157
162
|
availability_set_id: availability_set_id,
|
158
163
|
publisher: publisher,
|
159
164
|
offer: offer,
|
@@ -16,6 +16,12 @@ module Fog
|
|
16
16
|
load(virtual_machines)
|
17
17
|
end
|
18
18
|
|
19
|
+
def create_async(attributes = {})
|
20
|
+
server = new(attributes)
|
21
|
+
async_response = server.save(true)
|
22
|
+
Fog::AzureRM::AsyncResponse.new(server, async_response)
|
23
|
+
end
|
24
|
+
|
19
25
|
def get(resource_group_name, virtual_machine_name)
|
20
26
|
virtual_machine = service.get_virtual_machine(resource_group_name, virtual_machine_name)
|
21
27
|
virtual_machine_fog = Fog::Compute::AzureRM::Server.new(service: service)
|
@@ -55,6 +55,7 @@ module Fog
|
|
55
55
|
|
56
56
|
def update(profile_params)
|
57
57
|
validate_input(profile_params)
|
58
|
+
profile_params[:endpoints] = endpoints.map { |endpoint| get_hash_from_object(endpoint)['attributes'] }
|
58
59
|
merge_attributes(profile_params)
|
59
60
|
profile = service.create_or_update_traffic_manager_profile(traffic_manager_profile_hash)
|
60
61
|
merge_attributes(Fog::TrafficManager::AzureRM::TrafficManagerProfile.parse(profile))
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def check_managed_disk_exists(resource_group_name, disk_name)
|
7
|
+
msg = "Checking if Managed Disk: #{disk_name} exists"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
begin
|
10
|
+
@compute_mgmt_client.disks.get(resource_group_name, disk_name)
|
11
|
+
Fog::Logger.debug "Managed Disk #{disk_name} exist."
|
12
|
+
true
|
13
|
+
rescue MsRestAzure::AzureOperationError => e
|
14
|
+
if e.error_code == 'ResourceNotFound'
|
15
|
+
Fog::Logger.debug "Managed Disk #{disk_name} doesn't exist."
|
16
|
+
false
|
17
|
+
else
|
18
|
+
raise_azure_exception(e, msg)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Mock class for Compute Request
|
25
|
+
class Mock
|
26
|
+
def check_managed_disk_exists(*)
|
27
|
+
Fog::Logger.debug 'Managed Disk test-disk from Resource group fog-rg is available.'
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def create_or_update_managed_disk(managed_disk_params)
|
7
|
+
msg = "Creating/Updating Managed Disk: #{managed_disk_params[:name]}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
disk = get_managed_disk_object(managed_disk_params)
|
10
|
+
begin
|
11
|
+
managed_disk = @compute_mgmt_client.disks.create_or_update(managed_disk_params[:resource_group_name], managed_disk_params[:name], disk)
|
12
|
+
rescue MsRestAzure::AzureOperationError => e
|
13
|
+
raise_azure_exception(e, msg)
|
14
|
+
end
|
15
|
+
Fog::Logger.debug "Managed Disk #{managed_disk_params[:name]} created/updated successfully."
|
16
|
+
managed_disk
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_managed_disk_object(managed_disk_params)
|
22
|
+
managed_disk = Azure::ARM::Compute::Models::Disk.new
|
23
|
+
managed_disk.name = managed_disk_params[:name]
|
24
|
+
managed_disk.type = DISK_PREFIX
|
25
|
+
managed_disk.location = managed_disk_params[:location]
|
26
|
+
managed_disk.account_type = managed_disk_params[:account_type]
|
27
|
+
managed_disk.os_type = managed_disk_params[:os_type]
|
28
|
+
managed_disk.disk_size_gb = managed_disk_params[:disk_size_gb]
|
29
|
+
managed_disk.tags = managed_disk_params[:tags] if managed_disk.tags.nil?
|
30
|
+
|
31
|
+
creation_data = managed_disk_params[:creation_data]
|
32
|
+
managed_disk.creation_data = get_creation_data_object(creation_data) unless creation_data.nil?
|
33
|
+
|
34
|
+
encryption_settings = managed_disk_params[:encryption_settings]
|
35
|
+
managed_disk.encryption_settings = get_encryption_settings_object(encryption_settings) unless encryption_settings.nil?
|
36
|
+
|
37
|
+
managed_disk
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_creation_data_object(data)
|
41
|
+
creation_data = Azure::ARM::Compute::Models::CreationData.new
|
42
|
+
creation_data.create_option = data[:create_option]
|
43
|
+
creation_data.storage_account_id = data[:storage_account_id]
|
44
|
+
creation_data.source_uri = data[:source_uri]
|
45
|
+
creation_data.source_resource_id = data[:source_resource_id]
|
46
|
+
|
47
|
+
image_reference = data[:image_reference]
|
48
|
+
unless image_reference.nil?
|
49
|
+
image_disk_reference = Azure::ARM::Compute::Models::ImageDiskReference.new
|
50
|
+
image_disk_reference.id = image_reference[:id]
|
51
|
+
image_disk_reference.lun = image_reference[:lun]
|
52
|
+
|
53
|
+
creation_data.image_reference = image_disk_reference
|
54
|
+
end
|
55
|
+
creation_data
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_encryption_settings_object(settings)
|
59
|
+
encryption_settings = Azure::ARM::Compute::Models::EncryptionSettings.new
|
60
|
+
disk_encryption_key = Azure::ARM::Compute::Models::KeyVaultAndSecretReference.new
|
61
|
+
disk_encryption_key.secret_url = settings[:secret_url]
|
62
|
+
disk_encryption_key.source_vault.id = settings[:disk_source_vault_id]
|
63
|
+
encryption_settings.disk_encryption_key = disk_encryption_key
|
64
|
+
|
65
|
+
encryption_settings.enabled = settings[:enabled]
|
66
|
+
|
67
|
+
key_encryption_key = Azure::ARM::Compute::Models::KeyVaultAndKeyReference.new
|
68
|
+
key_encryption_key.key_url = settings[:key_uri]
|
69
|
+
key_encryption_key.source_vault = settings[:key_source_vault_id]
|
70
|
+
encryption_settings.key_encryption_key = key_encryption_key
|
71
|
+
|
72
|
+
encryption_settings
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Mock class for Compute Request
|
77
|
+
class Mock
|
78
|
+
def create_or_update_managed_disk(*)
|
79
|
+
disk = {
|
80
|
+
'accountType' => 'Standard_LRS',
|
81
|
+
'properties' => {
|
82
|
+
'osType' => 'Windows',
|
83
|
+
'creationData' => {
|
84
|
+
'createOption' => 'Empty'
|
85
|
+
},
|
86
|
+
'diskSizeGB' => 10,
|
87
|
+
'encryptionSettings' => {
|
88
|
+
'enabled' => true,
|
89
|
+
'diskEncryptionKey' => {
|
90
|
+
'sourceVault' => {
|
91
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
|
92
|
+
},
|
93
|
+
'secretUrl' => 'https://myvmvault.vault-int.azure-int.net/secrets/{secret}'
|
94
|
+
},
|
95
|
+
'keyEncryptionKey' => {
|
96
|
+
'sourceVault' => {
|
97
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
|
98
|
+
},
|
99
|
+
'keyUrl' => 'https://myvmvault.vault-int.azure-int.net/keys/{key}'
|
100
|
+
}
|
101
|
+
},
|
102
|
+
'timeCreated' => '2016-12-28T02:46:21.3322041+00:00',
|
103
|
+
'provisioningState' => 'Succeeded',
|
104
|
+
'diskState' => 'Unattached'
|
105
|
+
},
|
106
|
+
'type' => 'Microsoft.Compute/disks',
|
107
|
+
'location' => 'westus',
|
108
|
+
'tags' => {
|
109
|
+
'department' => 'Development',
|
110
|
+
'project' => 'ManagedDisks'
|
111
|
+
},
|
112
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk1',
|
113
|
+
'name' => 'myManagedDisk1'
|
114
|
+
}
|
115
|
+
disk_mapper = Azure::ARM::Compute::Models::Disk.mapper
|
116
|
+
@compute_mgmt_client.deserialize(disk_mapper, disk, 'result.body')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -6,7 +6,7 @@ module Fog
|
|
6
6
|
class AzureRM
|
7
7
|
# This class provides the actual implementation for service calls.
|
8
8
|
class Real
|
9
|
-
def create_virtual_machine(vm_hash)
|
9
|
+
def create_virtual_machine(vm_hash, async = false)
|
10
10
|
msg = "Creating Virtual Machine #{vm_hash[:name]} in Resource Group #{vm_hash[:resource_group]}."
|
11
11
|
Fog::Logger.debug msg
|
12
12
|
virtual_machine = Azure::ARM::Compute::Models::VirtualMachine.new
|
@@ -48,15 +48,19 @@ module Fog
|
|
48
48
|
vm_hash[:ssh_key_data],
|
49
49
|
encoded_data)
|
50
50
|
end
|
51
|
-
virtual_machine.network_profile = define_network_profile(vm_hash[:
|
51
|
+
virtual_machine.network_profile = define_network_profile(vm_hash[:network_interface_card_ids])
|
52
52
|
virtual_machine.location = vm_hash[:location]
|
53
53
|
begin
|
54
|
-
|
54
|
+
response = if async
|
55
|
+
@compute_mgmt_client.virtual_machines.create_or_update_async(vm_hash[:resource_group], vm_hash[:name], virtual_machine)
|
56
|
+
else
|
57
|
+
@compute_mgmt_client.virtual_machines.create_or_update(vm_hash[:resource_group], vm_hash[:name], virtual_machine)
|
58
|
+
end
|
55
59
|
rescue MsRestAzure::AzureOperationError => e
|
56
60
|
raise_azure_exception(e, msg)
|
57
61
|
end
|
58
|
-
Fog::Logger.debug "Virtual Machine #{vm_hash[:name]} Created Successfully."
|
59
|
-
|
62
|
+
Fog::Logger.debug "Virtual Machine #{vm_hash[:name]} Created Successfully." unless async
|
63
|
+
response
|
60
64
|
end
|
61
65
|
|
62
66
|
private
|
@@ -119,14 +123,17 @@ module Fog
|
|
119
123
|
os_disk.name = "#{vm_name}_os_disk"
|
120
124
|
os_disk.vhd = vhd
|
121
125
|
os_disk.create_option = Azure::ARM::Compute::Models::DiskCreateOptionTypes::FromImage
|
122
|
-
os_disk.caching =
|
126
|
+
os_disk.caching = unless os_disk_caching.nil?
|
127
|
+
case os_disk_caching
|
123
128
|
when 'None'
|
124
129
|
Azure::ARM::Compute::Models::CachingTypes::None
|
125
130
|
when 'ReadOnly'
|
126
131
|
Azure::ARM::Compute::Models::CachingTypes::ReadOnly
|
127
132
|
when 'ReadWrite'
|
128
133
|
Azure::ARM::Compute::Models::CachingTypes::ReadWrite
|
129
|
-
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
130
137
|
storage_profile.os_disk = os_disk
|
131
138
|
storage_profile
|
132
139
|
end
|
@@ -167,11 +174,17 @@ module Fog
|
|
167
174
|
os_profile
|
168
175
|
end
|
169
176
|
|
170
|
-
def define_network_profile(
|
177
|
+
def define_network_profile(network_interface_card_ids)
|
178
|
+
network_interface_cards = []
|
179
|
+
network_interface_card_ids.each_with_index do |id, index|
|
180
|
+
nic = Azure::ARM::Compute::Models::NetworkInterfaceReference .new
|
181
|
+
nic.id = id
|
182
|
+
nic.primary = index == PRIMARY_NIC_INDEX ? true : false
|
183
|
+
network_interface_cards << nic
|
184
|
+
end
|
185
|
+
|
171
186
|
network_profile = Azure::ARM::Compute::Models::NetworkProfile.new
|
172
|
-
|
173
|
-
nic.id = network_interface_card_id
|
174
|
-
network_profile.network_interfaces = [nic]
|
187
|
+
network_profile.network_interfaces = network_interface_cards
|
175
188
|
network_profile
|
176
189
|
end
|
177
190
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Fog
|
3
|
+
module Compute
|
4
|
+
class AzureRM
|
5
|
+
# Real class for Compute Request
|
6
|
+
class Real
|
7
|
+
def delete_managed_disk(resource_group_name, disk_name)
|
8
|
+
msg = "Deleting Managed Disk: #{disk_name}"
|
9
|
+
Fog::Logger.debug msg
|
10
|
+
begin
|
11
|
+
@compute_mgmt_client.disks.delete(resource_group_name, disk_name)
|
12
|
+
rescue MsRestAzure::AzureOperationError => e
|
13
|
+
raise_azure_exception(e, msg)
|
14
|
+
end
|
15
|
+
Fog::Logger.debug "Managed Disk #{disk_name} deleted successfully."
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Mock class for Compute Request
|
21
|
+
class Mock
|
22
|
+
def delete_managed_disk(*)
|
23
|
+
Fog::Logger.debug 'Managed Disk test-disk from Resource group fog-test-rg deleted successfully.'
|
24
|
+
true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -8,7 +8,7 @@ module Fog
|
|
8
8
|
Fog::Logger.debug msg
|
9
9
|
begin
|
10
10
|
@compute_mgmt_client.virtual_machines.delete(resource_group, name)
|
11
|
-
rescue
|
11
|
+
rescue MsRestAzure::AzureOperationError => e
|
12
12
|
raise_azure_exception(e, msg)
|
13
13
|
end
|
14
14
|
Fog::Logger.debug "Virtual Machine #{name} Deleted Successfully."
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Fog
|
2
|
+
module Compute
|
3
|
+
class AzureRM
|
4
|
+
# Real class for Compute Request
|
5
|
+
class Real
|
6
|
+
def get_managed_disk(resource_group_name, disk_name)
|
7
|
+
msg = "Getting Managed Disk: #{disk_name}"
|
8
|
+
Fog::Logger.debug msg
|
9
|
+
begin
|
10
|
+
managed_disk = @compute_mgmt_client.disks.get(resource_group_name, disk_name)
|
11
|
+
rescue MsRestAzure::AzureOperationError => e
|
12
|
+
raise_azure_exception(e, msg)
|
13
|
+
end
|
14
|
+
Fog::Logger.debug "Managed Disk #{disk_name} returned successfully."
|
15
|
+
managed_disk
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Mock class for Compute Request
|
20
|
+
class Mock
|
21
|
+
def get_managed_disk(*)
|
22
|
+
disk = {
|
23
|
+
'accountType' => 'Standard_LRS',
|
24
|
+
'properties' => {
|
25
|
+
'osType' => 'Windows',
|
26
|
+
'creationData' => {
|
27
|
+
'createOption' => 'Empty'
|
28
|
+
},
|
29
|
+
'diskSizeGB' => 10,
|
30
|
+
'encryptionSettings' => {
|
31
|
+
'enabled' => true,
|
32
|
+
'diskEncryptionKey' => {
|
33
|
+
'sourceVault' => {
|
34
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
|
35
|
+
},
|
36
|
+
'secretUrl' => 'https://myvmvault.vault-int.azure-int.net/secrets/{secret}'
|
37
|
+
},
|
38
|
+
'keyEncryptionKey' => {
|
39
|
+
'sourceVault' => {
|
40
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.KeyVault/vaults/myVMVault'
|
41
|
+
},
|
42
|
+
'keyUrl' => 'https://myvmvault.vault-int.azure-int.net/keys/{key}'
|
43
|
+
}
|
44
|
+
},
|
45
|
+
'timeCreated' => '2016-12-28T02:46:21.3322041+00:00',
|
46
|
+
'provisioningState' => 'Succeeded',
|
47
|
+
'diskState' => 'Unattached'
|
48
|
+
},
|
49
|
+
'type' => 'Microsoft.Compute/disks',
|
50
|
+
'location' => 'westus',
|
51
|
+
'tags' => {
|
52
|
+
'department' => 'Development',
|
53
|
+
'project' => 'ManagedDisks'
|
54
|
+
},
|
55
|
+
'id' => '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myManagedDisk1',
|
56
|
+
'name' => 'myManagedDisk1'
|
57
|
+
}
|
58
|
+
disk_mapper = Azure::ARM::Compute::Models::Disk.mapper
|
59
|
+
@compute_mgmt_client.deserialize(disk_mapper, disk, 'result.body')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|