Azure IaaS is awesome but…

AzureUnlocked

Azure IaaS (Infrastructure as a Service) is so unbelievably cool. You can make new VMs and delete them… wait. You can delete them, right? Well yes and no. You can delete the VM but for some unknown reason the disk image storage blob stays locked for … I don’t know. Forever? It’s very frustrating to me. In fact, it’s the only frustration thing I have found about Azure (aside from only being allowed to have one NIC per VM). So I did what I always do, wrote a tool. And that was great, but it didn’t benefit you, the reader. So now you can benefit! Here’s the code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
 
namespace ConsoleApplication1
{
    public static class AzureStorage
    {
        public static void BreakContainerLease(string AccountName, string AccountKey, string Container)
        {
            var account = new CloudStorageAccount(new StorageCredentialsAccountAndKey(AccountName, AccountKey), true);
            var client = new CloudBlobClient(account.BlobEndpoint, account.Credentials);
            var container = client.GetContainerReference(Container);
            container.BreakLease(new TimeSpan(0, 0, 1));
        }
 
        public static void BreakBlobLease(string AccountName, string AccountKey, string Container, string BlobName)
        {
            var account = new CloudStorageAccount(new StorageCredentialsAccountAndKey(AccountName, AccountKey), true);
            var client = new CloudBlobClient(account.BlobEndpoint, account.Credentials);
            var container = client.GetContainerReference(Container);
            var blob = container.GetBlobReference(BlobName);
            blob.BreakLease(new TimeSpan(0, 0, 1));
        }
    }
}

And as always, here’s the link to the running SSL encrypted version on my site: Azure Blob Unlocker!!!!

Leave a Reply