utils

package
v0.57.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvApstraUrl          = "APSTRA_URL"
	EnvApstraUsername     = "APSTRA_USER"
	EnvApstraPassword     = "APSTRA_PASS"
	EnvApstraLogfile      = "APSTRA_LOG"
	EnvApstraExperimental = "APSTRA_EXPERIMENTAL"
	EnvTlsKeyLogFile      = "SSLKEYLOGFILE"
)

Variables

This section is empty.

Functions

func AgentProfilePlatforms

func AgentProfilePlatforms() []string

func AllConfigletSectionNames

func AllConfigletSectionNames() []string

func AllDcRoutingPolicyImportPolicy

func AllDcRoutingPolicyImportPolicy() []string

func AllNodeDeployModes

func AllNodeDeployModes() []string

func AllOverlayControlProtocols

func AllOverlayControlProtocols() []string

func AllPlatformOSNames

func AllPlatformOSNames() []string

func AllResourceGroupNameStrings

func AllResourceGroupNameStrings() []string

func AllTemplateTypes

func AllTemplateTypes() []string

func AllValidPrefixFilterActions

func AllValidPrefixFilterActions() []string

func ApiStringerFromFriendlyString

func ApiStringerFromFriendlyString(target StringerWithFromString, in ...string) error

ApiStringerFromFriendlyString attempts to populate a StringerWithFromString using one or more friendly 'in' strings. It is used to turn friendly strings used in the web UI into types used by the SDK and ultimately the API. For example, we can get apstra.AsnAllocationSchemeDistinct directly from a string by invoking apstra.AsnAllocationScheme.FromString("distinct"). But the web UI uses "unique", rather than "distinct". This method will be able to translate "unique" into an apstra.AsnAllocationScheme value.

func BigIntToBigFloat

func BigIntToBigFloat(in *big.Int) *big.Float

func BlueprintExists

func BlueprintExists(ctx context.Context, client *apstra.Client, id apstra.ObjectId, diags *diag.Diagnostics) bool

func ConfigletSectionNamesByOS

func ConfigletSectionNamesByOS(os apstra.PlatformOS) []string

func ConfigletSupportsPlatforms

func ConfigletSupportsPlatforms(configletdata *apstra.ConfigletData, platforms []apstra.PlatformOS) bool

func ConfigletValidSectionsMap

func ConfigletValidSectionsMap() map[string][]string

func DiffSliceSets

func DiffSliceSets[A comparable](a, b []A) ([]A, []A)

DiffSliceSets compares two slices of un-ordered data. The returned values are un-ordered slices of values found in only one of the supplied slices. It might be reasonable to think of the returned slices as "missing from a" and "missing from b"

Example:
 a: []int{1,2,3,4}
 b: []int{2,1,5}
 return: []int{5}, []int{4, 3}

func FabricAddressing added in v0.53.0

func FabricAddressing(_ context.Context, s types.String, path *path.Path, diags *diag.Diagnostics) *apstra.AddressingScheme

func FcdModes

func FcdModes() []string

func GetAllSystemsInfo

func GetAllSystemsInfo(ctx context.Context, client *apstra.Client, diags *diag.Diagnostics) map[string]apstra.ManagedSystemInfo

GetAllSystemsInfo returns map[string]apstra.ManagedSystemInfo keyed by device_key (switch serial number)

func GetKeysFromJSON

func GetKeysFromJSON(str types.String) ([]attr.Value, error)

GetKeysFromJSON returns a list of keys from a Json string

func GetNodeDeployMode added in v0.43.0

func GetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, nodeId string) (string, error)

func Int64ValueOrNull

func Int64ValueOrNull(_ context.Context, in any, diags *diag.Diagnostics) types.Int64

func IsApstra404

func IsApstra404(err error) bool

func IsJSON

func IsJSON(str types.String) bool

IsJSON takes a string and returns true if json, false if not

func ItemInSlice

func ItemInSlice[A comparable](item A, slice []A) bool

func JSONEqual

func JSONEqual(m1, m2 types.String, d *diag.Diagnostics) bool

JSONEqual takes 2 json strings in types.String variables and matches them

func Known

func Known(v attr.Value) bool

func ListValueOrNull

func ListValueOrNull[T any](ctx context.Context, elementType attr.Type, elements []T, diags *diag.Diagnostics) types.List

ListValueOrNull returns a types.List based on the supplied elements. If the supplied elements is empty, the returned types.List will be flagged as null.

func MapValueOrNull

