lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.9.14 vs lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.9.15
- old
+ new
@@ -150,10 +150,11 @@
def delete_associated_resources(vmname, vmgroup, options = {})
options = {
:network_interfaces => true,
:ip_addresses => true,
:os_disk => true,
+ :data_disks => false,
:network_security_groups => false,
:storage_account => false,
:verbose => false
}.merge(options)
@@ -170,10 +171,14 @@
end
if options[:os_disk] || options[:storage_account]
delete_associated_disk(vm, options)
end
+
+ if options[:data_disks]
+ delete_associated_data_disks(vm, options)
+ end
end
def model_class
VirtualMachineModel
end
@@ -230,9 +235,23 @@
def delete_associated_disk(vm, options)
if vm.managed_disk?
delete_managed_storage(vm, options)
else
delete_unmanaged_storage(vm, options)
+ end
+ end
+
+ # This deletes any attached data disks that are associated with the
+ # virtual machine. Note that this should only happen after the VM
+ # has been deleted.
+ #
+ def delete_associated_data_disks(vm, options)
+ sds = Azure::Armrest::Storage::DiskService.new(configuration)
+ data_disks = vm.properties.storage_profile.try(:data_disks)
+
+ data_disks&.each do |data_disk|
+ disk = sds.get_by_id(data_disk.managed_disk.id)
+ delete_and_wait(sds, disk.name, disk.resource_group, options)
end
end
def delete_managed_storage(vm, options)
sds = Azure::Armrest::Storage::DiskService.new(configuration)