Beispiel #1
0
        /// <summary>
        /// Cleans up any disks which don't have an attached VM
        /// </summary>
        public void CleanupUnattachedDisks()
        {
            // get all of the disks in the subscription
            var command = new GetVirtualDisksCommand()
            {
                SubscriptionId = SubscriptionId,
                Certificate    = ManagementCertificate
            };

            command.Execute();
            var disks = command.Disks;

            // initiate the blob delete

            // iterate through the disks and clean up the unattached ones
            foreach (var disk in disks)
            {
                // get the blob details
                //string storageAccount = ParseBlobDetails(disk.MediaLink);
                //IBlobClient blobClient = new BlobClient(SubscriptionId, StorageContainerName, storageAccount, ManagementCertificate);
                DeleteNamedVirtualMachineDisk(disk.Name);
                // delete the underlying blob
                //blobClient.DeleteBlob(disk.Name);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Cleans up any disks which don't have an attached VM
        /// </summary>
        public void CleanupUnattachedDisks()
        {
            // get all of the disks in the subscription
            var command = new GetVirtualDisksCommand()
            {
                SubscriptionId = SubscriptionId,
                Certificate    = ManagementCertificate
            };

            command.Execute();
            var disks = command.Disks;

            // initiate the blob delete

            // iterate through the disks and clean up the unattached ones
            foreach (var disk in disks)
            {
                // make sure the disk is unattached
                if (disk.VM != null)
                {
                    continue;
                }
                // get the blob details
                string      storageAccount = ParseBlobDetails(disk.MediaLink);
                IBlobClient blobClient     = new BlobClient(SubscriptionId, StorageContainerName, storageAccount, ManagementCertificate);
                DeleteNamedVirtualMachineDisk(disk.Name);
                Trace.WriteLine(String.Format("Deleting disk with name {0}", disk.Name));
                // delete the underlying blob
                blobClient.DeleteBlob(StorageFileName);
                Trace.WriteLine(String.Format("Deleting disk with name {0}", StorageFileName));
            }
        }