cutil

package
v3.2.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Please do not change
	// they are used as error strings in api/path_service_config.go
	// they also used as templates for parsing the error strings in cli/register.go
	ANAX_SVC_MISSING_VARIABLE = "variable %v for service %v is missing from mappings."
	ANAX_SVC_MISSING_CONFIG   = "service config for version %v of %v is missing."
	ANAX_SVC_WRONG_TYPE       = "variable %v for service %v is "
)
View Source
const ExchangeTimeFormat = "2006-01-02T15:04:05.999Z[MST]"

Exchange time format. Golang requires the format string to be in reference to the specific time as shown. This is so that the formatter and parser can figure out what goes where in the string.

Variables

This section is empty.

Functions

func ArchString

func ArchString() string

func CheckConnectivity

func CheckConnectivity(host string) error

Check if the device has internect connection to the given host or not.

func ConvertToMB

func ConvertToMB(value string, unit string) (uint64, error)

Converts the given number (in string) to mega bytes. The unit can be MB, KB, GB, or B.

func CopyMap

func CopyMap(m1 map[string]interface{}, m2 map[string]interface{})

func FirstN

func FirstN(n int, ss []string) []string

func FormDockerImageName

func FormDockerImageName(domain, path, tag, digest string) string

for the image from the items parsed from ParseDockerImagePath function

func FormOrgSpecUrl

func FormOrgSpecUrl(url string, org string) string

it returns the org/url form for an api spec

func FormattedTime

func FormattedTime() string

func GenerateAgreementId

func GenerateAgreementId() (string, error)

func GetAllHostIPv4Addresses

func GetAllHostIPv4Addresses(interfaceFilters []NetFilter) ([]string, error)

Interface filter functions return false if the interface should be filtered out.

func GetCPUCount

func GetCPUCount(cpuinfo_file string) (int, error)

Get the number of cpus on local node. If cpuinfo_file is an empty string, this function will get /proc/cpuinfo for Linux.

func GetMemInfo

func GetMemInfo(meminfo_file string) (uint64, uint64, error)

Get the total memory size and available memory size in MegaBytes If meminfo_file is an empty string, this function will get /proc/meminfo for Linux.

func IsIPv4

func IsIPv4(address string) bool

func MakeMSInstanceKey

func MakeMSInstanceKey(specRef string, org string, v string, id string) string

This is also used as the container name The container name must start with an alphanumeric character and can then use _ . or - in addition to alphanumeric. [a-zA-Z0-9][a-zA-Z0-9_.-]+

func Maxuint64

func Maxuint64(first uint64, second uint64) uint64

func Min

func Min(first int, second int) int

func Minuint64

func Minuint64(first uint64, second uint64) uint64

func NativeToEnvVariableMap

func NativeToEnvVariableMap(envMap map[string]string, varName string, varValue interface{}) error

Convert a native typed user input variable to a string so that the value can be passed as an environment variable to a container. This function modifies the input env var map and it will modify map keys that already exist in the map.

func NormalizeURL

func NormalizeURL(specRef string) string

func OmitDown

func OmitDown(i net.Interface) bool

func OmitLoopback

func OmitLoopback(i net.Interface) bool

func OmitUp

func OmitUp(i net.Interface) bool

func ParseDockerImagePath

func ParseDockerImagePath(imagePath string) (domain, path, tag, digest string)

This function parsed the given image name to disfferent parts. The image name has the following format: [[repo][:port]/][somedir/]image[:tag][@digest] If the image path as an improper form (we could not parse it), path will be empty. image names can be domain.com/dir/dir:tag or domain.com/dir/dir@sha256:ac88f4... or domain.com/dir/dir:tag@sha256:ac88f4...

func SecureRandomString

func SecureRandomString() (string, error)

func SetPlatformEnvvars

func SetPlatformEnvvars(envAdds map[string]string, prefix string, agreementId string, deviceId string, org string, workloadPW string, exchangeURL string, pattern string, fssProtocol string, fssAddress string, fssPort string)

This function may seem simple but since it is shared with the hzn dev CLI, an update to it will cause a compile error in the CLI code. This will prevent us from adding a new platform env var but forgetting to update the CLI.

func SetSystemEnvvars

func SetSystemEnvvars(envAdds map[string]string, prefix string, lat string, lon string, cpus string, ram string, arch string)

This function is similar to the above, for env vars that are system related. It is only used by workloads.

func SliceContains

func SliceContains(a []string, s string) bool

check if a slice contains a string

func SplitOrgSpecUrl

func SplitOrgSpecUrl(org_url string) (string, string)

The input is org/url, output is (org, url). assume no `/` in the org

func TimeInSeconds

func TimeInSeconds(timestamp string, format string) int64

func TruncateDisplayString

func TruncateDisplayString(s string, n int) string

It will return the first n characters of the string and the rest will be as "..."

func VerifyWorkloadVarTypes

func VerifyWorkloadVarTypes(varValue interface{}, expectedType string) error

This function checks the input variable value against the expected exchange variable type and returns an error if there is no match. This function assumes the varValue was parsed with json decoder set to UseNumber().

Types

type NetFilter

type NetFilter func(net.Interface) bool

Jump to

Keyboard shortcuts

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