lvm

package
v1.6.2 Latest Latest
Warning

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

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

Documentation

Overview

Package lvm contains code for running and interpreting output of system logical volume manager utils such as: pvcreate/pvremove, vgcreate/vgremove, lvcreate/lvremove

Index

Constants

View Source
const (
	// EmptyName represents empty name for PV/LV/VG
	EmptyName = " "

	// PVCreateCmdTmpl create PV cmd
	PVCreateCmdTmpl = lvmPath + "pvcreate --yes %s" // add PV name
	// PVRemoveCmdTmpl remove PV cmd
	PVRemoveCmdTmpl = lvmPath + "pvremove --yes %s" // add PV name
	// PVsInVGCmdTmpl print PVs in VG cmd
	PVsInVGCmdTmpl = lvmPath + "pvs --select vg_name=%s -o pv_name --noheadings" // add VG name
	// PVsListCmdTmpl print all PVs name on node
	PVsListCmdTmpl = lvmPath + "pvdisplay --short"
	// VGCreateCmdTmpl create VG on provided PVs cmd
	VGCreateCmdTmpl = lvmPath + "vgcreate --yes %s %s" // add VG name and PV names
	// VGScanCmdTmpl searches for all VGs
	VGScanCmdTmpl = lvmPath + "vgscan"
	// VGRefreshCmdTmpl reactivates an LV using the latest metadata
	VGRefreshCmdTmpl = lvmPath + "vgchange --refresh %s"
	// VGRemoveCmdTmpl remove VG cmd
	VGRemoveCmdTmpl = lvmPath + "vgremove --yes %s" // add VG name
	// AllPVsCmd returns all physical volumes on the system
	AllPVsCmd = lvmPath + "pvs --options pv_name --noheadings"
	// VGFreeSpaceCmdTmpl check VG free space cmd
	VGFreeSpaceCmdTmpl = "vgs %s --options vg_free --units b --noheadings" // add VG name
	// LVCreateCmdTmpl create LV on provided VG cmd
	LVCreateCmdTmpl = lvmPath + "lvcreate --yes --name %s --size %s %s" // add LV name, size and VG name
	// LVRemoveCmdTmpl remove LV cmd
	LVRemoveCmdTmpl = lvmPath + "lvremove --yes %s" // add full LV name
	// LVsInVGCmdTmpl print LVs in VG cmd
	LVsInVGCmdTmpl = lvmPath + "lvs --select vg_name=%s -o lv_name --noheadings" // add VG name
	// PVInfoCmdTmpl returns colon (:) separated output, where pv name on first place and vg on second
	PVInfoCmdTmpl = lvmPath + "pvdisplay %s --colon" // add PV name
	// LVExpandCmdTmpl expand LV
	LVExpandCmdTmpl = lvmPath + "lvextend --size %sb --resizefs %s" // add full LV name

)

Variables

This section is empty.

Functions

This section is empty.

Types

type LVM

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

LVM is an implementation of WrapLVM interface and is a wrap for system /sbin/lvm util in

func NewLVM

func NewLVM(e command.CmdExecutor, l *logrus.Logger) *LVM

NewLVM is a constructor for LVM struct

func (*LVM) ExpandLV

func (l *LVM) ExpandLV(lvName string, requiredSize int64) error

ExpandLV expand logical volume Receives full name of a logical volume and requiredSize to resize Returns error if something went wrong

func (*LVM) GetAllPVs

func (l *LVM) GetAllPVs() ([]string, error)

GetAllPVs returns slice with names of all physical volumes in the system

func (*LVM) GetLVsInVG

func (l *LVM) GetLVsInVG(vgName string) ([]string, error)

GetLVsInVG collects LVs for given volume group Receives Volume Group name Returns slice of found logical volumes

func (*LVM) GetVGNameByPVName

func (l *LVM) GetVGNameByPVName(pvName string) (string, error)

GetVGNameByPVName finds out volume group name based on physical volume name

func (*LVM) GetVgFreeSpace

func (l *LVM) GetVgFreeSpace(vgName string) (int64, error)

GetVgFreeSpace returns VG free space in bytes Receives VG name to count ints free space Returns -1 in case of error and error

func (*LVM) IsVGContainsLVs

func (l *LVM) IsVGContainsLVs(vgName string) bool

IsVGContainsLVs checks whether VG vgName contains any LVs or no Receives Volume Group name to check Returns true in case of error to prevent mistaken VG remove

func (*LVM) LVCreate

func (l *LVM) LVCreate(name, size, vgName string) error

LVCreate created logical volume in volume group, ignore error if LV already exists Receives name of created LV, size which is a string like 1.2G, 100M and name of VG which LV should be based on Returns error if something went wrong

func (*LVM) LVRemove

func (l *LVM) LVRemove(fullLVName string) error

LVRemove removes logical volume, ignore error if LV doesn't exist Receives fullLVName that is a path to LV Returns error if something went wrong

func (*LVM) PVCreate

func (l *LVM) PVCreate(dev string) error

PVCreate creates physical volume based on provided device or partition Receives device path Returns error if something went wrong

func (*LVM) PVRemove

func (l *LVM) PVRemove(name string) error

PVRemove removes physical volumes, ignore error if PV doesn't exist Receives name of a physical volume to delete Returns error if something went wrong

func (*LVM) RemoveOrphanPVs

func (l *LVM) RemoveOrphanPVs() error

RemoveOrphanPVs removes PVs that do not have VG Returns error if something went wrong

func (*LVM) VGCreate

func (l *LVM) VGCreate(name string, pvs ...string) error

VGCreate creates volume group and based on provided physical volumes (pvs). Ignore error if VG already exists Receives name of VG to create and names of physical volumes which VG should based on Returns error if something went wrong

func (*LVM) VGReactivate

func (l *LVM) VGReactivate(name string) error

VGReactivate inactivates, scans and activates volume group to recover from disk missing scenario Receives name of VG to re-activate Returns error if something went wrong

func (*LVM) VGRemove

func (l *LVM) VGRemove(name string) error

VGRemove removes volume group, ignore error if VG doesn't exist Receives name of VG to remove Returns error if something went wrong

func (*LVM) VGScan

func (l *LVM) VGScan(name string) (bool, error)

VGScan scans for all VGs and checks for IO errors for specific volume group name Receives name of VG name to scan and check Return boolean (false if no IO errors detected, true otherwise) and error if command failed to execute

type WrapLVM

type WrapLVM interface {
	PVCreate(dev string) error
	PVRemove(name string) error
	VGCreate(name string, pvs ...string) error
	VGScan(name string) (bool, error)
	VGReactivate(name string) error
	VGRemove(name string) error
	LVCreate(name, size, vgName string) error
	LVRemove(fullLVName string) error
	IsVGContainsLVs(vgName string) bool
	RemoveOrphanPVs() error
	GetVgFreeSpace(vgName string) (int64, error)
	GetAllPVs() ([]string, error)
	GetLVsInVG(vgName string) ([]string, error)
	GetVGNameByPVName(pvName string) (string, error)
	ExpandLV(lvName string, requiredSize int64) error
}

WrapLVM is an interface that encapsulates operation with system logical volume manager (/sbin/lvm)

Jump to

Keyboard shortcuts

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