[PATCH 1/2][blivet] Add a method to apply Blivet settings to ksdata.
David Lehman
dlehman at redhat.com
Wed Jun 12 17:22:53 UTC 2013
Related: rhbz#929119
---
blivet/__init__.py | 105 +++++++++++++++++++++++++++++++++++++++++++++
blivet/devices.py | 90 ++++++++++++++++++++++++++++++++++++++
blivet/formats/__init__.py | 10 +++++
blivet/formats/fs.py | 11 +++++
blivet/formats/lvmpv.py | 1 +
blivet/formats/mdraid.py | 1 +
6 files changed, 218 insertions(+)
diff --git a/blivet/__init__.py b/blivet/__init__.py
index d9fbbd6..c924f42 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -1964,6 +1964,111 @@ class Blivet(object):
device.format.mountpoint = mountpoint # for future mounts
device.format._mountpoint = mountpoint # active mountpoint
+ def updateKSData(self):
+ """ Update ksdata to reflect the settings of this Blivet instance. """
+ if not self.ksdata:
+ return
+
+ # clear out whatever was there before
+ self.ksdata.partition.partitions = []
+ self.ksdata.logvol.lvList = []
+ self.ksdata.raid.raidList = []
+ self.ksdata.volgroup.vgList = []
+ self.ksdata.btrfs.btrfsList = []
+
+ # iscsi?
+ # fcoe?
+ # zfcp?
+ # dmraid?
+
+ # bootloader
+
+ # ignoredisk
+ if self.config.ignoredDisks:
+ self.ksdata.ignoredisk.drives = self.config.ignoredDisks[:]
+ elif self.config.exclusiveDisks:
+ self.ksdata.ignoredisk.onlyuse = self.config.exclusiveDisks[:]
+
+ # autopart
+ self.ksdata.autopart.autopart = self.doAutoPart
+ self.ksdata.autopart.type = self.autoPartType
+ self.ksdata.autopart.encrypted = self.encryptedAutoPart
+
+ # clearpart
+ self.ksdata.clearpart.type = self.config.clearPartType
+ self.ksdata.clearpart.drives = self.config.clearPartDisks[:]
+ self.ksdata.clearpart.devices = self.config.clearPartDevices[:]
+ self.ksdata.clearpart.initAll = self.config.initializeDisks
+ if self.ksdata.clearpart.type == CLEARPART_TYPE_NONE:
+ # Make a list of initialized disks and of removed partitions. If any
+ # partitions were removed from disks that were not completely
+ # cleared we'll have to use CLEARPART_TYPE_LIST and provide a list
+ # of all removed partitions. If no partitions were removed from a
+ # disk that was not cleared/reinitialized we can use
+ # CLEARPART_TYPE_ALL.
+ self.ksdata.clearpart.devices = []
+ self.ksdata.clearpart.drives = []
+ fresh_disks = [d.name for d in self.disks if d.partitioned and
+ not d.format.exists]
+
+ destroy_actions = self.devicetree.findActions(type="destroy",
+ object="device")
+
+ cleared_partitions = []
+ partial = False
+ for action in destroy_actions:
+ if action.device.type == "partition":
+ if action.device.disk.name not in fresh_disks:
+ partial = True
+
+ cleared_partitions.append(action.device.name)
+
+ if not destroy_actions:
+ pass
+ elif partial:
+ # make a list of removed partitions
+ self.ksdata.clearpart.type = CLEARPART_TYPE_LIST
+ self.ksdata.clearpart.devices = cleared_partitions
+ else:
+ # if they didn't partially clear any disks, use the shorthand
+ self.ksdata.clearpart.type = CLEARPART_TYPE_ALL
+ self.ksdata.clearpart.drives = fresh_disks
+
+ if self.doAutoPart:
+ return
+
+ # custom storage
+
+ dataMap = {PartitionDevice: "PartData",
+ LVMLogicalVolumeDevice: "LogVolData",
+ LVMVolumeGroupDevice: "VolGroupData",
+ MDRaidArrayDevice: "RaidData",
+ BTRFSDevice: "BTRFSData"}
+
+ listMap = {PartitionDevice: "partition",
+ LVMLogicalVolumeDevice: "logvol",
+ LVMVolumeGroupDevice: "volgroup",
+ MDRaidArrayDevice: "raid",
+ BTRFSDevice: "btrfs"}
+
+ # make a list of ancestors of all used devices
+ devices = list(set(a for d in self.mountpoints.values() + self.swaps
+ for a in d.ancestors))
+ devices.sort(key=lambda d: len(d.ancestors))
+ for device in devices:
+ class_attr = dataMap.get(device.__class__)
+ list_attr = listMap.get(device.__class__)
+ if not class_attr or not list_attr:
+ log.info("omitting ksdata: %s" % device)
+ continue
+
+ cls = getattr(self.ksdata, class_attr)
+ data = cls() # all defaults
+
+ device.populateKSData(data)
+
+ parent = getattr(self.ksdata, list_attr)
+ parent.dataList().append(data)
def mountExistingSystem(fsset, rootDevice,
allowDirty=None, dirtyCB=None,
diff --git a/blivet/devices.py b/blivet/devices.py
index 1587b91..f2232ee 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -986,6 +986,20 @@ class StorageDevice(Device):
return -1
return 0
+ def populateKSData(self, data):
+ # the common pieces are basically the formatting
+ self.format.populateKSData(data)
+
+ # this is a little bit of a hack for container member devices that
+ # need aliases, but even more of a hack for btrfs since you cannot tell
+ # from inside the BTRFS class whether you're dealing with a member or a
+ # volume/subvolume
+ if self.format.type == "btrfs" and not isinstance(self, BTRFSDevice):
+ data.mountpoint = "btrfs." # continued below, also for lvm, raid
+
+ if data.mountpoint.endswith("."):
+ data.mountpoint += str(self.id)
+
class DiskDevice(StorageDevice):
""" A disk """
_type = "disk"
@@ -1711,6 +1725,24 @@ class PartitionDevice(StorageDevice):
return -1
return 0
+ def populateKSData(self, data):
+ super(PartitionDevice, self).populateKSData(data)
+ data.resize = (self.exists and self.targetSize and
+ self.targetSize != self.currentSize)
+ if not self.exists:
+ data.size = int(self.req_base_size)
+ data.grow = self.req_grow
+ data.maxSizeMB = self.req_max_size
+ ##data.disk = self.disk.name # by-id
+ if self.req_disks and len(self.req_disks) == 1:
+ data.disk = self.disk.name
+ data.primOnly = self.req_primary
+ else:
+ data.onPart = self.name # by-id
+
+ if data.resize:
+ data.size = int(self.size)
+
class DMDevice(StorageDevice):
""" A device-mapper device """
_type = "dm"
@@ -1966,6 +1998,11 @@ class LUKSDevice(DMCryptDevice):
def dracutSetupArgs(self):
return set(["rd.luks.uuid=luks-%s" % self.slave.format.uuid])
+ def populateKSData(self, data):
+ self.slave.populateKSData(data)
+ data.encrypted = True
+ super(LUKSDevice, self).populateKSData(data)
+
class LVMVolumeGroupDevice(DMDevice):
""" An LVM Volume Group
@@ -2388,6 +2425,16 @@ class LVMVolumeGroupDevice(DMDevice):
return len(self.pvs) == self.pvCount or not self.exists
+ def populateKSData(self, data):
+ super(LVMVolumeGroupDevice, self).populateKSData(data)
+ data.vgname = self.name
+ data.physvols = ["pv.%d" % p.id for p in self.parents]
+ data.preexist = self.exists
+ if not self.exists:
+ data.pesize = self.peSize * 1024
+
+ # reserved percent/space
+
class LVMLogicalVolumeDevice(DMDevice):
""" An LVM Logical Volume """
@@ -2661,6 +2708,25 @@ class LVMLogicalVolumeDevice(DMDevice):
return -1
return 0
+ def populateKSData(self, data):
+ super(LVMLogicalVolumeDevice, self).populateKSData(data)
+ data.vgname = self.vg.name
+ data.name = self.lvname
+ data.preexist = self.exists
+ data.resize = (self.exists and self.targetSize and
+ self.targetSize != self.currentSize)
+ if not self.exists:
+ data.grow = self.req_grow
+ if self.req_grow:
+ data.size = int(self.req_size)
+ data.maxSizeMB = self.req_max_size
+ else:
+ data.size = int(self.size)
+
+ data.percent = self.req_percent
+ elif data.resize:
+ data.size = int(self.targetSize)
+
class MDRaidArrayDevice(StorageDevice):
""" An mdraid (Linux RAID) device. """
_type = "mdarray"
@@ -3212,6 +3278,17 @@ class MDRaidArrayDevice(StorageDevice):
def dracutSetupArgs(self):
return set(["rd.md.uuid=%s" % self.uuid])
+ def populateKSData(self, data):
+ if self.isDisk:
+ return
+
+ super(MDRaidArrayDevice, self).populateKSData(data)
+ data.level = self.level
+ data.spares = self.spares
+ data.members = ["raid.%d" % p.id for p in self.parents]
+ data.preexist = self.exists
+ data.device = self.name
+
class DMRaidArrayDevice(DMDevice):
""" A dmraid (device-mapper RAID) device """
_type = "dm-raid array"
@@ -4196,6 +4273,13 @@ class BTRFSVolumeDevice(BTRFSDevice):
device.setup(orig=True)
DeviceFormat(device=device.path, exists=True).destroy()
+ def populateKSData(self, data):
+ super(BTRFSVolumeDevice, self).populateKSData(data)
+ data.dataLevel = self.dataLevel
+ data.metaDataLevel = self.metaDataLevel
+ data.devices = ["btrfs.%d" % p.id for p in self.parents]
+ data.preexist = self.exists
+
class BTRFSSubVolumeDevice(BTRFSDevice):
""" A btrfs subvolume pseudo-device. """
_type = "btrfs subvolume"
@@ -4233,3 +4317,9 @@ class BTRFSSubVolumeDevice(BTRFSDevice):
raise RuntimeError("btrfs subvol destroy requires mounted volume")
btrfs.delete_subvolume(mountpoint, self.name)
self.volume._undo_temp_mount()
+
+ def populateKSData(self, data):
+ super(BTRFSSubVolumeDevice, self).populateKSData(data)
+ data.subvol = True
+ data.name = self.name
+ data.preexist = self.exists
diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index f018c6c..67ac996 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -160,6 +160,7 @@ class DeviceFormat(object):
_dump = False
_check = False
_hidden = False # hide devices with this formatting?
+ _ksMountpoint = None
def __init__(self, *args, **kwargs):
""" Create a DeviceFormat instance.
@@ -439,4 +440,13 @@ class DeviceFormat(object):
(udev_device_get_major(dev), udev_device_get_minor(dev))
return self._majorminor
+ @property
+ def ksMountpoint(self):
+ return (self._ksMountpoint or self.type or "")
+
+ def populateKSData(self, data):
+ data.format = not self.exists
+ data.fstype = self.type
+ data.mountpoint = self.ksMountpoint
+
collect_device_format_classes()
diff --git a/blivet/formats/fs.py b/blivet/formats/fs.py
index ed7eac3..641c81b 100644
--- a/blivet/formats/fs.py
+++ b/blivet/formats/fs.py
@@ -801,6 +801,17 @@ class FS(DeviceFormat):
def sync(self, root="/"):
pass
+ def populateKSData(self, data):
+ super(FS, self).populateKSData(data)
+ data.mountpoint = self.mountpoint or "none"
+ data.label = self.label or ""
+ if self.options != "defaults":
+ data.fsopts = self.options
+ else:
+ data.fsopts = ""
+
+ data.fsprofile = self.fsprofile or ""
+
class Ext2FS(FS):
""" ext2 filesystem. """
_type = "ext2"
diff --git a/blivet/formats/lvmpv.py b/blivet/formats/lvmpv.py
index 300b849..4111ad0 100644
--- a/blivet/formats/lvmpv.py
+++ b/blivet/formats/lvmpv.py
@@ -46,6 +46,7 @@ class LVMPhysicalVolume(DeviceFormat):
_linuxNative = True # for clearpart
_minSize = lvm.LVM_PE_SIZE * 2 # one for metadata and one for data
_packages = ["lvm2"] # required packages
+ _ksMountpoint = "pv."
def __init__(self, *args, **kwargs):
""" Create an LVMPhysicalVolume instance.
diff --git a/blivet/formats/mdraid.py b/blivet/formats/mdraid.py
index a99dec8..44d111e 100644
--- a/blivet/formats/mdraid.py
+++ b/blivet/formats/mdraid.py
@@ -46,6 +46,7 @@ class MDRaidMember(DeviceFormat):
_supported = True # is supported
_linuxNative = True # for clearpart
_packages = ["mdadm"] # required packages
+ _ksMountpoint = "raid."
def __init__(self, *args, **kwargs):
""" Create a MDRaidMember instance.
--
1.8.1.4
More information about the anaconda-patches
mailing list