utils

package
v0.1.39 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// state constants
	StateUnknown      = "unknown"
	StateRunning      = "running"
	StateFailed       = "failed"
	StateProvisioning = "provisioning"
	StateStopped      = "stopped"
	StateStopping     = "stopping"
	StateSuspended    = "suspended"
	StateSuspending   = "suspending"
	StateResizing     = "resizing"
	StateRestarting   = "restarting"
	// data constants
	ErrInvalidType   = "invalid Type"
	ErrKeyNotDefined = "key is not defined"
	ErrSet           = "failed to set"
	NAN              = 0

	// power constants
	PowerOn         = "poweron"
	PowerOff        = "poweroff"
	Restart         = "restart"
	Suspend         = "suspend"
	Deleting        = "deleting"
	Deleted         = "deleted"
	Failed          = "failed"
	PortGroupPrefix = "dvportgroup-"
)

Variables

This section is empty.

Functions

func GetSMap

func GetSMap(src interface{}) []map[string]interface{}

GetSMap for get map for a Set

func GetlistMap

func GetlistMap(src interface{}) []map[string]interface{}

func IsEmpty

func IsEmpty(n interface{}) bool

func JSONNumber

func JSONNumber(in interface{}) json.Number

func ParseInt

func ParseInt(str string) (int64, error)

func ParsePowerState

func ParsePowerState(state string) string

func Retry

func Retry(ctx context.Context, meta interface{}, fn RetryFunc) (interface{}, error)

Retry with default count and timeout

func SkipEmptyField added in v0.1.32

func SkipEmptyField() schema.SchemaDiffSuppressFunc

SkipEmptyField it to skip diff check when user didn't set any attribute in tf file but state file is updated

func SkipField

func SkipField() schema.SchemaDiffSuppressFunc

Types

type CondFunc

type CondFunc func(response interface{}, ResponseErr error) (bool, error)

CondFunc function accepts response and error of the RetryFunc. If any error returns retry will terminated and returns the error

type CustomRetry

type CustomRetry struct {
	RetryCount   int
	RetryDelay   time.Duration
	InitialDelay time.Duration
	Cond         CondFunc
	Timeout      time.Duration
	// contains filtered or unexported fields
}

CustomRetry allows developers to configure the timeout, retry count and delay

func (*CustomRetry) Retry

func (c *CustomRetry) Retry(
	ctx context.Context,
	meta interface{},
	fn RetryFunc,
) (interface{}, error)

Retry supports extra arguments. initialDelay will put a delay before invoking the function. RetryCount supports customized retry count. If Timeout specified then RetryCount will be skipped. RetryDelay will put a delay in between each retrys. If any of these values are not specified then default value will be assigned.

func (*CustomRetry) RetryParallel

func (c *CustomRetry) RetryParallel(ctx context.Context, meta interface{}, fn RetryFunc)

RetryParallel runs retry as routine. Use Wait function to wait and get the response error. To run more than one API or functions as a routine you may need to specify different CustomRetry struct.

func (*CustomRetry) Wait

func (c *CustomRetry) Wait() (interface{}, error)

type Data

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

func NewData

func NewData(d *schema.ResourceData) *Data

NewData returns new Data instance

func (*Data) Error

func (d *Data) Error() error

func (*Data) GetBool

func (d *Data) GetBool(key string) bool

func (*Data) GetChangedListMap

func (d *Data) GetChangedListMap(key string) ([]map[string]interface{}, []map[string]interface{})

func (*Data) GetChangedMap

func (d *Data) GetChangedMap(key string) (map[string]interface{}, map[string]interface{})

func (*Data) GetID

func (d *Data) GetID() int

func (*Data) GetIDString

func (d *Data) GetIDString() string

GetIDString returns ID as string

func (*Data) GetInt

func (d *Data) GetInt(key string, ignore ...bool) int

func (*Data) GetJSONNumber

func (d *Data) GetJSONNumber(key string, ignore ...bool) json.Number

func (*Data) GetListMap

func (d *Data) GetListMap(key string) []map[string]interface{}

GetListMap take key as parameter and returns []map[string]interfac{}. This function can be used for retrieving list of map or list of set

func (*Data) GetMap

func (d *Data) GetMap(key string, ignore ...bool) map[string]interface{}

func (*Data) GetOk

func (d *Data) GetOk(key string) (interface{}, bool)

func (*Data) GetString

func (d *Data) GetString(key string, ignore ...bool) string

func (*Data) GetStringList

func (d *Data) GetStringList(key string, ignore ...bool) []string

GetStringList returns list of string

func (*Data) HasChanged

func (d *Data) HasChanged(key string) bool

func (*Data) Id

func (d *Data) Id() string

nolint

func (*Data) ListToIntSlice

func (d *Data) ListToIntSlice(key string, ignore ...bool) []int

func (*Data) Set

func (d *Data) Set(key string, val interface{}) error

func (*Data) SetID

func (d *Data) SetID(v interface{})

SetID should either be int or string

func (*Data) SetId

func (d *Data) SetId(v string)

nolint

func (*Data) SetString

func (d *Data) SetString(key string, value string)

type RetryFunc

type RetryFunc func(ctx context.Context) (interface{}, error)

RetryFunc accepts ctx as parameters and return response and error

Jump to

Keyboard shortcuts

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