Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getattr(self.device.format, "biosraid", False):
array_type = MDContainerDevice
except raid.RaidError as e:
log.error("failed to create md array: %s", e)
return
try:
md_array = array_type(
md_name,
level=md_level,
member_devices=md_devices,
uuid=md_uuid,
metadata_version=md_metadata,
exists=True
)
except (ValueError, DeviceError) as e:
log.error("failed to create md array: %s", e)
return
md_array.update_sysfs_path()
md_array.parents.append(self.device)
self._devicetree._add_device(md_array)
if md_array.status:
array_info = udev.get_device(md_array.sysfs_path)
if not array_info:
log.error("failed to get udev data for %s", md_array.name)
return
self._devicetree.handle_device(array_info, update_orig_fmt=True)
class DeviceCreateError(DeviceError):
pass
class DeviceDestroyError(DeviceError):
pass
class DeviceResizeError(DeviceError):
pass
class DeviceSetupError(DeviceError):
pass
class DeviceTeardownError(DeviceError):
pass
class DeviceUserDeniedFormatError(DeviceError):
pass
# DeviceFormat
class DeviceFormatError(StorageError):
pass
class FormatCreateError(DeviceFormatError):
pass
class FormatDestroyError(DeviceFormatError):
pass
class FormatSetupError(DeviceFormatError):
pass
class FormatTeardownError(DeviceFormatError):
def _pre_destroy(self):
""" Destroy the device. """
log_method_call(self, self.name, status=self.status)
if not self.media_present:
raise errors.DeviceError("cannot destroy disk with no media", self.name)
StorageDevice._pre_destroy(self)
def update_sysfs_path(self):
""" Update this device's sysfs path. """
# We're using os.path.exists as a stand-in for status. We can't use
# the status property directly because MDRaidArrayDevice.status calls
# this method.
log_method_call(self, self.name, status=os.path.exists(self.path))
if not self.exists:
raise errors.DeviceError("device has not been created", self.name)
try:
udev_device = pyudev.Devices.from_device_file(udev.global_udev,
self.path)
# from_device_file() does not process exceptions but just propagates
# any errors that are raised.
except (pyudev.DeviceNotFoundError, EnvironmentError, ValueError, OSError) as e:
log.error("failed to update sysfs path for %s: %s", self.name, e)
self.sysfs_path = ''
else:
self.sysfs_path = udev_device.sys_path
log.debug("%s sysfs_path set to %s", self.name, self.sysfs_path)
def _pre_destroy(self):
""" Preparation and precondition checking for device destruction. """
if not self.exists:
raise errors.DeviceError("device has not been created", self.name)
if not self.isleaf:
raise errors.DeviceError("Cannot destroy non-leaf device", self.name)
self.teardown()
def mdadmConfEntry(self):
uuid = self.mdadmFormatUUID
if not uuid:
raise errors.DeviceError("array is not fully defined", self.name)
return "ARRAY %s UUID=%s\n" % (self.path, uuid)
def _removeParent(self, member):
levels = (l for l in (self.dataLevel, self.metaDataLevel) if l)
for l in levels:
error_msg = self._validateParentRemoval(l, member)
if error_msg:
raise errors.DeviceError(error_msg)
super(BTRFSVolumeDevice, self)._removeParent(member)