vagrant-azure icon indicating copy to clipboard operation
vagrant-azure copied to clipboard

Blob (vhd file) not being deleted?

Open vmary2014 opened this issue 8 years ago • 9 comments

Hi Not sure if this is an option available or not but here is: When I create a VM on Azure, then destroy it, it appears the VHD file (127GB each time) remains in the container. Why is the VHD file not being destroyed? Is it possible to get it removed? Thanks Vincent

vmary2014 avatar Aug 26 '16 09:08 vmary2014

I'm also facing this issue. Any news, team?

matt-richardson avatar Jan 24 '17 02:01 matt-richardson

Is this still the case? Could you share your Vagrantfile (minus the sensitive info)?

devigned avatar Feb 02 '17 01:02 devigned

Yep, happens with 1.3.0:

Vagrant.configure(2) do |config|

  hostname = "vagrantdsc.local"
  config.vm.guest = :windows
  config.vm.communicator = "winrm"

  config.vm.synced_folder ".", "/vagrant", disabled: true

  if Vagrant.has_plugin?("vagrant-multi-hostsupdater")
    config.multihostsupdater.aliases = {ip_address => [hostname]}
  end

  config.vm.provider :azure do |azure, override|
    azure.mgmt_certificate = 'azure-management-cert.pem'
    azure.mgmt_endpoint = 'https://management.core.windows.net'
    azure.subscription_id = ENV['AZURE_SUBSCRIPTION_ID']
    azure.vm_image = 'fb83b3509582419d99629ce476bcb5c8__SqlServer-2016-RTM-13.0.1601.5-Web-ENU-WS2012R2-CY16-SU03v5'
    azure.vm_name = 'MyVM'
    azure.cloud_service_name = 'MyCloudService'
    azure.vm_password = ENV['AZURE_VM_PASSWORD']
    azure.storage_acct_name = 'my_storage_account'
    azure.vm_user = 'my_admin'
    azure.vm_size = 'Standard_DS2_v2'
    azure.vm_location = 'Australia East'
    azure.state_read_timeout = 600 # seconds
    azure.winrm_transport = [ 'https' ]
    azure.tcp_endpoints = '3389:53389' 
    override.vm.box = "dummy"
    override.vm.box_url = "azure.dummy.box"
  end
end

matt-richardson avatar Feb 02 '17 02:02 matt-richardson

Could a reasonable response to this be, please use 2.0.0.pre2 or greater?

devigned avatar Feb 02 '17 02:02 devigned

Unfortunately, not for my scenario, as I need to test against both ASM and ARM modes (its for an Azure VM extension).

matt-richardson avatar Feb 02 '17 02:02 matt-richardson

It looks like its not releasing the lease on the disk - not sure why

matt-richardson avatar Feb 02 '17 05:02 matt-richardson

Last I investigated this, that is exactly what I found @matt-richardson. The lease on the disk took too long to release and we give up trying to delete it.

I honestly didn't dig too deeply into it, but rather used a naming convention and a automated script to clean up after myself.

devigned avatar Feb 02 '17 18:02 devigned

Thats the approach I took:

disk_name=`azure vm disk list VM_NAME --json | grep -i "mediaLink" | sed 's/.*vhds\/\(.*\)\",/\1/'`

echo "Running 'vagrant destroy -f'"
vagrant destroy -f

echo "Cleaning up orphaned disk" # for some reason, its not releasing the lease, so its not deleting the disk
azure storage blob lease break --blob $disk_name --container vhds --account-name $AZURE_STORAGE_ACCOUNT_NAME --account-key $AZURE_STORAGE_ACCOUNT_KEY --duration 0
azure storage blob delete --blob $disk_name --container vhds --account-name $AZURE_STORAGE_ACCOUNT_NAME --account-key $AZURE_STORAGE_ACCOUNT_KEY --delete-snapshots include --quiet

It'd be better if we didn't have to do that though. I didn't notice for ages, then by chance, I found 25 x 127GB files in a storage account that I wasn't expecting, so I can see this impacting others.

matt-richardson avatar Feb 02 '17 18:02 matt-richardson

I think this could be added pretty simply through https://github.com/Azure/azure-storage-ruby/blob/master/lib/azure/storage/blob/blob.rb#L571.

devigned avatar Feb 02 '17 20:02 devigned