lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.9.3 vs lib/azure/armrest/virtual_machine_service.rb in azure-armrest-0.9.4

- old
+ new

@@ -2,17 +2,17 @@ module Azure # Armrest namespace module Armrest # Base class for managing virtual machines class VirtualMachineService < ResourceGroupBasedService - # Create and return a new VirtualMachineService (VMM) instance. Most - # methods for a VMM instance will return one or more VirtualMachine - # instances. + # Create and return a new VirtualMachineService instance. Most + # methods for a VirtualMachineService instance will return one or more + # VirtualMachine instances. # # This subclass accepts the additional :provider option as well. The - # default is 'Microsoft.ClassicCompute'. You may need to set this to - # 'Microsoft.Compute' for your purposes. + # default is 'Microsoft.Compute'. You may need to set this to + # 'Microsoft.ClassicCompute' for your purposes. # def initialize(configuration, options = {}) super(configuration, 'virtualMachines', 'Microsoft.Compute', options) end @@ -190,13 +190,17 @@ nics.each do |nic_id_string| nic = get_by_id(nic_id_string) delete_and_wait(nis, nic.name, nic.resource_group, options) if options[:ip_addresses] - nic.properties.ip_configurations.each do |ip| - ip = get_by_id(ip.properties.public_ip_address.id) - delete_and_wait(ips, ip.name, ip.resource_group, options) + nic.properties.ip_configurations.each do |ipconfig| + address = ipconfig.properties.try(:public_ip_address) + + if address + ip = get_by_id(address.id) + delete_and_wait(ips, ip.name, ip.resource_group, options) + end end end if options[:network_security_groups] if nic.properties.respond_to?(:network_security_group) @@ -214,9 +218,23 @@ # If the option to delete the entire storage account was selected, then # it will not bother with deleting invidual files from the storage # account first. # def delete_associated_disk(vm, options) + if vm.managed_disk? + delete_managed_storage(vm, options) + else + delete_unmanaged_storage(vm, options) + end + end + + def delete_managed_storage(vm, options) + sds = Azure::Armrest::Storage::DiskService.new(configuration) + disk = sds.get_by_id(vm.properties.storage_profile.os_disk.managed_disk.id) + delete_and_wait(sds, disk.name, disk.resource_group, options) + end + + def delete_unmanaged_storage(vm, options) sas = Azure::Armrest::StorageAccountService.new(configuration) storage_account = sas.get_from_vm(vm) # Deleting the storage account does not require deleting the disks