0
votes

Is it possible to get list of ClassicCompute virtual machines and manage them using Azure resource manager libraries?

VMs and storage accounts created using Azure preview portal are also of Classic version.

Is it not supported to create V2 VMs using azure preview portal or am i missing any settings?

3

3 Answers

1
votes

It would appear that the Azure preview Portal has been recently updated to allow you to choose if you want "classic" vms or vms using the new ARM templates.

To do this:

Goto "New", select your template such as "Windows Server 2012 R2 Datacenter", and in the drop down box above the "Create" command button, there is a section titled "Select a compute stack." This will let you select "Use the Service Management stack (classic)" - (ie V1 classic compute) or "Use the Resource Manager Stack" - (ie V2 classic compute).

Hope that helps!

0
votes

Azure preview portal support both V1 and V2 VMs. You can create a V2 VM using Browse All -> Virtual Machines, and create a V1 VM using Browse All -> Virtual Machines (classic)

0
votes

You can get a list of V1 & V2 VMs using the code below. ListRecursiveAsync() is just an extension method I threw together to deal with the possibility of more than one page of results.

Also for understanding the capabilities of the ARM API in general, the Azure Resource Explorer) is a great tool.

    using (var client = new ResourceManagementClient(creds))
    {
        var v1ComputeParams = new ResourceListParameters { ResourceType = "Microsoft.ClassicCompute/virtualMachines" };
        var v2ComputeParams = new ResourceListParameters { ResourceType = "Microsoft.Compute/virtualMachines" };

        var v1ComputeResult = await client.ListRecursiveAsync(v1ComputeParams, null);
        var v2ComputeResult = await client.ListRecursiveAsync(v2ComputeParams, null);
    }

/// <summary>
/// Gets the list of resources, recursing until ResourceListResult.NextLink is empty. 
/// </summary>
/// <param name="client"></param>
/// <param name="parameters">Optional. Query parameters. If null is passed returns all resources from all resource groups.</param>
/// <param name="nextLink"></param>
/// <returns></returns>
public static async Task<IList<GenericResourceExtended>> ListRecursiveAsync(this ResourceManagementClient client, ResourceListParameters listParams, string nextLink)
{
    var rValue = new List<GenericResourceExtended>();

    ResourceListResult computeList = null;

    if (!string.IsNullOrWhiteSpace(nextLink))
    {
        computeList = await client.Resources.ListNextAsync(nextLink);
    }
    else
    {
        computeList = await client.Resources.ListAsync(listParams);
    }

    rValue.AddRange(computeList.Resources);

    if (!string.IsNullOrWhiteSpace(computeList.NextLink))
    {
        var nextResult = await ListRecursiveAsync(client, null, computeList.NextLink);
        rValue.AddRange(nextResult);
    }

    return rValue;
}