如何以编程方式重新启动Azure VM角色(PaaS VM)

时间:2014-12-03 16:43:03

标签: azure azure-web-roles azure-management azure-management-api

我有一个需要使用Azure管理库重新启动的PaaS VM角色。我尝试使用以下代码,但使用" BadRequest失败:MyPaaSVmName"类型的角色不支持该操作。但是我使用下面的Method1成功重启了IaaS VM。 是否可以使用Azure管理库重新启动PaaS VM角色? 如果没有,有没有其他方法可以使用c#实现它。

1

ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
client.VirtualMachines.Restart(hostedServiceName, deploymentName, vmName);

2

ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
VirtualMachineOperationsExtensions.Restart(client.VirtualMachines, hostserviceName, deploymentName, vmName);

谢谢。

2 个答案:

答案 0 :(得分:1)

发现问题, 当我重新启动角色实例时,Method1应该是这样的。 Method2错了。

client.Deployments.RebootRoleInstanceByDeploymentName(hostserviceName, deploymentName, roleName);

答案 1 :(得分:1)

以下是使用Azure Powershell执行此操作的方法:

ReSet-AzureRoleInstance -ServiceName“MySvc1”-Slot Staging -InstanceName“MyWebRole_IN_0”-reboot

https://msdn.microsoft.com/en-us/library/azure/dn495202.aspx

以下是Azure自动化Runbook的一个片段,它可以重新启动所有云服务的实例,每个更新域(因此您没有停机时间):

https://gallery.technet.microsoft.com/Reboot-Cloud-Service-PaaS-b337a06d

assert("2")
相关问题