Used to delete a hosted service given a service name
Наследование: ServiceCommand
Пример #1
0
 /// <summary>
 /// Used to delete the current cloud service
 /// </summary>
 public void DeleteCloudService()
 {
     // delete the hosted service
     var deleteService = new DeleteHostedServiceCommand(Name)
     {
         Certificate = ManagementCertificate,
         SubscriptionId = SubscriptionId
     };
     deleteService.Execute();
 }
 /// <summary>
 /// Deletes a deployment to make space for a new one!
 /// </summary>
 private void DeleteHostedService()
 {
     // most likely there is something in the slot ...
     var deleteHostedService = new DeleteHostedServiceCommand(_manager.HostedServiceName)
                                   {
                                       Certificate = _manager.ManagementCertificate,
                                       SubscriptionId = _manager.SubscriptionId
                                   };
     deleteHostedService.Execute();
 }
        /// <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();
            }
        }
        /// <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();
            }
        }
Пример #5
0
 /// <summary>
 /// Deletes a cloud service and removes all of the .vhds for vms associated with the production deployment
 /// </summary>
 /// <param name="deploymentName">The name of the deployment to delete</param>
 public void DeleteCloudServiceAndDeployment(string deploymentName)
 {
     var command = new DeleteCloudServiceAndDeploymentCommand(Name, deploymentName)
     {
         SubscriptionId = SubscriptionId,
         Certificate = ManagementCertificate
     };
     command.Execute();
     var csDelete = new DeleteHostedServiceCommand(Name)
     {
         SubscriptionId = SubscriptionId,
         Certificate = ManagementCertificate
     };
     csDelete.Execute();
 }
 public void Delete()
 {
     try
     {
         var deleteDeployment = new DeleteDeploymentCommand(_manager.HostedServiceName, DeploymentSlot.Production)
                                    {
                                        Certificate = _manager.ManagementCertificate,
                                        SubscriptionId = _manager.SubscriptionId
                                    };
         deleteDeployment.Execute();
         deleteDeployment.DeploymentSlot = DeploymentSlot.Staging;
         deleteDeployment.Execute();
     }
     catch (Exception)
     {
         // no deployment here who cares!
     }
     // delete the hosted service
     var deleteService = new DeleteHostedServiceCommand(_manager.HostedServiceName)
                             {
                                 Certificate = _manager.ManagementCertificate,
                                 SubscriptionId = _manager.SubscriptionId
                             };
     deleteService.Execute();
 }