skewer

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 25, 2020 License: MIT Imports: 6 Imported by: 0

README

skewer codecov

This package wraps the Azure SDK for Go clients to simplify working with Azure's Resource SKU APIs.

Documentation

Index

Constants

View Source
const (
	// VirtualMachines is the .
	VirtualMachines = "virtualMachines"
	// Disks is a convenience constant to filter resource SKUs to only include disks.
	Disks = "disks"
)
View Source
const (
	// EphemeralOSDisk identifies the capability for ephemeral os support.
	EphemeralOSDisk = "EphemeralOSDiskSupported"
	// AcceleratedNetworking identifies the capability for accelerated networking support.
	AcceleratedNetworking = "AcceleratedNetworkingEnabled"
	// VCPUs identifies the capability for the number of vCPUS.
	VCPUs = "vCPUs"
	// MemoryGB identifies the capability for memory capacity.
	MemoryGB = "MemoryGB"
	// HyperVGenerations identifies the hyper-v generations this vm sku supports.
	HyperVGenerations = "HyperVGenerations"
	// EncryptionAtHost identifies the capability for accelerated networking support.
	EncryptionAtHost = "EncryptionAtHostSupported"
	// UltraSSDAvailable identifies the capability for ultra ssd
	// enablement.
	UltraSSDAvailable = "UltraSSDAvailable"
	// CachedDiskBytes identifies the maximum size of the cach disk for
	// a vm.
	CachedDiskBytes = "CachedDiskBytes"
)

Variables

This section is empty.

Functions

func All

func All(sku *SKU, conditions []FilterFn) bool

All returns true if the provided sku meets all provided conditions.

func NameFilter

func NameFilter(name string) func(*SKU) bool

NameFilter produces a filter function for the name of a resource sku.

func ResourceTypeFilter

func ResourceTypeFilter(resourceType string) func(*SKU) bool

ResourceTypeFilter produces a filter function for any resource type.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache stores a list of known skus, possibly fetched with a provided client

func NewCache

func NewCache(ctx context.Context, opts ...CacheOption) (*Cache, error)

NewCache instantiates a cache of resource sku data with a ResourceClient client, optionally with additional filtering by location. The accepted client interface matches the real Azure clients (it returns a paginated iterator).

func NewStaticCache

func NewStaticCache(data []SKU, opts ...CacheOption) (*Cache, error)

NewStaticCache initializes a cache with data and no ability to refresh. Used for testing.

func (*Cache) Equal

func (c *Cache) Equal(other *Cache) bool

Equal compares two caches.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, name, resourceType string) (SKU, bool)

Get returns the first matching resource of a given name and type in a location.

func (*Cache) GetAvailabilityZones

func (c *Cache) GetAvailabilityZones(ctx context.Context, filters ...FilterFn) []string

GetAvailabilityZones returns the list of all availability zones in a given azure location.

func (*Cache) GetVirtualMachineAvailabilityZones

func (c *Cache) GetVirtualMachineAvailabilityZones(ctx context.Context) []string

GetVirtualMachineAvailabilityZones returns all virtual machine zones available in a given location.

func (*Cache) GetVirtualMachineAvailabilityZonesForSize

func (c *Cache) GetVirtualMachineAvailabilityZonesForSize(ctx context.Context, size string) []string

GetVirtualMachineAvailabilityZonesForSize returns all virtual machine zones available in a given location.

func (*Cache) GetVirtualMachines

func (c *Cache) GetVirtualMachines(ctx context.Context) []SKU

GetVirtualMachines returns the list of all virtual machines *SKUs in a given azure location.

func (*Cache) List

func (c *Cache) List(ctx context.Context, filters ...FilterFn) []SKU

List returns all resource types for this location.

type CacheOption

type CacheOption func(c *Cache) error

CacheOption describes functional options to customize the listing behavior of the cache.

func WithClient

func WithClient(client client) CacheOption

WithClient is a functional option to use a cache backed by a client meeting the skewer signature.

func WithLocation

func WithLocation(location string) CacheOption

WithLocation is a functional option to filter skus by location

func WithResourceClient

func WithResourceClient(client ResourceClient) CacheOption

