[PATCH 2/3] Add a "dict" attribute to Device and DeviceFormat classes.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This attribute is a dict that describes the device or format instance
with considerable detail. It is intended that the dict will be
pickled using the shelve module, so values should be picklable objects.
Keys should be descriptive strings.
---
 storage/devices.py           |   69 ++++++++++++++++++++++++++++++++++++++++++
 storage/formats/__init__.py  |    8 +++++
 storage/formats/disklabel.py |   10 ++++++
 storage/formats/fs.py        |    9 +++++
 storage/formats/luks.py      |    9 +++++
 storage/formats/lvmpv.py     |    7 ++++
 storage/formats/mdraid.py    |    6 ++++
 storage/formats/swap.py      |    6 ++++
 8 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index 1065a68..1355474 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -270,6 +270,12 @@ class Device(object):
               "status": self.status, "dev_id": self.id})
         return s
 
+    @property
+    def dict(self):
+        d =  {"type": self.type, "name": self.name,
+              "parents": [p.name for p in self.parents]}
+        return d
+
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
         return
 
@@ -525,6 +531,16 @@ class StorageDevice(Device):
         return s
 
     @property
+    def dict(self):
+        d =  super(StorageDevice, self).dict
+        d.update({"uuid": self.uuid, "size": self.size,
+                  "format": self.format.dict, "removable": self.removable,
+                  "major": self.major, "minor": self.minor,
+                  "exists": self.exists, "sysfs": self.sysfsPath,
+                  "targetSize": self.targetSize, "path": self.path})
+        return d
+
+    @property
     def path(self):
         """ Device node representing this device. """
         return "%s/%s" % (self._devDir, self.name)
@@ -943,6 +959,22 @@ class PartitionDevice(StorageDevice):
 
         return s
 
+    @property
+    def dict(self):
+        d = super(PartitionDevice, self).dict
+        d.update({"type": self.partType})
+        if not self.exists:
+            d.update({"grow": self.req_grow, "maxsize": self.req_max_size,
+                      "bootable": self.bootable,
+                      "primary": self.req_primary})
+
+        if self.partedPartition:
+            d.update({"length": self.partedPartition.geometry.length,
+                      "start": self.partedPartition.geometry.start,
+                      "end": self.partedPartition.geometry.end,
+                      "flags": self.partedPartition.getFlagsAsString()})
+        return d
+
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
         args = []
 
@@ -1379,6 +1411,12 @@ class DMDevice(StorageDevice):
         return s
 
     @property
+    def dict(self):
+        d = super(DMDevice, self).dict
+        d.update({"target": self.target, "dmUuid": self.dmUuid})
+        return d
+
+    @property
     def fstabSpec(self):
         """ Return the device specifier for use in /etc/fstab. """
         return self.path
@@ -1638,6 +1676,17 @@ class LVMVolumeGroupDevice(DMDevice):
                "freeExtents": self.freeExtents, "pvs": self.pvs, "lvs": self.lvs})
         return s
 
+    @property
+    def dict(self):
+        d = super(LVMVolumeGroupDevice, self).dict
+        d.update({"free": self.free, "peSize": self.peSize,
+                  "peCount": self.peCount, "peFree": self.peFree,
+                  "pvCount": self.pvCount, "extents": self.extents,
+                  "freeSpace": self.freeSpace,
+                  "freeExtents": self.freeExtents,
+                  "lvNames": [lv.name for lv in self.lvs]})
+        return d
+
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
         args = ["--pesize=%s" % int(self.peSize * 1024)]
         pvs = []
@@ -2041,6 +2090,18 @@ class LVMLogicalVolumeDevice(DMDevice):
                "snapshots": self.snapshotSpace, "vgspace": self.vgSpaceUsed })
         return s
 
+    @property
+    def dict(self):
+        d = super(LVMLogicalVolumeDevice, self).dict
+        if self.exists:
+            d.update({"mirrored": self.mirrored, "stripes": self.stripes,
+                      "snapshots": self.snapshotSpace,
+                      "vgspace": self.vgSpaceUsed})
+        else:
+            d.update({"percent": self.req_percent})
+
+        return d
+
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
         args = ["--name=%s" % self.lvname,
                 "--vgname=%s" % self.vg.name]
@@ -2341,6 +2402,14 @@ class MDRaidArrayDevice(StorageDevice):
                "memberDevices": self.memberDevices, "totalDevices": self.totalDevices})
         return s
 
+    @property
+    def dict(self):
+        d = super(MDRaidArrayDevice, self).dict
+        d.update({"level": self.level, "bitmap": self.bitmap,
+                  "spares": self.spares, "memberDevices": self.memberDevices,
+                  "totalDevices": self.totalDevices})
+        return d
+
     def writeKS(self, f, preexisting=False, noformat=False, s=None):
         args = ["--level=%s" % self.level,
                 "--device=%s" % self.name]
