utils

package
v19.10.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: 31 Imported by: 0

Documentation

Index

Constants

View Source
const Darwin = "darwin"

Darwin is a constant value for the runtime.GOOS that represents Apple MacOS

View Source
const Linux = "linux"

Linux is a constant value for the runtime.GOOS that represents the Linux OS

View Source
const Windows = "windows"

Windows is a constant value for the runtime.GOOS that represents the Windows OS

Variables

This section is empty.

Functions

func AttachISCSIVolume

func AttachISCSIVolume(name, mountpoint string, publishInfo *VolumePublishInfo) error

Attach the volume to the local host. This method must be able to accomplish its task using only the data passed in. It may be assumed that this method always runs on the host to which the volume will be attached. If the mountpoint parameter is specified, the volume will be mounted. The device path is set on the in-out publishInfo parameter so that it may be mounted later instead.

func AttachNFSVolume

func AttachNFSVolume(name, mountpoint string, publishInfo *VolumePublishInfo) error

Attach the volume to the local host. This method must be able to accomplish its task using only the data passed in. It may be assumed that this method always runs on the host to which the volume will be attached.

func ConsistentRead

func ConsistentRead(filename string, attempts int) ([]byte, error)

ConsistentRead repeatedly reads a file until it gets the same content twice. This is useful when reading files in /proc that are larger than page size and kernel may modify them between individual read() syscalls.

func ConvertSizeToBytes

func ConvertSizeToBytes(s string) (string, error)

ConvertSizeToBytes converts size to bytes; see also https://en.wikipedia.org/wiki/Kilobyte

func DeleteResourceAtPath

func DeleteResourceAtPath(resource string) error

DeleteResourceAtPath makes sure that given named file or (empty) directory is removed

func EnsureDirExists

func EnsureDirExists(path string) error

EnsureDirExists makes sure that given directory structure exists

func EnsureFileExists

func EnsureFileExists(path string) error

EnsureFileExists makes sure that file of given name exists

func EnsureISCSISession

func EnsureISCSISession(hostDataIP string) error

func EnsureISCSISessions

func EnsureISCSISessions(hostDataIPs []string) error

func ExpandISCSIFilesystem

func ExpandISCSIFilesystem(publishInfo *VolumePublishInfo, stagedTargetPath string) (int64, error)

ExpandISCSIFilesystem will expand the filesystem of an already expanded volume.

func GetDeviceNameFromMount

func GetDeviceNameFromMount(mountpath string) (string, int, error)

func GetInitiatorIqns

func GetInitiatorIqns() ([]string, error)

GetInitiatorIqns returns parsed contents of /etc/iscsi/initiatorname.iscsi

func GetV

func GetV(opts map[string]string, keys string, defaultValue string) string

GetV takes a map, key(s), and a defaultValue; will return the value of the key or defaultValue if none is set. If keys is a string of key values separated by "|", then each key is tried in turn. This allows compatibility with deprecated values, i.e. "fstype|fileSystemType".

func GetVolumeSizeBytes

func GetVolumeSizeBytes(opts map[string]string, defaultVolumeSize string) (uint64, error)

GetVolumeSizeBytes determines the size, in bytes, of a volume from the "size" opt value. If "size" has a units suffix, that is handled here. If there are no units, the default is GiB. If size is not in opts, the specified default value is parsed identically and used instead.

func ISCSIDisableDelete

func ISCSIDisableDelete(targetIQN, targetPortal string) error

ISCSIDisableDelete logs out from the supplied target and removes the iSCSI device.

func ISCSIRescanDevices

func ISCSIRescanDevices(targetIQN string, lunID int32, minSize int64) error

func ISCSISupported

func ISCSISupported() bool

ISCSISupported returns true if iscsiadm is installed and in the PATH.

func ISCSITargetHasMountedDevice

func ISCSITargetHasMountedDevice(targetIQN string) (bool, error)

ISCSITargetHasMountedDevice returns true if this host has any mounted devices on the specified target.

func IsAlreadyAttached

func IsAlreadyAttached(lunID int, targetIqn string) bool

