utilwrappers

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: 11 Imported by: 0

Documentation

Overview

Package utilwrappers consists of code that manipulates by os utils and use code from linuxutils for that

Interfaces descriptions: 1. FSOperations works with file system and holds compound methods for interacting with it 2. PartitionOperations works with partition on the system and holds compound methods for interacting with it

Index

Constants

View Source
const (
	// NumberOfRetriesToObtainPartName how many retries to obtain partition name
	NumberOfRetriesToObtainPartName = 5
	// SleepBetweenRetriesToObtainPartName default timeout between retries to obtain partition name
	SleepBetweenRetriesToObtainPartName = 3 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FSOperations

type FSOperations interface {
	// PrepareAndPerformMount composite methods which is prepare source and destination directories
	// and performs mount operation from src to dst
	PrepareAndPerformMount(src, dst string, bindMount, dstIsDir bool, mountOptions ...string) error
	// MountFakeTmpfs does attach of a temporary folder on failure
	MountFakeTmpfs(volumeID, dst string) error
	// UnmountWithCheck unmount operation
	UnmountWithCheck(path string) error
	// CreateFSIfNotExist checks FS and creates one if not exist
	CreateFSIfNotExist(fsType fs.FileSystem, device, uuid string) error
	// CreateFakeDevice creates of fake block device
	CreateFakeDevice(src string) (string, error)
	fs.WrapFS
}

FSOperations is holds idempotent methods that consists of WrapFS methods

type FSOperationsImpl

type FSOperationsImpl struct {
	fs.WrapFS
	// contains filtered or unexported fields
}

FSOperationsImpl is a base implementation for FSOperation interface

func NewFSOperationsImpl

func NewFSOperationsImpl(e command.CmdExecutor, log *logrus.Logger) *FSOperationsImpl

NewFSOperationsImpl constructor for FSOperationsImpl and returns pointer on it

func (*FSOperationsImpl) CreateFSIfNotExist

func (fsOp *FSOperationsImpl) CreateFSIfNotExist(fsType fs.FileSystem, device, uuid string) error

CreateFSIfNotExist checks FS and creates one if not exist

CMD example:
	lsblk <device> --output FSTYPE --noheadings
	# Check output

	mkfs.<fsType> <device>

func (*FSOperationsImpl) CreateFakeDevice added in v1.4.0

func (fsOp *FSOperationsImpl) CreateFakeDevice(src string) (string, error)

CreateFakeDevice creates a fake device, which is actually a loop device mapped to a regular file created at src file path

func (*FSOperationsImpl) MountFakeTmpfs

func (fsOp *FSOperationsImpl) MountFakeTmpfs(volumeID, dst string) error

MountFakeTmpfs does attach of temp folder in read only mode

func (*FSOperationsImpl) PrepareAndPerformMount

func (fsOp *FSOperationsImpl) PrepareAndPerformMount(src, dst string, bindMount, dstIsDir bool, mountOptions ...string) error

PrepareAndPerformMount (idempotent) implementation of FSOperations method create (if isn't exist) dst folder on node and perform mount from src to dst if bindMount set to true - mount operation will contain "--bind" option if error occurs and dst has created during current method call then dst will be removed

func (*FSOperationsImpl) UnmountWithCheck

func (fsOp *FSOperationsImpl) UnmountWithCheck(path string) error

UnmountWithCheck idempotent implemetation of unmount operation check whether path is mounted and only if yes - try to unmount

type Partition

type Partition struct {
	Device    string
	Name      string
	Num       string
	TableType string
	Label     string
	PartUUID  string
}

Partition is hold all attributes of partition on block device

func (*Partition) GetFullPath

func (p *Partition) GetFullPath() string

GetFullPath return full path of partition, that path could be used for file system operations

type PartitionOperations

type PartitionOperations interface {
	// PreparePartition is fully prepare partition on node for use
	PreparePartition(p Partition) (*Partition, error)
	// ReleasePartition is fully release resources that had consumed by partition on node
	ReleasePartition(p Partition) error
	// SearchPartName returns partition name
	SearchPartName(device, partUUID string) (string, error)
	ph.WrapPartition
}

PartitionOperations is a high-level interface that encapsulates all low-level operations with partitions on node

type PartitionOperationsImpl

type PartitionOperationsImpl struct {
	ph.WrapPartition
	fs.WrapFS
	// contains filtered or unexported fields
}

PartitionOperationsImpl is a base implementation for PartitionOperations interface

func NewPartitionOperationsImpl

func NewPartitionOperationsImpl(e command.CmdExecutor, log *logrus.Logger) *PartitionOperationsImpl

NewPartitionOperationsImpl constructor for PartitionOperationsImpl and returns pointer on it

func (*PartitionOperationsImpl) PreparePartition

func (d *PartitionOperationsImpl) PreparePartition(p Partition) (*Partition, error)

PreparePartition completely creates and prepares partition p on node After that FS could be created on partition

func (*PartitionOperationsImpl) ReleasePartition

func (d *PartitionOperationsImpl) ReleasePartition(p Partition) error

ReleasePartition completely removes partition p

func (*PartitionOperationsImpl) SearchPartName

func (d *PartitionOperationsImpl) SearchPartName(device, partUUID string) (string, error)

SearchPartName search (with retries) partition with UUID partUUID on device and returns partition name e.g. "1" for /dev/sda1, "p1n1" for /dev/loopbackp1n1

Jump to

Keyboard shortcuts

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