volumequery

package
v0.0.0-...-6489ed8 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Where to read mountpoint info from.
	ProcMounts string = "/proc/mounts"
)
View Source
const SimpleMetadataLabel string = "simple-metadata"
View Source
const SimpleMetadataUUID string = "903b0d2d-812e-4029-89fa-a905b9cd80c1"
View Source
const (
	VolumeLabelVersion int = 1
)

Variables

This section is empty.

Functions

func CheckIfDiskIsBlankCandidate

func CheckIfDiskIsBlankCandidate(diskPath string) (bool, error)

CheckIfDiskIsBlankCandidate ensures the disk has no filesystems, no partition table, and can be safely recruited as a simple disk. Internally it calls CheckIfDiskIsInitialized - if you need to do both checks, then it's better to use IsBlankDisk which just does the response code parsing.

func GetCandidateDisks

func GetCandidateDisks(selectionRules []DeviceSelectionRule) (initialized []string, uninitialized []string, rejected []string, rerr error)

GetCandidateDisks returns all disks that simple might be able to use safely. A safe disk is either one which is already labelled as a simple disk, or one which is unpartitioned and does not appear to contain a filesystem or appear in the mount table.

func GetDevicePaths

func GetDevicePaths(selectionRules []DeviceSelectionRule) ([]string, error)

GetDevicePaths returns a sorted list of disk devices which are matched by the DeviceSelectionRule

func GetDiskDeviceFromPartitionPath

func GetDiskDeviceFromPartitionPath(partitionPath string) (map[string]*DeviceSelectionRule, error)

GetDiskDeviceFromPartitionPath takes a partition path and tries to query the disk it is attached to by device number. It is guaranteed to only ever return the one device.

func GetDiskLabelAndVolumePath

func GetDiskLabelAndVolumePath(diskPath string) (string, string, error)

GetDiskLabelAndVolumePath get's the disk label and volume path.

func GetPartitionDevicesFromDiskPath

func GetPartitionDevicesFromDiskPath(diskPath string) (map[string]*DeviceSelectionRule, error)

GetPartitionDevicesFromDiskPath takes a disk path and returns the device path deduplicated list of partitions on the disk.

func IsBlankDisk

func IsBlankDisk(isInitialized bool, failReason DiskFailReason) bool

IsBlankDisk converts an isInitialized/failReason pair into a check if the disk is blank.

func SerializeVolumeLabel

func SerializeVolumeLabel(label *VolumeLabel) ([]byte, error)

Serializes the label to it's null-terminated JSON form

func VolumeQueryMatch

func VolumeQueryMatch(query *VolumeQuery, labelPath string, dataPath string) (bool, error)

VolumeQueryMatch checks if a given volume query would match the device at the given path. Does not check for initialization or exclusive access constraints.

func VolumeQueryVar

func VolumeQueryVar(settings kingpin.Settings, target *VolumeQuery)

VolumeQueryVar implements a var mapped for reading VolumeQuery's with kingpin from the command line./

Types

type DeviceSelectionRule

type DeviceSelectionRule struct {
	Subsystems []string
	Name       []string
	Tag        []string
	Properties map[string]string
	Attrs      map[string]string
}

func GetFullSelectionRuleForDevice

func GetFullSelectionRuleForDevice(diskPath string) (*DeviceSelectionRule, error)

GetFullSelectionRulesForDevice queries a device by device path and returns a selection rule block which would uniquely match it. Mostly useful for simplectl to crosscheck rules.

func NewDeviceSelectionRule

func NewDeviceSelectionRule() DeviceSelectionRule

func (*DeviceSelectionRule) Copy

type Disk

type Disk struct {
	Label         VolumeLabel
	PartitionPath string
}

Struct representing a disk which is able to be used by the plugin

type DiskFailReason

type DiskFailReason error

func CheckIfDiskIsInitialized

func CheckIfDiskIsInitialized(diskPath string) (bool, DiskFailReason, error)

CheckIfDiskIsInitialized takes a device path and determines if it is a simple disk. It returns the outcome of the assessment, a reason code if the assessment fails, and a failure code if the lookup fails.

type NamingType

type NamingType string
const (
	NamingNumeric NamingType = "numeric"
	NamingUUID    NamingType = "uuid"
)

type VolumeLabel

type VolumeLabel struct {
	// Version of the label schema
	Version int `json:"version"`
	// Hostname this disk was last initialized on
	Hostname string `json:"hostname"`
	// Machine ID this disk was last initialized on, if available
	MachineId string `json:"machine_id"`
	// Label of this disk (should match partition label)
	Label string `json:"label"`
	// Last numbering assignment this disk had for the current label
	Numbering string `json:"numbering"`
	// Disk was created as an encrypted volume
	Encrypted bool `json:"encrypted"`
	// Extra metadata
	Metadata map[string]string `json:"metadata"`
}

Struct representing labelled data (output as JSON)

func DeserializeVolumeLabel

func DeserializeVolumeLabel(path string) (VolumeLabel, error)

DeserializeVolumeLabel reads a given path for a null terminated VolumeLabel

type VolumeQuery

type VolumeQuery struct {
	// Label of disk to search for
	Label string `volumelabel:"label"`

	// Hostname disk should be associated with
	OwnHostname bool `volumelabel:"own-hostname"`
	// MachineID the disk should be associated with
	OwnMachineId bool `volumelabel:"own-machine-id"`

	// Should the disk have been initialized by the filesystem
	Initialized bool `volumelabel:"initialized"`
	// Should the disk be marked as exclusive use?
	Exclusive bool `volumelabel:"exclusive"`
	// Should the disk be placed in a subdirectory and dynamically updated
	// as matching disks are added/removed
	DynamicMounts bool `volumelabel:"dynamic-mounts"`
	// Should disk numbering fields be respected from the label?
	PersistNumbering bool `volumelabel:"persist-numbering"`

	// Basename is the prefix assigned to mounted disks under the volume.
	Basename string `volumelabel:"basename"`
	// Naming style to use for disk mounts - numeric (incremented numbers)
	// or uuid (what it sounds like).
	NamingStyle NamingType `volumelabel:"naming-style"`

	// Minimum disk size to be considered valid.
	MinimumSizeBytes uint64 `volumelabel:"min-size"`
	// Maximum disk size to be considered valid.
	MaximumSizeBytes uint64 `volumelabel:"max-size"`

	// Minimum number of disks which must match before returning
	MinDisks int32 `volumelabel:"min-disks"`
	// Maximum number of disks which can be returned by the match
	MaxDisks int32 `volumelabel:"max-disks"`

	// Filesystem which will be created or found
	Filesystem string `volumelabel:"filesystem"`

	// Encryption Key - if specified requires a volume be encrypted with the
	// given key.
	EncryptionKey string `volumelabel:"encryption-passphrase"`
	// LUKS cipher to be used if creating a volume. If a passphrase is
	// specified then uses the LUKS default.
	EncryptionCipher string `volumelabel:"encryption-hash"`
	// LUKS key size.
	EncryptionKeySize int `volumelabel:"encryption-key-size"`
	// LUKS hash function
	EncryptionHash string `volumelabel:"encryption-hash"`
}

Specifies a volume query (this is a mash-up of query and create parameters in reality.

type VolumeQueryValue

type VolumeQueryValue VolumeQuery

VolumeQueryValue implements flag parsing for VolumeQuery's

func (*VolumeQueryValue) Set

func (this *VolumeQueryValue) Set(value string) error

func (*VolumeQueryValue) String

func (this *VolumeQueryValue) String() string

Jump to

Keyboard shortcuts

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