Skip to content

Instantly share code, notes, and snippets.

@jamisonhyatt
Created January 28, 2021 21:06
Show Gist options
  • Select an option

  • Save jamisonhyatt/20e01c5837c15165fca566bf459516c7 to your computer and use it in GitHub Desktop.

Select an option

Save jamisonhyatt/20e01c5837c15165fca566bf459516c7 to your computer and use it in GitHub Desktop.

Revisions

  1. jamisonhyatt created this gist Jan 28, 2021.
    44 changes: 44 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    package main

    import (
    "context"
    "fmt"
    "github.com/Azure/azure-sdk-for-go/profiles/latest/hdinsight/mgmt/hdinsight"
    "github.com/Azure/go-autorest/autorest/azure/auth"
    "log"
    "strings"
    )

    func vmIsAvailableHDInsight(subscriptionID, region, vmSize string) bool {
    client := hdinsight.NewLocationsClient(subscriptionID)
    auth, err := auth.NewAuthorizerFromCLI()
    if err != nil {
    log.Fatal(err)
    }
    client.Authorizer = auth
    res, err := client.GetCapabilities(context.Background(), region)
    if err != nil {
    log.Print(err)
    }

    iaas, ok := res.VMSizes["iaas"]
    if !ok {
    log.Fatal("no iaas vms available")
    }
    vmSize = strings.ToUpper(strings.TrimSpace(vmSize))
    for _, vm := range *iaas.Available {
    if vm == vmSize {
    return true
    }
    }
    return false
    }

    func main() {
    region, vm := "eastus", "STANDARD_D5_V2"
    if vmIsAvailableHDInsight("{InsertYourSubscriptionID}", region, vm) {
    fmt.Printf("%s is available in %s\n", vm, region)
    } else {
    fmt.Printf("error! %s is NOT available in %s", vm, region)
    }
    }