IsAlreadyAttached checks if there is already an established iSCSI session to the specified LUN.

func IsLikelyDir

func IsLikelyDir(mountpoint string) (bool, error)

IsLikelyDir determines if mountpoint is a directory

func IsLikelyNotMountPoint

func IsLikelyNotMountPoint(mountpoint string) (bool, error)

IsLikelyNotMountPoint determines if a directory is not a mountpoint.

func IsMounted

func IsMounted(sourceDevice, mountpoint string) (bool, error)

IsMounted verifies if the supplied device is attached at the supplied location.

func Lock

func Lock(ctx, lockID string)

Lock acquires a mutex with the specified ID. The mutex does not need to exist before calling this method. The semantics of this method are intentionally identical to sync.Mutex.Lock().

func LogHTTPRequest

func LogHTTPRequest(request *http.Request, requestBody []byte)

func LogHTTPResponse

func LogHTTPResponse(response *http.Response, responseBody []byte)

func MountDevice

func MountDevice(device, mountpoint, options string, isMountPointFile bool) (err error)

MountDevice attaches the supplied device at the supplied location. Use this for iSCSI devices.

func PathExists

func PathExists(path string) bool

PathExists returns true if the file/directory at the specified path exists, false otherwise or if an error occurs.

func Pow

func Pow(x int64, y int) int64

Pow is an integer version of exponentiation; existing builtin is float, we needed an int version.

func PrepareDeviceAtMountPathForRemoval

func PrepareDeviceAtMountPathForRemoval(mountpoint string, unmount bool) error

PrepareDeviceAtMountPathForRemoval informs Linux that a device will be removed.

func PrepareDeviceForRemoval

func PrepareDeviceForRemoval(lunID int, iSCSINodeName string)

PrepareDeviceForRemoval informs Linux that a device will be removed.

func RandomString

func RandomString(strSize int) string

RandomString returns a string of the specified length consisting only of alphabetic characters.

func RemoveStringFromSlice

func RemoveStringFromSlice(slice []string, s string) (result []string)

RemoveStringFromSlice removes a string from a []string

func SliceContainsString

func SliceContainsString(slice []string, s string) bool

SliceContainsString checks to see if a []string contains a string

func StringInSlice

func StringInSlice(s string, list []string) bool

StringInSlice checks whether a string is in a list of strings

func Umount

func Umount(mountpoint string) (err error)

Umount detaches from the supplied location.

func UmountAndRemoveTemporaryMountPoint

func UmountAndRemoveTemporaryMountPoint(mountPath string) error

UmountAndRemoveTemporaryMountPoint unmounts and removes the TemporaryMountDir

func Unlock

func Unlock(ctx, lockID string)

Unlock releases a mutex with the specified ID. The semantics of this method are intentionally identical to sync.Mutex.Unlock().

func VolumeSizeWithinTolerance

func VolumeSizeWithinTolerance(requestedSize int64, currentSize int64, delta int64) (bool, error)

VolumeSizeWithinTolerance checks to see if requestedSize is within the delta of the currentSize. If within the delta true is returned. If not within the delta and requestedSize is less than the currentSize false is returned.

Types

type CertInfo

type CertInfo struct {
	CAKey      string
	CACert     string
	ServerKey  string
	ServerCert string
	ClientKey  string
	ClientCert string
}

func MakeHTTPCertInfo

func MakeHTTPCertInfo(caCertName, serverCertName, clientCertName string) (*CertInfo, error)

makeHTTPCertInfo generates a CA key and cert, then uses that key to sign two other keys and certs, one for a TLS server and one for a TLS client. None of the parameters are configurable...the serial numbers and principal names are hardcoded, the validity period is hardcoded to 1970-2070, and the algorithm and key size are hardcoded to 521-bit elliptic curve.

type DFInfo

type DFInfo struct {
	Target string
	Source string
}

DFInfo data structure for wrapping the parsed output from the 'df' command

func GetDFOutput

func GetDFOutput() ([]DFInfo, error)

