Пример #1
0
        public void SwitchOffVM()
        {
            if (virtualMachine == null)
            {
                return;
            }

            virtualMachine.PowerOff();
            DeallocateVM();
        }
Пример #2
0
        public void StopVirtualMachine(String resourceId)
        {
            Microsoft.Azure.Management.Fluent.IAzure azureCredentials =
                new AzureCredentialProvider().LoginAzure();

            Console.WriteLine("Deallocating Virtual Machine...");

            IVirtualMachine virtualMachine = azureCredentials.VirtualMachines.GetById(resourceId);

            virtualMachine.PowerOff();
            virtualMachine.Deallocate();
        }
Пример #3
0
        public void VMDiskReplacement()
        {
            string logMessage  = string.Empty;
            var    credentials = SdkContext.AzureCredentialsFactory.FromFile("servicePrincipleInformation.json");
            var    azure       = Microsoft.Azure.Management.Fluent.Azure
                                 .Configure()
                                 .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                                 .Authenticate(credentials)
                                 .WithDefaultSubscription();
            string resourceGroupName = this.txtBxResourceGroupName.Text;
            string vmName            = this.txtBxVnetwork.Text;

            IVirtualMachine vmList = azure.VirtualMachines.GetByResourceGroup(resourceGroupName, vmName);

            try
            {
                vmList.PowerOff();
                logMessage = String.Format("{0} VM turned off", vmList.Name);
                Utilities.Log(logMessage);
                this.lblCurrentStatus.Text = logMessage;
            }
            catch (Exception ex)
            {
                logMessage = String.Format("Error occurred {0}", ex.ToString());
                Utilities.Log(logMessage);
                this.lblCurrentStatus.Text = logMessage;
            }


            List <IDisk> dataDisks = new List <IDisk>();

            foreach (IDisk disk in vmList.DataDisks.Values)
            {
            }

            Utilities.Log("Selected subscription: " + azure.SubscriptionId);
            this.lblCurrentStatus.Text = "Selected subscription: " + azure.SubscriptionId;
        }