WithResourceClient is a functional option to use a cache backed by a ResourceClient.

func WithResourceProviderClient

func WithResourceProviderClient(client ResourceProviderClient) CacheOption

WithResourceProviderClient is a functional option to use a cache backed by a ResourceProviderClient.

type ErrCapabilityNotFound

type ErrCapabilityNotFound struct {
	// contains filtered or unexported fields
}

ErrCapabilityNotFound will be returned when a capability could not be found, even without a value.

func (*ErrCapabilityNotFound) Error

func (e *ErrCapabilityNotFound) Error() string

type ErrCapabilityValueNil

type ErrCapabilityValueNil struct {
	// contains filtered or unexported fields
}

ErrCapabilityValueNil will be returned when a capability was found by name but the value was nil.

func (*ErrCapabilityValueNil) Error

func (e *ErrCapabilityValueNil) Error() string

type ErrCapabilityValueParse

type ErrCapabilityValueParse struct {
	// contains filtered or unexported fields
}

ErrCapabilityValueParse will be returned when a capability was found by name but the value was nil.

func (*ErrCapabilityValueParse) Error

func (e *ErrCapabilityValueParse) Error() string

type ErrClientNil

type ErrClientNil struct {
}

ErrClientNil will be returned when a user attempts to create a cache without a client and use it.

func (*ErrClientNil) Error

func (e *ErrClientNil) Error() string

type ErrClientNotNil

type ErrClientNotNil struct {
}

ErrClientNotNil will be returned when a user attempts to set two clients on the same cache.

func (*ErrClientNotNil) Error

func (e *ErrClientNotNil) Error() string

type FilterFn

type FilterFn func(*SKU) bool

FilterFn is a convenience type for filtering.

type LazyCacheCreator

type LazyCacheCreator struct {
	// contains filtered or unexported fields
}

LazyCacheCreator is a convenience type for lazily instantiating caches.

func NewLazyCacheCreator

func NewLazyCacheCreator() *LazyCacheCreator

NewLazyCacheCreator instantiates a lazy cache creator.

func (*LazyCacheCreator) GetCache

func (l *LazyCacheCreator) GetCache(ctx context.Context, opts ...CacheOption) (*Cache, error)

GetCache returns the wrapped cache or instantiates a new one, storing it before returning a reference to it.

type MapFn

type MapFn func(*SKU) SKU

MapFn is a convenience type for mapping.

type NewCacheFunc

type NewCacheFunc func(ctx context.Context, opts ...CacheOption) (*Cache, error)

NewCacheFunc describes the live cache instantiation signature. Used for testing.

type ResourceClient

type ResourceClient interface {
	ListComplete(ctx context.Context, filter string) (compute.ResourceSkusResultIterator, error)
}

ResourceClient is the required Azure client interface used to populate skewer's data.

type ResourceProviderClient

type ResourceProviderClient interface {
	List(ctx context.Context, filter string) (compute.ResourceSkusResultPage, error)
}

ResourceProviderClient is a convenience interface for uses cases specific to Azure resource providers.

type SKU

type SKU compute.ResourceSku

SKU wraps an Azure compute SKU with richer functionality

func Filter

func Filter(skus []SKU, filterFn ...FilterFn) []SKU

Filter returns a new slice containing all values in the slice that satisfy all filterFn predicates.

func Map

func Map(skus []SKU, fn MapFn) []SKU

Map returns a new slice containing the results of applying the mapFn to each value in the original slice.

func (*SKU) AvailabilityZones

func (s *SKU) AvailabilityZones(location string) map[string]bool

AvailabilityZones returns the list of Availability Zones which have this resource SKU available and unrestricted.

func (*SKU) Equal

func (s *SKU) Equal(other *SKU) bool

Equal returns true when two skus have the same location, type, and name.

func (*SKU) GetCapabilityQuantity

func (s *SKU) GetCapabilityQuantity(name string) (int64, error)

GetCapabilityQuantity retrieves and parses the value of a numeric capability with the provided name. It errors if the capability is not found, the value was nil, or the value could not be parsed as an integer.

func (*SKU) GetLocation

func (s *SKU) GetLocation() string