GetDFOutput returns parsed DF output

type HTTPError

type HTTPError struct {
	Status     string
	StatusCode int
}

func NewHTTPError

func NewHTTPError(response *http.Response) *HTTPError

func (HTTPError) Error

func (e HTTPError) Error() string

type ISCSIDiscoveryInfo

type ISCSIDiscoveryInfo struct {
	Portal     string
	PortalIP   string
	TargetName string
}

ISCSIDiscoveryInfo contains information about discovered iSCSI targets.

type ISCSISessionInfo

type ISCSISessionInfo struct {
	SID        string
	Portal     string
	PortalIP   string
	TargetName string
}

ISCSISessionInfo contains information about iSCSI sessions.

type IscsiAccessInfo

type IscsiAccessInfo struct {
	IscsiTargetPortal    string   `json:"iscsiTargetPortal,omitempty"`
	IscsiPortals         []string `json:"iscsiPortals,omitempty"`
	IscsiTargetIQN       string   `json:"iscsiTargetIqn,omitempty"`
	IscsiLunNumber       int32    `json:"iscsiLunNumber,omitempty"`
	IscsiInterface       string   `json:"iscsiInterface,omitempty"`
	IscsiIgroup          string   `json:"iscsiIgroup,omitempty"`
	IscsiVAGs            []int64  `json:"iscsiVags,omitempty"`
	IscsiUsername        string   `json:"iscsiUsername,omitempty"`
	IscsiInitiatorSecret string   `json:"iscsiInitiatorSecret,omitempty"`
	IscsiTargetSecret    string   `json:"iscsiTargetSecret,omitempty"`
}

type MountInfo

type MountInfo struct {
	MountId      int
	ParentId     int
	DeviceId     string
	Root         string
	MountPoint   string
	MountOptions []string
	//OptionalFields []string
	FsType       string
	MountSource  string
	SuperOptions []string
}

This represents a single line in /proc/self/mountinfo.

type MountPoint

type MountPoint struct {
	Device string
	Path   string
	Type   string
	Opts   []string
	Freq   int
	Pass   int
}

This represents a single line in /proc/mounts or /etc/fstab.

type NfsAccessInfo

type NfsAccessInfo struct {
	NfsServerIP string `json:"nfsServerIp,omitempty"`
	NfsPath     string `json:"nfsPath,omitempty"`
}

type Node

type Node struct {
	Name string   `json:"name"`
	IQN  string   `json:"iqn,omitempty"`
	IPs  []string `json:"ips,omitempty"`
}

type ScsiDeviceInfo

type ScsiDeviceInfo struct {
	Host            string
	Channel         string
	Target          string
	LUN             string
	Devices         []string
	MultipathDevice string
	Filesystem      string
	IQN             string
	HostSessionMap  map[int]int
}

ScsiDeviceInfo contains information about SCSI devices

func GetISCSIDevices

func GetISCSIDevices() ([]*ScsiDeviceInfo, error)

GetISCSIDevices returns a list of iSCSI devices that are attached to (but not necessarily mounted on) this host.

func GetMountedISCSIDevices

func GetMountedISCSIDevices() ([]*ScsiDeviceInfo, error)

GetMountedISCSIDevices returns a list of iSCSI devices that are *mounted* on this host.

type Version

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

Version is an opaque representation of a version number

func MustParseDate

func MustParseDate(str string) *Version

MustParseDate is like ParseDate except that it panics on error

func MustParseGeneric

func MustParseGeneric(str string) *Version

MustParseGeneric is like ParseGeneric except that it panics on error

func MustParseSemantic

func MustParseSemantic(str string) *Version

MustParseSemantic is like ParseSemantic except that it panics on error

func ParseDate

func ParseDate(str string) (*Version, error)

