A package to simplify working with Azure's Resource SKU APIs by wrapping the existing Azure SDK for Go.
Перейти к файлу
Bryce Soghigian 6f2365e468
doc: adding example with compiling code for easier use for new users of skewer (#22)
* doc: adding example with compiling code for easier use for new users of skewer

* fix: removing comment
2023-10-06 10:32:08 -07:00
.github/workflows feat: initial commit 2020-08-25 16:23:43 -07:00
ci fix: go get vs go install dependencies (#17) 2023-07-10 15:30:22 -04:00
hack update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
testdata feat: add capabilties using vmsize-parsing (#19) 2023-08-23 17:00:07 -07:00
.gitignore feat: initial commit 2020-08-25 16:23:43 -07:00
.golangci.yml fix: interface break for 2021-12-01 api (#15) 2022-08-03 10:43:52 -04:00
CODE_OF_CONDUCT.md Initial CODE_OF_CONDUCT.md commit 2020-08-22 03:30:21 -07:00
LICENSE feat: initial commit 2020-08-25 16:23:43 -07:00
README.md doc: adding example with compiling code for easier use for new users of skewer (#22) 2023-10-06 10:32:08 -07:00
SECURITY.md Initial SECURITY.md commit 2020-08-22 03:30:24 -07:00
cache.go fix: interface break for 2021-12-01 api (#15) 2022-08-03 10:43:52 -04:00
cache_test.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
clients.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
const.go add more capabilities in skewer (#16) 2023-07-18 09:14:14 -07:00
data_test.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
fakes_test.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
go.mod feat: add capabilties using vmsize-parsing (#19) 2023-08-23 17:00:07 -07:00
go.sum feat: add capabilties using vmsize-parsing (#19) 2023-08-23 17:00:07 -07:00
interface.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
justfile feat: initial commit 2020-08-25 16:23:43 -07:00
sku.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
sku_test.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00
strings.go 💎 clarify method names and improve string comparisons 2020-10-30 17:49:56 -07:00
vmsize.go feat: capitalize vmsize struct fields (#20) 2023-09-01 12:58:57 -07:00
vmsize_test.go feat: capitalize vmsize struct fields (#20) 2023-09-01 12:58:57 -07:00
wrap.go update cloud-provider compute version to 2022-08-01 (#21) 2023-09-01 16:18:45 -07:00

README.md

skewer GoDoc codecov

A package to simplify working with Azure's Resource SKU APIs by wrapping the existing Azure SDK for Go.

Usage

This package requires an existing, authorized Azure client. Here is a complete example using the simplest methods.

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" //nolint:staticcheck
	"github.com/Azure/go-autorest/autorest/azure/auth"

	"github.com/Azure/skewer"
)

const (
	SubscriptionID = "AZURE_SUBSCRIPTION_ID"
	TenantID       = "AZURE_TENANT_ID"
	ClientID       = "AZURE_CLIENT_ID"
	ClientSecret   = "AZURE_CLIENT_SECRET"
)

func main() {
	os.Setenv(SubscriptionID, "subscriptionID")
	os.Setenv(TenantID, "TenantID")
	os.Setenv(ClientID, "AAD Client ID or AppID")
	os.Setenv(ClientSecret, "AADClientSecretHere")
	sub := os.Getenv(SubscriptionID)
	authorizer, err := auth.NewAuthorizerFromEnvironment()
	// Create a skus client
	client := compute.NewResourceSkusClient(sub)
	client.Authorizer = authorizer

	cache, err := skewer.NewCache(context.Background(), skewer.WithLocation("southcentralus"), skewer.WithResourceClient(client))
	if err != nil {
		fmt.Printf("failed to instantiate sku cache: %s", err)
		os.Exit(1)
	}

	for _, sku := range cache.List(context.Background()) {
		fmt.Printf("sku: %s\n", sku.GetName())
	}
}

Once we have a cache, we can query against its contents:

sku, found := cache.Get(context.Background, "standard_d4s_v3", skewer.VirtualMachines, "eastus")
if !found {
    return fmt.Errorf("expected to find virtual machine sku standard_d4s_v3")
}

// Check for capabilities
if sku.IsEphemeralOSDiskSupported() {
    fmt.Println("SKU %s supports ephemeral OS disk!", sku.GetName())
}

cpu, err := sku.VCPU()
if err != nil {
    return fmt.Errorf("failed to parse cpu from sku: %s", err)
}

memory, err := sku.Memory()
if err != nil {
    return fmt.Errorf("failed to parse memory from sku: %s", err)
}

fmt.Printf("vm sku %s has %d vCPU cores and %.2fGi of memory", sku.GetName(), cpu, memory)

Development

This project uses a simple justfile for make-like functionality. The commands are simple enough to run on their own if you do not want to install just.

For each command below like just $CMD, the full manual commands are below separated by one line.

Default: tidy, fmt, lint, test and calculate coverage.

$ just
$
$ go mod tidy
$ go fmt
$ golangci-lint run --fix
$ go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
$ go tool cover -html=coverage.out -o coverage.html

Clean up dependencies:

$ just tidy
$
$ go mod tidy

Format:

$ just fmt
$
$ go fmt

Lint:

$ just lint
$
$ golangci-lint run --fix

Test and calculate coverage:

$ just cover
$ 
$ go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
$ go tool cover -html=coverage.out -o coverage.html

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.