1

I have a PaaS VM role that need to be restart using Azure Management libraries. I tried following codes but failed with "BadRequest: The operation is not supported on a role of type MyPaaSVmName". But I successfully restarted IaaS VM using below Method1. Is it possible to restart a PaaS VM role using Azure Management Libraries? if not, is there any other way to achieve it using 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);

Thank you.

Vins007
  • 23
  • 4

2 Answers2

1

Found the issue, Method1 should be like this as I am restarting a Role Instance. Method2 is wrong.

client.Deployments.RebootRoleInstanceByDeploymentName(hostserviceName, deploymentName, roleName);
Vins007
  • 23
  • 4
1

Here's how you can do it using Azure Powershell:

ReSet-AzureRoleInstance -ServiceName "MySvc1" -Slot Staging -InstanceName "MyWebRole_IN_0" –reboot

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

And here's a snippet from an Azure Automation Runbook which can reboot all cloud service's instances, per update domain (so you have no downtime):

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
    } 
}
  • A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – davejal Dec 16 '15 at 00:13