小编Sor*_*eri的帖子

关闭VM会将所有VM状态恢复为未知状态

使用以下方法关闭和查询角色实例时.当我关闭VM时,将返回状态为ready state unknown的所有其他角色实例.大约几分钟后,我可以再次查询并获得实际状态.如何使用Azure Management API实时获取实际状态.或者这是如何配置VM的问题?它们配置有相同的存储位置和相同的虚拟网络

显示的代码基于Visual Studio 2015中的部署和管理虚拟机模板.

关闭VM的调用:

var shutdownParams = new VirtualMachineShutdownParameters();

if (deallocate)//deallocate is true in this instance
    shutdownParams.PostShutdownAction = PostShutdownAction.StoppedDeallocated; // Fully deallocate resources and stop billing
else
    shutdownParams.PostShutdownAction = PostShutdownAction.Stopped; // Just put the machine in stopped state, keeping resources allocated

await _computeManagementClient.VirtualMachines.ShutdownAsync(_parameters.CloudServiceName, _parameters.CloudServiceName, vmName, shutdownParams);
Run Code Online (Sandbox Code Playgroud)

对所有角色实例的查询调用 XXX_VirtualMachine是一个包含名称和实例状态的类:

internal List<XXX_VirtualMachine> GetAllVirtualMachines()
{
    List<XXX_VirtualMachine> vmList = new List<XXX_VirtualMachine>();
    try
    {
        DeploymentGetResponse deployment;

        deployment = _computeManagementClient.Deployments.GetByName(_parameters.CloudServiceName, _parameters.CloudServiceName);

        for (int i = 0; i < deployment.RoleInstances.Count; i++) …
Run Code Online (Sandbox Code Playgroud)

c# azure azure-virtual-machine azure-sdk-.net

13
推荐指数
1
解决办法
885
查看次数

标签 统计

azure ×1

azure-sdk-.net ×1

azure-virtual-machine ×1

c# ×1