示例#1
0
        /// <summary>
        ///     Break leases on vhd blobs
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <param name="vhdBlobContainer"></param>
        public void BreakVhdLeases(string hostedServiceName, string vhdBlobContainer = "vhds")
        {
            var storageManager = new AzureStorageServiceManager();
            var vhdManager     = new AzureVirtualMachineManager();
            var vhdsLeased     = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);

            foreach (var vhd in vhdsLeased)
            {
                var storage = storageManager.GetStorageServiceForBlob(vhd.MediaLinkUri);
                var blob    = storage.GetBlob(Path.GetFileName(vhd.MediaLinkUri.ToString()), vhdBlobContainer);

                TestEasyLog.Instance.Info("Breaking lease on [" + blob.Uri + "]");

                blob.BreakLease(TimeSpan.FromSeconds(1));
            }

            TestEasyLog.Instance.Info("Waiting for VHDs to be released");
            // now wait a short while for the lease to actually expire.
            RetryHelper.RetryUntil(() =>
            {
                var remainingVhdsLeased = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);
                return(!remainingVhdsLeased.Any());
            }, 30, TimeSpan.FromSeconds(5));
        }
示例#2
0
        /// <summary>
        ///     Get storage accounts that are used by hosted service
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <returns></returns>
        public IList <StorageAccount> GetStorageAccountsUsedByHostedService(string hostedServiceName)
        {
            var uniqueStorageAccounts = new HashSet <StorageAccount>();
            var storageManager        = new AzureStorageServiceManager();
            var vhdManager            = new AzureVirtualMachineManager();
            var vhdsLeased            = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);

            foreach (var vhd in vhdsLeased)
            {
                var storageAccount = storageManager.GetStorageServiceForBlob(vhd.MediaLinkUri);
                uniqueStorageAccounts.Add(storageAccount);
            }

            return(uniqueStorageAccounts.ToList());
        }
        /// <summary>
        ///     Break leases on vhd blobs
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <param name="vhdBlobContainer"></param>
        public void BreakVhdLeases(string hostedServiceName, string vhdBlobContainer = "vhds")
        {
            var storageManager = new AzureStorageServiceManager();
            var vhdManager = new AzureVirtualMachineManager();
            var vhdsLeased = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);
            foreach (var vhd in vhdsLeased)
            {
                var storage = storageManager.GetStorageServiceForBlob(vhd.MediaLinkUri);
                var blob = storage.GetBlob(Path.GetFileName(vhd.MediaLinkUri.ToString()), vhdBlobContainer);

                TestEasyLog.Instance.Info("Breaking lease on [" + blob.Uri + "]");

                blob.BreakLease(TimeSpan.FromSeconds(1));
            }

            TestEasyLog.Instance.Info("Waiting for VHDs to be released");
            // now wait a short while for the lease to actually expire.
            RetryHelper.RetryUntil(() =>
            {
                var remainingVhdsLeased = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);
                return !remainingVhdsLeased.Any();
            }, 30, TimeSpan.FromSeconds(5));
        }
        /// <summary>
        ///     Get storage accounts that are used by hosted service
        /// </summary>
        /// <param name="hostedServiceName"></param>
        /// <returns></returns>
        public IList<StorageAccount> GetStorageAccountsUsedByHostedService(string hostedServiceName)
        {
            var uniqueStorageAccounts = new HashSet<StorageAccount>();
            var storageManager = new AzureStorageServiceManager();
            var vhdManager = new AzureVirtualMachineManager();
            var vhdsLeased = vhdManager.GetVirtualHardDisks().Where(vhd => vhd.UsageDetails.HostedServiceName == hostedServiceName);
            foreach (var vhd in vhdsLeased)
            {
                var storageAccount = storageManager.GetStorageServiceForBlob(vhd.MediaLinkUri);
                uniqueStorageAccounts.Add(storageAccount);
            }

            return uniqueStorageAccounts.ToList();
        }