GetLocation returns the first found location on this *SKU resource. Typically only one should be listed (multiple SKU results will be returned for multiple regions). We fallback to locationInfo although this appears to be duplicate info.

func (*SKU) GetName

func (s *SKU) GetName() string

GetName returns the name of this resource sku. It normalizes pointers to the empty string for comparison purposes. For example, "Standard_D8s_v3" for a virtual machine.

func (*SKU) GetResourceType

func (s *SKU) GetResourceType() string

GetResourceType returns the name of this resource sku. It normalizes pointers to the empty string for comparison purposes. For example, "virtualMachines" for a virtual machine.

func (*SKU) HasCapability

func (s *SKU) HasCapability(name string) bool

HasCapability return true for a capability which can be either supported or not. Examples include "EphemeralOSDiskSupported", "EncryptionAtHostSupported", "AcceleratedNetworkingEnabled", and "RdmaEnabled"

func (*SKU) HasCapabilityWithCapacity

func (s *SKU) HasCapabilityWithCapacity(name string, value int64) (bool, error)

HasCapabilityWithCapacity returns true when the provided resource exposes a numeric capability and the maximum value exposed by that capability exceeds the value requested by the user. Examples include "MaxResourceVolumeMB", "OSVhdSizeMB", "vCPUs", "MemoryGB","MaxDataDiskCount", "CombinedTempDiskAndCachedIOPS", "CombinedTempDiskAndCachedReadBytesPerSecond", "CombinedTempDiskAndCachedWriteBytesPerSecond", "UncachedDiskIOPS", and "UncachedDiskBytesPerSecond"

func (*SKU) HasCapabilityWithSeparator

func (s *SKU) HasCapabilityWithSeparator(name, value string) bool

HasCapabilityWithSeparator return true for a capability which may be exposed as a comma-separated list. We check that the list contains the desired substring. An example is "HyperVGenerations" which may be "V1,V2"

func (*SKU) HasZonalCapability

func (s *SKU) HasZonalCapability(name string) bool

HasZonalCapability return true for a capability which can be either supported or not. Examples include "UltraSSDAvailable". This function only checks that zone details suggest support: it will return true for a whole location even when only one zone supports the feature. Currently, the only real scenario that appears to use zoneDetails is UltraSSDAvailable which always lists all regions as available. TODO(ace): update this function signature/behavior if necessary to account for per-zone availability.

func (*SKU) IsAvailable

func (s *SKU) IsAvailable(location string) bool

IsAvailable returns true when the requested location matches one on the sku, and there are no total restrictions on the location.

func (*SKU) IsEncryptionAtHostSupported

func (s *SKU) IsEncryptionAtHostSupported() bool

func (*SKU) IsEphemeralOSDiskSupported

func (s *SKU) IsEphemeralOSDiskSupported() bool

func (*SKU) IsResourceType

func (s *SKU) IsResourceType(t string) bool

IsResourceType returns true when the wrapped SKU has the provided value as its resource type. This may be used to filter using values such as "virtualMachines", "disks", "availabilitySets", "snapshots", and "hostGroups/hosts".

func (*SKU) IsRestricted

func (s *SKU) IsRestricted(location string) bool

IsRestricted returns true when a location restriction exists for this SKU.

func (*SKU) IsUltraSSDAvailable

func (s *SKU) IsUltraSSDAvailable() bool

func (*SKU) MaxCachedDiskBytes

func (s *SKU) MaxCachedDiskBytes() (int64, error)

func (*SKU) Memory

func (s *SKU) Memory() (int64, error)

Memory returns the amount of memory this SKU supports.

func (*SKU) VCPU added in v0.0.2

func (s *SKU) VCPU() (int64, error)

VCPU returns the number of vCPUs this SKU supports.

type Supported

type Supported string

Supported models an enum of possible boolean values for resource support in the Azure API.

const (
	// CapabilitySupported is an enum value for the string "True" returned when a SKU supports a binary capability.
	CapabilitySupported Supported = "True"
	// CapabilityUnupported is an enum value for the string "True" returned when a SKU does not support a binary capability.
	CapabilityUnupported Supported = "False"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL