1

我有一个需要使用Azure管理库重新启动的PaaS VM角色。我尝试了以下代码,但因“BadRequest:该操作不支持类型为MyPaaSVmName的角色”而失败。但是我使用下面的Method1成功地重新启动了IaaS VM。 是否可以使用Azure管理库重新启动PaaS VM角色? 如果没有,是否有任何其他方式来实现它使用C#。以编程方式重新启动Azure VM角色(PaaS VM)

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); 

谢谢。

回答

1

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

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

这里是如何使用Azure的Powershell的做到这一点:

复位AzureRoleInstance -ServiceName “MySvc1” -Slot分期-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

$roleInstances = Get-AzureRole -ServiceName $cloudServiceName -Slot Production -InstanceDetails 
Write-Output "Retrieved all role instances for cloud service: $cloudServiceName. Number of instances: " + $roleInstances.Count 

# Group instances per update domain 
$roleInstanceGroups = $roleInstances | Group-Object -AsHashTable -AsString -Property InstanceUpgradeDomain 
Write-Output "Number of update domains found: " + $roleInstanceGroups.Keys.Count 

# Visit each update domain 
foreach ($key in $roleInstanceGroups.Keys) 
{ 
    $count = $perDomainInstances.Count; 
    Write-Output "Rebooting $count instances in domain $key"  

    $perDomainInstances = $roleInstanceGroups.Get_Item($key) 

    foreach -parallel($instance in $perDomainInstances) 
    { 
     $instanceName = $instance.InstanceName 
     Write-Output "Rebooting instance $instanceName" 

     Reset-AzureRoleInstance -ServiceName $cloudServiceName -Slot Production -InstanceName $instanceName -Reboot -ErrorAction Stop 
    } 
} 
+0

链接到一个潜在的解决方案总是受欢迎的,但请周围添加链接方面,以便其他用户将有一些想法是什么,为什么它的存在。如果目标网站无法访问或永久离线,请始终引用重要链接中最相关的部分。 – davejal 2015-12-16 00:13:20