Created
January 28, 2021 21:06
-
-
Save jamisonhyatt/20e01c5837c15165fca566bf459516c7 to your computer and use it in GitHub Desktop.
Check Available HDI VM Sizes by Region
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment