def create(self, *args, **kwargs): """ Create the format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.hasKey: raise LUKSError("luks device has no key/passphrase") intf = kwargs.get("intf") w = None if intf: w = intf.waitWindow(_("Formatting"), _("Encrypting %s") % kwargs.get("device", self.device)) try: DeviceFormat.create(self, *args, **kwargs) crypto.luks_format(self.device, passphrase=self.__passphrase, key_file=self._key_file, cipher=self.cipher, key_size=self.key_size) except Exception: raise else: self.uuid = crypto.luks_uuid(self.device) self.exists = True self.mapName = "luks-%s" % self.uuid self.notifyKernel() finally: if w: w.pop()
def destroy(self, *args, **kwargs): log_method_call(self, device=self.device, type=self.type, status=self.status) raise MultipathMemberError( "destruction of multipath members is non-sense")
def create(self, *args, **kwargs): """ Create the format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) intf = kwargs.get("intf") w = None if intf: w = intf.progressWindow(_("Formatting"), _("Creating %(type)s on %(device)s") % {"type": self.type, "device": self.device}, 100, pulse = True) try: DeviceFormat.create(self, *args, **kwargs) # Consider use of -Z|--zero # -f|--force or -y|--yes may be required # lvm has issues with persistence of metadata, so here comes the # hammer... DeviceFormat.destroy(self, *args, **kwargs) lvm.pvcreate(self.device, progress=w) except Exception: raise else: self.exists = True self.notifyKernel() finally: if w: w.pop()
def create(self, *args, **kwargs): """ Create the device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) intf = kwargs.get("intf") force = kwargs.get("force") if not force and self.exists: raise SwapSpaceError("format already exists") if force: self.teardown() elif self.status: raise SwapSpaceError("device exists and is active") w = None if intf: w = intf.progressWindow(_("Formatting"), _("Creating %(type)s on %(device)s") % {"type": self.type, "device": kwargs.get("device", self.device)}, 100, pulse = True) try: DeviceFormat.create(self, *args, **kwargs) swap.mkswap(self.device, label=self.label, progress=w) except Exception: raise else: self.exists = True self.notifyKernel() finally: if w: w.pop()
def create(self, *args, **kwargs): """ Create the format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) intf = kwargs.get("intf") w = None if intf: w = intf.progressWindow(_("Formatting"), _("Creating %(type)s on %(device)s") % { "type": self.type, "device": self.device }, 100, pulse=True) try: DeviceFormat.create(self, *args, **kwargs) # Consider use of -Z|--zero # -f|--force or -y|--yes may be required # lvm has issues with persistence of metadata, so here comes the # hammer... DeviceFormat.destroy(self, *args, **kwargs) lvm.pvcreate(self.device, progress=w) except Exception: raise else: self.exists = True self.notifyKernel() finally: if w: w.pop()
def teardown(self, *args, **kwargs): """ Close, or tear down, a device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise DeviceFormatError("format has not been created")
def probe(self): """ Probe for any missing information about this device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise PhysicalVolumeError("format has not been created")
def commitToDisk(self): """ Commit the current partition table to disk. """ log_method_call(self, device=self.device, numparts=len(self.partitions)) try: self.partedDisk.commitToDevice() except parted.DiskException as msg: raise DiskLabelCommitError(msg)
def teardown(self, *args, **kwargs): """ Close, or tear down, a device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise SwapSpaceError("format has not been created") if self.status: swap.swapoff(self.device)
def setup(self, *args, **kwargs): log_method_call(self, type=self.mountType, device=self.device, mountpoint=self.mountpoint) if not self.mountpoint and "mountpoint" not in kwargs: # Since btrfs vols have subvols the format setup is automatic. # Don't try to mount it if there's no mountpoint. return return self.mount(*args, **kwargs)
def create(self, *args, **kwargs): log_method_call(self, device=self.device, type=self.type, status=self.status) # allow late specification of device path device = kwargs.get("device") if device: self.device = device if not os.path.exists(self.device): raise FormatCreateError("invalid device specification", self.device)
def teardown(self, *args, **kwargs): """ Close, or tear down, the format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise LUKSError("format has not been created") if self.status: log.debug("unmapping %s" % self.mapName) crypto.luks_close(self.mapName)
def commit(self): """ Commit the current partition table to disk and notify the OS. """ log_method_call(self, device=self.device, numparts=len(self.partitions)) try: self.partedDisk.commit() except parted.DiskException as msg: raise DiskLabelCommitError(msg) else: udev_settle()
def removePassphrase(self, passphrase): """ Remove the specified passphrase from the LUKS header. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise LUKSError("format has not been created") crypto.luks_remove_key(self.device, passphrase=self.__passphrase, key_file=self._key_file, del_passphrase=passphrase)
def setup(self, *args, **kwargs): """ Open, or set up, a device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise DeviceFormatError("format has not been created") if self.status: return DeviceFormat.setup(self, *args, **kwargs)
def notifyKernel(self): log_method_call(self, device=self.device, type=self.type) if not self.device: return if self.device.startswith("/dev/mapper/"): try: name = dm_node_from_name(os.path.basename(self.device)) except Exception, e: log.warning("failed to get dm node for %s" % self.device) return
def probe(self): """ Probe for any missing information about this format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise MDMemberError("format does not exist") info = mdraid.mdexamine(self.device) if self.uuid is None: self.uuid = info['uuid'] if self.raidMinor is None: self.raidMinor = info['mdMinor']
def destroy(self, *args, **kwargs): """ Wipe the disklabel from the device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise DeviceFormatError("format does not exist") if not os.access(self.device, os.W_OK): raise DeviceFormatError("device path does not exist") self.partedDevice.clobber() self.exists = False
def setup(self, *args, **kwargs): """ Open, or set up, the format. """ log_method_call(self, device=self.device, mapName=self.mapName, type=self.type, status=self.status) if not self.configured: raise LUKSError("luks device not configured") if self.status: return DeviceFormat.setup(self, *args, **kwargs) crypto.luks_open(self.device, self.mapName, passphrase=self.__passphrase, key_file=self._key_file)
def addPassphrase(self, passphrase): """ Add a new passphrase. Add the specified passphrase to an available key slot in the LUKS header. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise LUKSError("format has not been created") crypto.luks_add_key(self.device, passphrase=self.__passphrase, key_file=self._key_file, new_passphrase=passphrase)
def removeKeyFromFile(self, keyfile): """ Remove a key contained in a file. Remove key contained in the specified key file from the LUKS header. """ log_method_call(self, device=self.device, type=self.type, status=self.status, file=keyfile) if not self.exists: raise LUKSError("format has not been created") crypto.luks_remove_key(self.device, passphrase=self.__passphrase, key_file=self._key_file, del_key_file=keyfile)
def addKeyFromFile(self, keyfile): """ Add a new key from a file. Add the contents of the specified key file to an available key slot in the LUKS header. """ log_method_call(self, device=self.device, type=self.type, status=self.status, file=keyfile) if not self.exists: raise LUKSError("format has not been created") crypto.luks_add_key(self.device, passphrase=self.__passphrase, key_file=self._key_file, new_key_file=keyfile)
def __init__(self, *args, **kwargs): """ Create a SwapSpace instance. Keyword Arguments: device -- path to the underlying device uuid -- this swap space's uuid label -- this swap space's label priority -- this swap space's priority exists -- indicates whether this is an existing format """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) self.priority = kwargs.get("priority") self.label = kwargs.get("label")
def __init__(self, *args, **kwargs): """ Create a DeviceFormat instance. Keyword Arguments: device -- path to the underlying device uuid -- this format's UUID exists -- indicates whether this is an existing format On initialization this format is like DeviceFormat """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) # Initialize the attribute that will hold the block object. self._member = None
def setup(self, *args, **kwargs): log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise FormatSetupError("format has not been created") if self.status: return # allow late specification of device path device = kwargs.get("device") if device: self.device = device if not self.device or not os.path.exists(self.device): raise FormatSetupError("invalid device specification")
def __init__(self, *args, **kwargs): """ Create a MDRaidMember instance. Keyword Arguments: device -- path to underlying device uuid -- this member device's uuid mdUuid -- the uuid of the array this device belongs to exists -- indicates whether this is an existing format """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) self.mdUuid = kwargs.get("mdUuid") self.raidMinor = None #self.probe() self.biosraid = kwargs.get("biosraid")
def create(self, *args, **kwargs): """ Create the device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if self.exists: raise DeviceFormatError("format already exists") if self.status: raise DeviceFormatError("device exists and is active") DeviceFormat.create(self, *args, **kwargs) # We're relying on someone having called resetPartedDisk -- we # could ensure a fresh disklabel by setting self._partedDisk to # None right before calling self.commit(), but that might hide # other problems. self.commit() self.exists = True
def destroy(self, *args, **kwargs): """ Destroy the format. """ log_method_call(self, device=self.device, type=self.type, status=self.status) if not self.exists: raise PhysicalVolumeError("format has not been created") if self.status: raise PhysicalVolumeError("device is active") # FIXME: verify path exists? try: lvm.pvremove(self.device) except LVMError: DeviceFormat.destroy(self, *args, **kwargs) self.exists = False self.notifyKernel()
def destroy(self, *args, **kwargs): log_method_call(self, device=self.device, type=self.type, status=self.status) try: rc = execWithRedirect("wipefs", ["-a", self.device], stderr="/dev/tty5", stdout="/dev/tty5") except Exception as e: err = str(e) else: err = "" if rc: err = str(rc) if err: msg = "error wiping old signatures from %s: %s" % (self.device, err) raise FormatDestroyError(msg) self.exists = False
def __init__(self, *args, **kwargs): """ Create an LVMPhysicalVolume instance. Keyword Arguments: device -- path to the underlying device uuid -- this PV's uuid (not the VG uuid) vgName -- the name of the VG this PV belongs to vgUuid -- the UUID of the VG this PV belongs to peStart -- offset of first physical extent exists -- indicates whether this is an existing format """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) self.vgName = kwargs.get("vgName") self.vgUuid = kwargs.get("vgUuid") # liblvm may be able to tell us this at some point, even # for not-yet-created devices self.peStart = kwargs.get("peStart", 1.0) # in MB
def notifyKernel(self): log_method_call(self, device=self.device, type=self.type) if not self.device: return if self.device.startswith("/dev/mapper/"): try: name = dm_node_from_name(os.path.basename(self.device)) except DMError: log.warning("failed to get dm node for %s" % self.device) return else: name = self.device path = get_sysfs_path_by_name(name) try: notify_kernel(path, action="change") except (ValueError, IOError) as e: log.warning("failed to notify kernel of change: %s" % e)
def _build_topology(self): log_method_call(self) self._build_devmap() self._build_mpath_topology() for dev in self._devices: name = dev['name'] if not udev_device_is_disk(dev): self._nondisks.append(name) log.info("MultipathTopology: found non-disk device: %s" % name) continue mpath_name = self.multipath_name(name) if mpath_name: dev["ID_FS_TYPE"] = "multipath_member" dev["ID_MPATH_NAME"] = mpath_name log.info("MultipathTopology: found a multipath member of %s: %s " % (mpath_name, name)) continue # it's a disk and not a multipath member (can be a coalesced # multipath) self._singlepaths.append(name) log.info("MultipathTopology: found singlepath device: %s" % name)
def __init__(self, *args, **kwargs): """ Create a LUKS instance. Keyword Arguments: device -- the path to the underlying device name -- the name of the mapped device uuid -- this device's UUID passphrase -- device passphrase (string) key_file -- path to a file containing a key (string) cipher -- cipher mode string key_size -- key size in bits exists -- indicates whether this is an existing format escrow_cert -- certificate to use for key escrow add_backup_passphrase -- generate a backup passphrase? """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) self.cipher = kwargs.get("cipher") self.key_size = kwargs.get("key_size") self.mapName = kwargs.get("name") if not self.exists and not self.cipher: self.cipher = "aes-xts-plain64" if not self.key_size: # default to the max (512 bits) for aes-xts self.key_size = 512 # FIXME: these should both be lists, but managing them will be a pain self.__passphrase = kwargs.get("passphrase") self._key_file = kwargs.get("key_file") self.escrow_cert = kwargs.get("escrow_cert") self.add_backup_passphrase = kwargs.get("add_backup_passphrase", False) if not self.mapName and self.exists and self.uuid: self.mapName = "luks-%s" % self.uuid elif not self.mapName and self.device: self.mapName = "luks-%s" % os.path.basename(self.device)
def __init__(self, *args, **kwargs): """ Create a DiskLabel instance. Keyword Arguments: device -- path to the underlying device exists -- indicates whether this is an existing format """ log_method_call(self, *args, **kwargs) DeviceFormat.__init__(self, *args, **kwargs) self._size = None self._partedDevice = None self._partedDisk = None self._origPartedDisk = None self._alignment = None self._endAlignment = None if self.partedDevice: # set up the parted objects and raise exception on failure self._origPartedDisk = self.partedDisk.duplicate()
def create(self, *args, **kwargs): """ Create the device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) intf = kwargs.get("intf") force = kwargs.get("force") if not force and self.exists: raise SwapSpaceError("format already exists") if force: self.teardown() elif self.status: raise SwapSpaceError("device exists and is active") w = None if intf: w = intf.progressWindow( _("Formatting"), _("Creating %(type)s on %(device)s") % { "type": self.type, "device": kwargs.get("device", self.device) }, 100, pulse=True) try: DeviceFormat.create(self, *args, **kwargs) swap.mkswap(self.device, label=self.label, progress=w) except Exception: raise else: self.exists = True finally: if w: w.pop()