diff --git a/storage/formats/__init__.py b/storage/formats/__init__.py
index 8e479b6..adf5ef1 100644
--- a/storage/formats/__init__.py
+++ b/storage/formats/__init__.py
@@ -187,6 +187,14 @@ class DeviceFormat(object):
               "format": self.formattable, "resize": self.resizable})
         return s
 
+    @property
+    def dict(self):
+        d = {"type": self.type, "name": self.name, "device": self.device,
+             "uuid": self.uuid, "exists": self.exists,
+             "options": self.options, "supported": self.supported,
+             "resizable": self.resizable}
+        return d
+
     def _setOptions(self, options):
         self._options = options
 
diff --git a/storage/formats/disklabel.py b/storage/formats/disklabel.py
index e5c5631..e5fab94 100644
--- a/storage/formats/disklabel.py
+++ b/storage/formats/disklabel.py
@@ -101,6 +101,16 @@ class DiskLabel(DeviceFormat):
                "dev": self.partedDevice})
         return s
 
+    @property
+    def dict(self):
+        d = super(DiskLabel, self).dict
+        d.update({"labelType": self.labelType,
+                  "partitionCount": len(self.partitions),
+                  "sectorSize": self.partedDevice.sectorSize,
+                  "offset": self.alignment.offset,
+                  "grainSize": self.alignment.grainSize})
+        return d
+
     def resetPartedDisk(self):
         """ Set this instance's partedDisk to reflect the disk's contents. """
         log_method_call(self, device=self.device)
diff --git a/storage/formats/fs.py b/storage/formats/fs.py
index 09e764d..b07bd4a 100644
--- a/storage/formats/fs.py
+++ b/storage/formats/fs.py
@@ -172,6 +172,15 @@ class FS(DeviceFormat):
                "targetSize": self.targetSize})
         return s
 
+    @property
+    def dict(self):
+        d = super(FS, self).dict
+        d.update({"mountpoint": self.mountpoint, "size": self._size,
+                  "label": self.label, "targetSize": self.targetSize,
+                  "mountable": self.mountable,
+                  "migratable": self.migratable})
+        return d
+
     def _setTargetSize(self, newsize):
         """ Set a target size for this filesystem. """
         if not self.exists:
diff --git a/storage/formats/luks.py b/storage/formats/luks.py
index 1105a6f..880f652 100644
--- a/storage/formats/luks.py
+++ b/storage/formats/luks.py
@@ -108,6 +108,15 @@ class LUKS(DeviceFormat):
         return s
 
     @property
+    def dict(self):
+        d = super(LUKS, self).dict
+        d.update({"cipher": self.cipher, "keySize": self.key_size,
+                  "mapName": self.mapName, "hasKey": self.hasKey,
+                  "escrowCert": self.escrow_cert,
+                  "backup": self.add_backup_passphrase})
+        return d
+
+    @property
     def name(self):
         name = self._name
         # for existing locked devices, show "Encrypted" instead of LUKS
diff --git a/storage/formats/lvmpv.py b/storage/formats/lvmpv.py
index 67fa751..9fe9ba3 100644
--- a/storage/formats/lvmpv.py
+++ b/storage/formats/lvmpv.py
@@ -75,6 +75,13 @@ class LVMPhysicalVolume(DeviceFormat):
                "peStart": self.peStart})
         return s
 
+    @property
+    def dict(self):
+        d = super(LVMPhysicalVolume, self).dict
+        d.update({"vgName": self.vgName, "vgUUID": self.vgUuid,
+                  "peStart": self.peStart})
+        return d
+
     def probe(self):
         """ Probe for any missing information about this device. """
         log_method_call(self, device=self.device,
diff --git a/storage/formats/mdraid.py b/storage/formats/mdraid.py
index eeef943..b26abfc 100644
--- a/storage/formats/mdraid.py
+++ b/storage/formats/mdraid.py
@@ -71,6 +71,12 @@ class MDRaidMember(DeviceFormat):
         s += ("  mdUUID = %(mdUUID)s" % {"mdUUID": self.mdUuid})
         return s
 
+    @property
+    def dict(self):
+        d = super(MDRaidMember, self).dict
+        d.update({"mdUUID": self.mdUuid, "biosraid": self.biosraid})
+        return d
+
     def probe(self):
         """ Probe for any missing information about this format. """
         log_method_call(self, device=self.device,
diff --git a/storage/formats/swap.py b/storage/formats/swap.py
index 0d96fb1..f7538c2 100644
--- a/storage/formats/swap.py
+++ b/storage/formats/swap.py
@@ -69,6 +69,12 @@ class SwapSpace(DeviceFormat):
               {"priority": self.priority, "label": self.label})
         return s
 
+    @property
+    def dict(self):
+        d = super(SwapSpace, self).dict
+        d.update({"priority": self.priority, "label": self.label})
+        return d
+
     def _setPriority(self, priority):
         if priority is None:
             self._priority = None
-- 
1.6.5.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux