2

The title says it all. I've tried lots of things but I don't think any of them are worth mentioning. I have finally figured out to avoid Microsoft.WindowsAzure and have installed the Microsoft.Azure.Management.Compute and Microsoft.Azure.Common libraries.

I've finally got an authentication token like this:

var authenticationContext = new AuthenticationContext("https://login.windows.net/deadbeef-beef-beef-beef-ec74557498e8");
var credential = new ClientCredential("beefbeef-beef-beef-beef-b1d3cf5d037d", "passwordpasswordpasswordpasswordpasswordpas=");
var result = authenticationContext.AcquireTokenAsync("https://www.url.com/servicename", credential);

But now I'm struggling to use the documentation to learn to power on my VMs. I'm not even sure exactly where to start. All I know is I'd like to avoid the REST API and keep my code in C#. I'm looking for something like:

using (var client = new ComputeManagementClient(creds)) {
    foreach (var vm in client.VMs)
    {
        Console.WriteLine("Starting VM: {0}", vm.Name);

        vm.PowerOn();
    }
}
4

1 に答える 1

2

ARM ベースの VM を扱っていると仮定して、ARM ベースの VM を起動するコードを次に示します。"context" は、Microsoft.Azure.Management.Compute 名前空間の ComputeManagementClient です。

var result = VirtualMachinesOperationsExtensions.Start(context.VirtualMachines, azureResourceGroup, azureResourceName);

クラシック VM を扱っている場合は、これを開始するためのコードを次に示します。"context" は、Microsoft.WindowsAzure.Management.Compute 名前空間の ComputeManagementClient です。

var result = context.VirtualMachines.BeginStarting(serviceName, deploymentName,
                        instanceName);

また、独自のコードを記述して監視し、すべてが適切に機能することを確認するという頭痛の種をすべて回避し、CloudMonixを使用して Azure VM の起動とシャットダウンをスケジュールすることもできます。(私はサービスに所属しています)

于 2016-05-24T21:32:37.233 に答える