lunedì, dicembre 16, 2013

New Azure Storage Client not compatible with current Storage Emulator

Bad news. Azure Storage Client 3.0 and 3.0.1 is not compatible with Storage Emulator 2.2 (the current version). You will get a generic "The remote server returned an error: (400) Bad Request." on CreateIfNotExists().

No mention on releses https://github.com/WindowsAzure/azure-storage-net/blob/master/README.md
Info here: http://blogs.msdn.com/b/windowsazurestorage/archive/2013/11/27/windows-azure-storage-release-introducing-cors-json-minute-metrics-and-more.aspx

:(




sabato, dicembre 14, 2013

Calculate space used by VHD on Azure Blob Storage

A piece of code to calculate space used by VHD files (Azure Virtual Machine) on Azure Blob Storage.
Code adapted (and fixed) from a previous post of Michel Chi http://nettecharticles.blogspot.tw/2012/12/azurevhdcharge.html


        public static void Exec()
        {
            string accountName = ".......";
            string keyValue = ".......";

            Console.WriteLine("UTC NOW : " + DateTime.UtcNow);

            float GB = (1024 * 1024 * 1024);
            float totalBytes = 0;

            var storage = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, keyValue), false);
            var blobClient = storage.CreateCloudBlobClient();
            var vhds = blobClient.GetContainerReference("vhds");
            var blobs = vhds.ListBlobs();

            foreach (var blob in blobs)
            {
                var pageBlob = vhds.GetPageBlobReference(blob.Uri.Segments.Last());
                pageBlob.FetchAttributes();
                var pageRanges = pageBlob.GetPageRanges();

                float vhdBytes = pageRanges.Sum(x => x.EndOffset - x.StartOffset);

                totalBytes += vhdBytes;

                Console.WriteLine(new string('-', 60));
                Console.WriteLine("ID         = " + blob.Uri.Segments.Last());
                Console.WriteLine("Used GB    = " + vhdBytes / GB);
                Console.WriteLine("DailyUsage = " + vhdBytes / GB / 31.0);
                Console.WriteLine("PageRanges = " + pageRanges.Count());                

            }

            Console.WriteLine(new string('-', 60));
            Console.WriteLine("Total GB    : " + totalBytes / GB);
            Console.WriteLine("Daily usage : " + totalBytes / GB / 31.0);

            Console.WriteLine(new string('-', 60));
        }