How to get VM architecture type using Go SDK? (x64 / arm64)

Amit Hayat 0 Reputation points
2023-07-03T12:58:49.36+00:00

Hi,

We list VMs with Azure SDK for Go, and need to know the VM arch.

Preferable, with 1 call to Azure (maybe with an extension / filter through list VMs API?)

Thanks,

Amit

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,035 questions
{count} votes

1 answer

Sort by: Most helpful
  1. derrickharrison 0 Reputation points
    2023-07-06T07:08:57.2733333+00:00

    Hi Amit,

    I have some suggestion for you Kindly go though it might helps you

    Follow below steps

    Import the necessary packages:
    go
    Copy code
    import (
        "context"
        "fmt"
        "google.golang.org/api/compute/v1"
        "google.golang.org/api/option"
    )
    Create a client and authenticate:
    go
    Copy code
    ctx := context.Background()
    client, err := compute.NewService(ctx, option.WithCredentialsFile("path/to/your/credentials.json"))
    if err != nil {
        // Handle error
    }
    Make sure to replace "path/to/your/credentials.json" with the actual path to your Google Cloud credentials file.
    
    Retrieve the instance information:
    go
    Copy code
    project := "your-project-id"
    zone := "your-zone"
    instance := "your-instance-name"
    
    resp, err := client.Instances.Get(project, zone, instance).Do()
    if err != nil {
        // Handle error
    }
    Replace "your-project-id", "your-zone", and "your-instance-name" with the appropriate values for your instance.
    
    Extract the architecture type: [TellHappyStar](https://www.tellhappystar.org/)
    go
    Copy code
    architecture := resp.CpuPlatform
    fmt.Printf("VM Architecture: %s\n", architecture)
    
    Thanks and regards
    derrickharrison
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.