ParseDate parses a version string that mostly obeys the syntax and semantics of the "Semantic Versioning" specification (http://semver.org/) (although it ignores leading and trailing whitespace, and allows the version to be preceded by "v"). Furthermore, it allows leading zeroes on the second numerical component so that the version may represent a two-digit month (i.e. 17.07.1). A date-based version string must be of the form <year>.<month>.<rev>[-preRelease][+buildMetadata], where the year/month/rev values are numerical, and the month must be in the range 1..12.

func ParseGeneric

func ParseGeneric(str string) (*Version, error)

ParseGeneric parses a "generic" version string. The version string must consist of two or more dot-separated numeric fields (the first of which can't have leading zeroes), followed by arbitrary uninterpreted data (which need not be separated from the final numeric field by punctuation). For convenience, leading and trailing whitespace is ignored, and the version can be preceded by the letter "v". See also ParseSemantic.

func ParseSemantic

func ParseSemantic(str string) (*Version, error)

ParseSemantic parses a version string that exactly obeys the syntax and semantics of the "Semantic Versioning" specification (http://semver.org/) (although it ignores leading and trailing whitespace, and allows the version to be preceded by "v"). For version strings that are not guaranteed to obey the Semantic Versioning syntax, use ParseGeneric.

func (*Version) AtLeast

func (v *Version) AtLeast(min *Version) bool

AtLeast tests if a version is at least equal to a given minimum version. If both Versions are Semantic Versions, this will use the Semantic Version comparison algorithm. Otherwise, it will compare only the numeric components, with non-present components being considered "0" (ie, "1.4" is equal to "1.4.0").

func (*Version) BuildMetadata

func (v *Version) BuildMetadata() string

BuildMetadata returns the build metadata, if v is a Semantic Version, or ""

func (*Version) Compare

func (v *Version) Compare(other string) (int, error)

Compare compares v against a version string (which will be parsed as either Semantic or non-Semantic depending on v). On success it returns -1 if v is less than other, 1 if it is greater than other, or 0 if they are equal.

func (*Version) GreaterThan

func (v *Version) GreaterThan(other *Version) bool

GreaterThan tests if a version is greater than a given version.

func (*Version) LessThan

func (v *Version) LessThan(other *Version) bool

LessThan tests if a version is less than a given version. (It is exactly the opposite of AtLeast, for situations where asking "is v too old?" makes more sense than asking "is v new enough?".)

func (*Version) MajorVersion

func (v *Version) MajorVersion() uint

func (*Version) MajorVersionString

func (v *Version) MajorVersionString() string

func (*Version) MinorVersion

func (v *Version) MinorVersion() uint

func (*Version) MinorVersionString

func (v *Version) MinorVersionString() string

func (*Version) PatchVersion

func (v *Version) PatchVersion() uint

func (*Version) PreRelease

func (v *Version) PreRelease() string

func (*Version) ShortString

func (v *Version) ShortString() string

ShortString converts a Version back to a string, including only the major/minor/patch components.

func (*Version) String

func (v *Version) String() string

String converts a Version back to a string; note that for versions parsed with ParseGeneric, this will not include the trailing uninterpreted portion of the version number.

func (*Version) ToMajorMinorString

func (v *Version) ToMajorMinorString() string

func (*Version) ToMajorMinorVersion

func (v *Version) ToMajorMinorVersion() *Version

type VolumeAccessInfo

type VolumeAccessInfo struct {
	IscsiAccessInfo
	NfsAccessInfo
	MountOptions string `json:"mountOptions,omitempty"`
}

type VolumePublishInfo

type VolumePublishInfo struct {
	Localhost      bool     `json:"localhost,omitempty"`
	HostIQN        []string `json:"hostIQN,omitempty"`
	HostIP         []string `json:"hostIP,omitempty"`
	HostName       string   `json:"hostName,omitempty"`
	FilesystemType string   `json:"fstype,omitempty"`
	UseCHAP        bool     `json:"useCHAP,omitempty"`
	SharedTarget   bool     `json:"sharedTarget,omitempty"`
	DevicePath     string   `json:"devicePath,omitempty"`
	VolumeAccessInfo
}

type VolumeTrackingPublishInfo

type VolumeTrackingPublishInfo struct {
	StagingTargetPath string `json:"stagingTargetPath`
}

Jump to

Keyboard shortcuts

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