Categorygithub.com/Azure/skewer
modulepackage
0.0.19
Repository: https://github.com/azure/skewer.git
Documentation: pkg.go.dev

# README

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"

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

    "github.com/Azure/skewer"
)

func main() {
    // Create an authorizer
    authorizer, err := auth.NewAuthorizerFromEnvironment()
    if err != nil {
        fmt.Printf("failed to get authorizer: %s", err)
        os.Exit(1)
    }

    // Create a skus client
    client := compute.NewResourceSkusClient(sub)
    client.Authorizer = authorizer

    // Now we can use the client...
    resourceSkuIterator, err := client.ListComplete(context.Background(), "eastus")
    if err != nil {
        fmt.Printf("failed to list skus: %s", err)
        os.Exit(1)
    }

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

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 [email protected] with any additional questions or comments.

# Packages

No description provided by the author

# Functions

All returns true if the provided sku meets all provided conditions.
Filter returns a new slice containing all values in the slice that satisfy all filterFn predicates.
LocationFilter matches against a SKU listing the given location.
Map returns a new slice containing the results of applying the mapFn to each value in the original slice.
NameFilter produces a filter function for the name of a resource sku.
NewCache instantiates a cache of resource sku data with a ResourceClient client, optionally with additional filtering by location.
NewStaticCache initializes a cache with data and no ability to refresh.
ResourceTypeFilter produces a filter function for any resource type.
UnsafeLocationFilter produces a filter function for the location of a resource sku.
WithClient is a functional option to use a cache backed by a client meeting the skewer signature.
WithExtendedLocations is a functional option to include extended locations.
WithLocation is a functional option to filter skus by location.
WithResourceClient is a functional option to use a cache backed by a ResourceClient.
WithResourceProviderClient is a functional option to use a cache backed by a ResourceProviderClient.
Wrap takes an array of compute resource skus and wraps them into an array of our richer type.

# Constants

AcceleratedNetworking identifies the capability for accelerated networking support.
CachedDiskBytes identifies the maximum size of the cache disk for a vm.
CapabilityConfidentialComputingType identifies the type of ConfidentialComputing.
CapabilityCpuArchitectureType identifies the type of CPU architecture (x64,Arm64).
CapabilityPremiumIO identifies the capability for PremiumIO.
CapabilitySupported is an enum value for the string "True" returned when a SKU supports a binary capability.
CapabilityTrustedLaunchDisabled identifes whether TrustedLaunch is disabled.
CapabilityUnsupported is an enum value for the string "False" returned when a SKU does not support a binary capability.
ConfidentialComputingTypeSNP denoted the "SNP" ConfidentialComputing.
Disks is a convenience constant to filter resource SKUs to only include disks.
EncryptionAtHost identifies the capability for accelerated networking support.
EphemeralOSDisk identifies the capability for ephemeral os support.
GPUs identifies the capability for the number of GPUS.
HyperVGeneration1 identifies a sku which supports HyperV Generation 1.
HyperVGeneration2 identifies a sku which supports HyperV Generation 2.
HyperVGenerations identifies the hyper-v generations this vm sku supports.
MaxResourceVolumeMB identifies the maximum size of the temporary disk for a vm.
MemoryGB identifies the capability for memory capacity.
UltraSSDAvailable identifies the capability for ultra ssd enablement.
VCPUs identifies the capability for the number of vCPUS.
VirtualMachines is the .

# Structs

Cache stores a list of known skus, possibly fetched with a provided client.
Config contains configuration options for a cache.
ErrCapabilityNotFound will be returned when a capability could not be found, even without a value.
ErrCapabilityValueNil will be returned when a capability was found by name but the value was nil.
ErrCapabilityValueParse will be returned when a capability was found by name but there was error parsing the capability.
ErrClientNil will be returned when a user attempts to create a cache without a client and use it.
ErrClientNotNil will be returned when a user attempts to set two clients on the same cache.
ErrMultipleSKUsMatch will be returned when multiple skus match a fully qualified triple of resource type, location and name.
ErrSKUNotFound will be returned when no skus match a fully qualified triple of resource type, location and name.
No description provided by the author

# Interfaces

ResourceClient is the required Azure client interface used to populate skewer's data.
ResourceProviderClient is a convenience interface for uses cases specific to Azure resource providers.

# Type aliases

FilterFn is a convenience type for filtering.
MapFn is a convenience type for mapping.
NewCacheFunc describes the live cache instantiation signature.
Option describes functional options to customize the listing behavior of the cache.
SKU wraps an Azure compute SKU with richer functionality.
Supported models an enum of possible boolean values for resource support in the Azure API.