Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
label_regex = r'(?P<label>.*)'
@property
def args(self):
return [self.fs.device]
class Ext2FSReadLabel(FSReadLabel):
ext = availability.E2LABEL_APP
label_regex = r'(?P<label>.*)'
@property
def args(self):
return [self.fs.device]
class NTFSReadLabel(FSReadLabel):
ext = availability.NTFSLABEL_APP
label_regex = r'(?P<label>.*)'
@property
def args(self):
return [self.fs.device]
class XFSReadLabel(FSReadLabel):
ext = availability.XFSADMIN_APP
label_regex = r'label = "(?P<label>.*)"'
@property
def args(self):
return ["-l", self.fs.device]
class UnimplementedFSReadLabel(fstask.UnimplementedFSTask):
pass</label></label></label></label>
def is_mpath_member(self, device):
"""Checks if the given device is a member of some multipath mapping or not.
:param str device: path of the device to query
"""
if self._members is None and availability.BLOCKDEV_MPATH_PLUGIN.available:
self._members = set(blockdev.mpath.get_mpath_members())
device = os.path.realpath(device)
device = device[len("/dev/"):]
return device in self._members
st = os.stat(self.path)
size = Size(st.st_size)
return size
class DMRaidArrayDevice(DMDevice, ContainerDevice):
""" A dmraid (device-mapper RAID) device """
_type = "dm-raid array"
_packages = ["dmraid"]
_partitionable = True
_is_disk = True
_format_class_name = property(lambda s: "dmraidmember")
_format_uuid_attr = property(lambda s: None)
_external_dependencies = [availability.BLOCKDEV_DM_PLUGIN_RAID]
def __init__(self, name, fmt=None,
size=None, parents=None, sysfs_path='', wwn=None):
"""
:param name: the device name (generally a device node's basename)
:type name: str
:keyword size: the device's size
:type size: :class:`~.size.Size`
:keyword parents: a list of parent devices
:type parents: list of :class:`StorageDevice`
:keyword fmt: this device's formatting
:type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
:keyword sysfs_path: sysfs device path
:type sysfs_path: str
:keyword str wwn: the device's WWN
try:
pv_info = blockdev.lvm.pvinfo(self.pv.device)
pv_size = pv_info.pv_size
except blockdev.LVMError as e:
raise PhysicalVolumeError(e)
return Size(pv_size)
class PVResize(task.BasicApplication, dfresize.DFResizeTask):
""" Handle resize of the LVMPV format. """
description = "resize the LVMPV format"
ext = availability.BLOCKDEV_LVM_PLUGIN
unit = B
def __init__(self, a_pv):
""" Initializer.
:param :class:`~.formats.lvmpv.LVMPhysicalVolume` a_pv: a LVMPV format object
"""
self.pv = a_pv
def do_task(self):
""" Resizes the LVMPV format. """
try:
blockdev.lvm.pvresize(self.pv.device, self.pv.target_size.convert_to(self.unit))
except blockdev.LVMError as e:
raise PhysicalVolumeError(e)
class NTFSWriteLabel(FSWriteLabel):
ext = availability.NTFSLABEL_APP
@property
def args(self):
return [self.fs.device, self.fs.label]
class ReiserFSWriteLabel(FSWriteLabel):
ext = availability.REISERFSTUNE_APP
@property
def args(self):
return ["-l", self.fs.label, self.fs.device]
class XFSWriteLabel(FSWriteLabel):
ext = availability.XFSADMIN_APP
@property
def args(self):
return ["-L", self.fs.label if self.fs.label != "" else "--", self.fs.device]
class UnimplementedFSWriteLabel(fstask.UnimplementedFSTask):
pass
8: "Corrupt filesystem, repairs did not succeed.",
47: "Major error found; no repairs attempted."}
ext = availability.FSCK_HFSPLUS_APP
options = []
def _error_message(self, rc):
if rc < 1:
return None
try:
return self._fsck_errors[rc]
except KeyError:
return _UNKNOWN_RC_MSG % rc
class NTFSFSCK(FSCK):
ext = availability.NTFSRESIZE_APP
options = ["-c"]
def _error_message(self, rc):
return _UNKNOWN_RC_MSG % (rc,) if rc != 0 else None
class UnimplementedFSCK(fstask.UnimplementedFSTask):
pass
import logging
log = logging.getLogger("blivet")
from .storage import StorageDevice
from .container import ContainerDevice
from .raid import RaidDevice
class MDRaidArrayDevice(ContainerDevice, RaidDevice):
""" An mdraid (Linux RAID) device. """
_type = "mdarray"
_packages = ["mdadm"]
_devDir = "/dev/md"
_formatClassName = property(lambda s: "mdmember")
_formatUUIDAttr = property(lambda s: "mdUuid")
_external_dependencies = [availability.BLOCKDEV_MDRAID_PLUGIN]
def __init__(self, name, level=None, major=None, minor=None, size=None,
memberDevices=None, totalDevices=None,
uuid=None, fmt=None, exists=False, metadataVersion=None,
parents=None, sysfsPath=''):
"""
:param name: the device name (generally a device node's basename)
:type name: str
:keyword exists: does this device exist?
:type exists: bool
:keyword size: the device's size
:type size: :class:`~.size.Size`
:keyword parents: a list of parent devices
:type parents: list of :class:`StorageDevice`
:keyword fmt: this device's formatting
:type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
log = logging.getLogger("blivet")
class LVMPhysicalVolume(DeviceFormat):
""" An LVM physical volume. """
_type = "lvmpv"
_name = N_("physical volume (LVM)")
_udevTypes = ["LVM2_member"]
partedFlag = PARTITION_LVM
_formattable = True # can be formatted
_supported = True # is supported
_linuxNative = True # for clearpart
_minSize = lvm.LVM_PE_SIZE * 2 # one for metadata and one for data
_packages = ["lvm2"] # required packages
_ksMountpoint = "pv."
_plugin = availability.BLOCKDEV_LVM_PLUGIN
def __init__(self, **kwargs):
"""
:keyword device: path to the block device node
:keyword uuid: this PV's uuid (not the VG uuid)
:keyword exists: indicates whether this is an existing format
:type exists: bool
:keyword vgName: the name of the VG this PV belongs to
:keyword vgUuid: the UUID of the VG this PV belongs to
:keyword peStart: offset of first physical extent
:type peStart: :class:`~.size.Size`
:keyword dataAlignment: data alignment (for non-existent PVs)
:type dataAlignment: :class:`~.size.Size`
.. note::
# No bytes specification is described in the man pages. A number without
# any suffix is interpreted as indicating the number of filesystem blocks.
# A suffix of "s" specifies a 512 byte sector. It is omitted here because
# the lookup is only by standard binary units.
size_fmt = {KiB: "%dK", MiB: "%dM", GiB: "%dG"}[unit]
def size_spec(self):
return self.size_fmt % self.fs.target_size.convert_to(self.unit)
@property
def args(self):
return ["-p", self.fs.device, self.size_spec()]
class NTFSResize(FSResize):
ext = availability.NTFSRESIZE_APP
unit = B
size_fmt = {B: "%d", KB: "%dK", MB: "%dM", GB: "%dG"}[unit]
def size_spec(self):
return self.size_fmt % self.fs.target_size.convert_to(self.unit)
@property
def args(self):
return [
"-ff", # need at least two 'f's to fully suppress interaction
"-s", self.size_spec(),
self.fs.device
]
class TmpFSResize(FSResize):
def needs_config_refresh(fn):
if not availability.BLOCKDEV_LVM_PLUGIN.available:
return lambda *args, **kwargs: None
def fn_with_refresh(*args, **kwargs):
ret = fn(*args, **kwargs)
_set_global_config()
return ret
return fn_with_refresh