func MapValueOrNull[T any](ctx context.Context, elementType attr.Type, elements map[string]T, diags *diag.Diagnostics) types.Map

MapValueOrNull returns a types.Map based on the supplied elements. If the supplied elements is empty, the returned types.Map will be flagged as null.

func MapsMatch

func MapsMatch[A, B comparable](a, b map[A]B) bool

func Min

func Min[T constraints.Ordered](a, b T) T

func NewClientConfig

func NewClientConfig(apstraUrl string) (*apstra.ClientCfg, error)

func ObjectValueOrNull

func ObjectValueOrNull(ctx context.Context, attrTypes map[string]attr.Type, attributes any, diags *diag.Diagnostics) types.Object

ObjectValueOrNull returns a types.Object based on the supplied attributes. If the supplied attributes is nil, the returned types.Object will be flagged as null.

func Reverse

func Reverse[A any](in []A)

func SetNodeDeployMode added in v0.43.0

func SetNodeDeployMode(ctx context.Context, client *apstra.TwoStageL3ClosClient, nodeId string, modeString string) error

func SetValueOrNull

func SetValueOrNull[T any](ctx context.Context, elementType attr.Type, elements []T, diags *diag.Diagnostics) types.Set

SetValueOrNull returns a types.Set based on the supplied elements. If the supplied elements is empty, the returned types.Set will be flagged as null.

func SliceComplementOfA

func SliceComplementOfA[T comparable](a, b []T) []T

SliceComplementOfA returns items from b which do not appear in a

func SliceContains

func SliceContains[A comparable](a A, s []A) bool

func SliceDeleteUnOrdered

func SliceDeleteUnOrdered[A any](i int, a *[]A)

func SliceIntersectionOfAB

func SliceIntersectionOfAB[T comparable](a, b []T) []T

SliceIntersectionOfAB returns items which appear in both a and b

func SliceStringersMatch

func SliceStringersMatch[A fmt.Stringer](a, b []A) bool

func SlicesMatch

func SlicesMatch[A comparable](a, b []A) bool

func Sort added in v0.42.0

func Sort[A constraints.Ordered](in []A)

func StringValueOrNull

func StringValueOrNull(_ context.Context, in string, _ *diag.Diagnostics) types.String

StringValueOrNull returns a types.String based on the supplied string. If the supplied string is empty, the returned types.String will be flagged as null.

func StringValueWithNull

func StringValueWithNull(ctx context.Context, inStr string, nullStr string, diags *diag.Diagnostics) types.String

StringValueWithNull returns a types.String based on the supplied inStr. If inStr matches nullStr or is empty, the returned types.String will be flagged as null.

func StringersToFriendlyString

func StringersToFriendlyString(in ...fmt.Stringer) string

StringersToFriendlyString accepts stringers (probably apstra-go-sdk string-able iota or enum types) and returns a string that better reflects terminology used by the Apstra web UI.

For example, the API uses "distinct" where the web UI uses "unique". This function turns apstra.AsnAllocationSchemeDistinct into "unique".

func StringersToStrings

func StringersToStrings[A fmt.Stringer](in []A) []string

func Swap

func Swap[A any](a, b int, in []A)

func ToPtr added in v0.52.0

func ToPtr[A any](a A) *A

func Uniq

func Uniq[A comparable](in []A) []A

Uniq returns the supplied slice with consecutive duplicates removed. Order is not preserved. Name is taken from '/usr/bin/uniq' because of similar function.

func UniqStringers

func UniqStringers[A fmt.Stringer](in []A) []A

UniqStringers returns the supplied slice with consecutive duplicates removed. Order is not preserved. Name is taken from '/usr/bin/uniq' because of similar function.

func UniqueElementsFromA

func UniqueElementsFromA[E comparable](a, b []E) []E

UniqueElementsFromA returns elements of slice 'a' which do not appear in slice 'b'. Order is not preserved.

func UrlEscapeTable

func UrlEscapeTable() string

func ValidSectionsAsTable

func ValidSectionsAsTable() string

func WrapDiagnostic

func WrapDiagnostic(in diag.Diagnostic, detail string) diag.Diagnostic

func WrapEachDiagnostic

func WrapEachDiagnostic(prefix string, in ...diag.Diagnostic) diag.Diagnostics

Types

type Stringer added in v0.48.0

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

func NewStringer added in v0.48.0

func NewStringer(s string) Stringer

func (Stringer) String added in v0.48.0

func (o Stringer) String() string

type StringerWithFromString

type StringerWithFromString interface {
	String() string
	FromString(string) error
}

Jump to

Keyboard shortcuts

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