Inheritance: IBlobClient
コード例 #1
0
 /// <summary>
 /// Constructs a DeploymenTransaction class instance
 /// </summary>
 /// <param name="manager">The DeploymentManager class which has the transaction state and context necessary</param>
 public DeploymentTransaction(DeploymentManager manager)
 {
     _manager = manager;
     _blobClient = new BlobClient(_manager.SubscriptionId, Constants.DefaultBlobContainerName, _manager.StorageAccountName, _manager.StorageAccountKey);
 }
コード例 #2
0
        /// <summary>
        /// Deletes the virtual machine that has context with the client
        /// </summary>
        /// <param name="removeDisks">True if the underlying disks in blob storage should be removed</param>
        /// <param name="removeUnderlyingBlobs">Whether or not remove the blob as well as the OS disk</param>
        /// <param name="removeCloudService">Removes the cloud service container</param>
        /// <param name="removeStorageAccount">The storage account that the vhd is in</param>
        public void DeleteVirtualMachine(bool removeDisks = true, bool removeUnderlyingBlobs = true, bool removeCloudService = true, bool removeStorageAccount = true)
        {
            // set this if it hasn't been set yet
            PersistentVMRole vm = null;
            if (_vmRole == null)
                vm = VirtualMachine;

            // create the blob client
            string diskName = _vmRole.OSHardDisk.DiskName;
            string storageAccount = ParseBlobDetails(_vmRole.OSHardDisk.MediaLink);
            // create the blob client
            IBlobClient blobClient = new BlobClient(Properties.SubscriptionId, StorageContainerName, storageAccount, Properties.Certificate);

            // first delete the virtual machine command
            var deleteVirtualMachine = new DeleteVirtualMachineCommand(Properties)
                                           {
                                               SubscriptionId = Properties.SubscriptionId,
                                               Certificate = Properties.Certificate
                                           };
            try
            {
                deleteVirtualMachine.Execute();
            }
            catch (Exception)
            {
                // should be a 400 here if this is the case then there is only a single role in the deployment - quicker to do it this way!
                var deleteVirtualMachineDeployment = new DeleteVirtualMachineDeploymentCommand(Properties)
                                                         {
                                                             SubscriptionId = Properties.SubscriptionId,
                                                             Certificate = Properties.Certificate
                                                         };
                deleteVirtualMachineDeployment.Execute();
            }

            // when this is finished we'll delete the operating system disk - check this as we may need to putin a pause
            // remove the disk association
            DeleteNamedVirtualMachineDisk(diskName);
            // remove the data disks
            DeleteDataDisks(removeDisks ? blobClient : null);
            if (removeDisks)
            {
                // remove the physical disk
                blobClient.DeleteBlob(StorageFileName);
            }
            // remove the cloud services
            if (removeCloudService)
            {
                // delete the cloud service here
                var deleteCloudService = new DeleteHostedServiceCommand(Properties.CloudServiceName)
                                             {
                                                 SubscriptionId = Properties.SubscriptionId,
                                                 Certificate = Properties.Certificate
                                             };
                deleteCloudService.Execute();
            }
            // remove the storage account
            if (removeStorageAccount)
            {
                blobClient.DeleteStorageAccount();
            }
        }
コード例 #3
0
        /// <summary>
        /// Deletes the virtual machine that has context with the client
        /// </summary>
        /// <param name="removeDisks">True if the underlying disks in blob storage should be removed</param>
        /// <param name="removeUnderlyingBlobs">removes the underlying blob</param>
        /// <param name="removeCloudService">Removes the cloud service container</param>
        /// <param name="removeStorageAccount">The storage account that the vhd is in</param>
        public void DeleteVirtualMachine(bool removeDisks = true, bool removeUnderlyingBlobs = true, bool removeCloudService = true, bool removeStorageAccount = true)
        {
            //TODO: write a get method for the virtual machine properties
            IBlobClient blobClient = null;
            foreach (var vm in VirtualMachine)
            {
                // create the blob client
                string diskName = vm.OSHardDisk.DiskName;
                string storageAccount = ParseBlobDetails(vm.OSHardDisk.MediaLink);
                // create the blob client
                blobClient = new BlobClient(SubscriptionId, StorageContainerName, storageAccount, ManagementCertificate);

                // find the property
                var linuxVirtualMachineProperty = Properties.Find(a => a.RoleName == vm.RoleName);
                // if this property is null then we don't want it to impede the operation
                if (linuxVirtualMachineProperty == null)
                    continue;
                // first delete the virtual machine command
                var deleteVirtualMachine = new DeleteVirtualMachineCommand(linuxVirtualMachineProperty)
                    {
                        SubscriptionId = SubscriptionId,
                        Certificate = ManagementCertificate
                    };
                try
                {
                    deleteVirtualMachine.Execute();
                    Trace.WriteLine(String.Format("Deleted virtual machine {0}", linuxVirtualMachineProperty.HostName));
                }
                catch (Exception)
                {
                    if (VirtualMachine.Count == 1)
                    {
                        // should be a 400 here if this is the case then there is only a single role in the deployment - quicker to do it this way!
                        var deleteVirtualMachineDeployment =
                            new DeleteVirtualMachineDeploymentCommand(linuxVirtualMachineProperty)
                                {
                                    SubscriptionId = SubscriptionId,
                                    Certificate = ManagementCertificate
                                };
                        deleteVirtualMachineDeployment.Execute();
                    }
                }

                if (!removeDisks)
                    continue;

                // when this is finished we'll delete the operating system disk - check this as we may need to putin a pause
                // remove the disk association
                DeleteNamedVirtualMachineDisk(diskName);
                // remove the data disks
                DeleteDataDisks(vm, removeUnderlyingBlobs ? blobClient : null);
                if (removeUnderlyingBlobs)
                {
                    // remove the physical disk
                    blobClient.DeleteBlob(StorageFileName);
                }
            }
            // if we need to use the first cloud service
            // remove the cloud services
            if (removeCloudService)
            {
                // delete the cloud service here
                var deleteCloudService = new DeleteHostedServiceCommand(Properties[0].CloudServiceName)
                {
                    SubscriptionId = SubscriptionId,
                    Certificate = ManagementCertificate
                };
                deleteCloudService.Execute();
            }
            // remove the storage account
            if (removeStorageAccount)
            {
                blobClient.DeleteStorageAccount();
            }
        }
コード例 #4
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));
            }
        }
コード例 #5
0
        /// <summary>
        /// Deletes the virtual machine that has context with the client
        /// </summary>
        /// <param name="removeDisks">True if the underlying disks in blob storage should be removed</param>
        /// <param name="removeUnderlyingBlobs">removes the underlying blob</param>
        /// <param name="removeCloudService">Removes the cloud service container</param>
        /// <param name="removeStorageAccount">The storage account that the vhd is in</param>
        public void DeleteVirtualMachine(bool removeDisks = true, bool removeUnderlyingBlobs = true, bool removeCloudService = true, bool removeStorageAccount = true)
        {
            //TODO: write a get method for the virtual machine properties
            IBlobClient blobClient = null;

            foreach (var vm in VirtualMachine)
            {
                // create the blob client
                string diskName       = vm.OSHardDisk.DiskName;
                string storageAccount = ParseBlobDetails(vm.OSHardDisk.MediaLink);
                // create the blob client
                blobClient = new BlobClient(SubscriptionId, StorageContainerName, storageAccount, ManagementCertificate);

                // find the property
                var linuxVirtualMachineProperty = Properties.Find(a => a.RoleName == vm.RoleName);
                // if this property is null then we don't want it to impede the operation
                if (linuxVirtualMachineProperty == null)
                {
                    continue;
                }
                // first delete the virtual machine command
                var deleteVirtualMachine = new DeleteVirtualMachineCommand(linuxVirtualMachineProperty)
                {
                    SubscriptionId = SubscriptionId,
                    Certificate    = ManagementCertificate
                };
                try
                {
                    deleteVirtualMachine.Execute();
                    Trace.WriteLine(String.Format("Deleted virtual machine {0}", linuxVirtualMachineProperty.HostName));
                }
                catch (Exception)
                {
                    if (VirtualMachine.Count == 1)
                    {
                        // should be a 400 here if this is the case then there is only a single role in the deployment - quicker to do it this way!
                        var deleteVirtualMachineDeployment =
                            new DeleteVirtualMachineDeploymentCommand(linuxVirtualMachineProperty)
                        {
                            SubscriptionId = SubscriptionId,
                            Certificate    = ManagementCertificate
                        };
                        deleteVirtualMachineDeployment.Execute();
                    }
                }

                if (!removeDisks)
                {
                    continue;
                }

                // when this is finished we'll delete the operating system disk - check this as we may need to putin a pause
                // remove the disk association
                DeleteNamedVirtualMachineDisk(diskName);
                // remove the data disks
                DeleteDataDisks(vm, removeUnderlyingBlobs ? blobClient : null);
                if (removeUnderlyingBlobs)
                {
                    // remove the physical disk
                    blobClient.DeleteBlob(StorageFileName);
                }
            }
            // if we need to use the first cloud service
            // remove the cloud services
            if (removeCloudService)
            {
                // delete the cloud service here
                var deleteCloudService = new DeleteHostedServiceCommand(Properties[0].CloudServiceName)
                {
                    SubscriptionId = SubscriptionId,
                    Certificate    = ManagementCertificate
                };
                deleteCloudService.Execute();
            }
            // remove the storage account
            if (removeStorageAccount)
            {
                blobClient.DeleteStorageAccount();
            }
        }
コード例 #6
0
 public void PostProcess()
 {
     var extractor = new PublishSettingsExtractor(PublishSettings);
     var client = new StorageClient(SubscriptionId, extractor.AddPublishSettingsToPersonalMachineStore());
     var keys = client.GetStorageAccountKeys(StorageName);
     ConnectionString = String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageName, keys[0]);
     // put a container create process here - add this method to fluent!!!
     var blobClient = new BlobClient(SubscriptionId, "packages", StorageName, keys[0]);
     blobClient.CreatBlobContainer();
 }