From 62c783264ac426aaac946ead099bd9ecf452debf Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Thu, 19 Jul 2012 17:16:39 -0500
Subject: [PATCH 05/16] Use parents consistently in Device constructors.

---
 pyanaconda/kickstart.py            |    8 ++++----
 pyanaconda/storage/__init__.py     |   15 +++------------
 pyanaconda/storage/devices.py      |   14 +++++++-------
 pyanaconda/storage/partitioning.py |   10 ++++------
 4 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index de46e38..3ec2f3c 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -611,7 +611,7 @@ class LogVolData(commands.logvol.F17_LogVolData):
 
             request = storage.newLV(format=format,
                                     name=self.name,
-                                    vg=vg,
+                                    parents=[vg],
                                     size=self.size,
                                     grow=self.grow,
                                     maxsize=self.maxSizeMB,
@@ -937,12 +937,12 @@ class PartitionData(commands.partition.F17_PartData):
 
                 should_clear = storage.shouldClear(disk)
                 if disk and (disk.partitioned or should_clear):
-                    kwargs["disks"] = [disk]
+                    kwargs["parents"] = [disk]
                     break
                 elif disk:
                     raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified unpartitioned disk %s in partition command" % self.disk)
 
-            if not kwargs["disks"]:
+            if not kwargs["parents"]:
                 raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified nonexistent disk %s in partition command" % self.disk)
 
         kwargs["grow"] = self.grow
@@ -1222,7 +1222,7 @@ class VolGroupData(commands.volgroup.FC16_VolGroupData):
         elif self.vgname in [vg.name for vg in storage.vgs]:
             raise KickstartValueError(formatErrorMsg(self.lineno, msg="The volume group name \"%s\" is already in use." % self.vgname))
         else:
-            request = storage.newVG(pvs=pvs,
+            request = storage.newVG(parents=pvs,
                                     name=self.vgname,
                                     peSize=self.pesize/1024.0)
 
diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index b37794a..a4ca648 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1111,13 +1111,6 @@ class Storage(object):
                                                                None),
                                          **kwargs.pop("fmt_args", {}))
 
-        if kwargs.has_key("disks"):
-            parents = kwargs.pop("disks")
-            if isinstance(parents, Device):
-                kwargs["parents"] = [parents]
-            else:
-                kwargs["parents"] = parents
-
         if kwargs.has_key("name"):
             name = kwargs.pop("name")
         else:
@@ -1146,7 +1139,7 @@ class Storage(object):
 
     def newVG(self, *args, **kwargs):
         """ Return a new LVMVolumeGroupDevice instance. """
-        pvs = kwargs.pop("pvs", [])
+        pvs = kwargs.pop("parents", [])
         for pv in pvs:
             if pv not in self.devices:
                 raise ValueError("pv is not in the device tree")
@@ -1170,9 +1163,7 @@ class Storage(object):
 
     def newLV(self, *args, **kwargs):
         """ Return a new LVMLogicalVolumeDevice instance. """
-        if kwargs.has_key("vg"):
-            vg = kwargs.pop("vg")
-
+        vg = kwargs.get("parents")[0]
         mountpoint = kwargs.pop("mountpoint", None)
         if kwargs.has_key("fmt_type"):
             kwargs["format"] = getFormat(kwargs.pop("fmt_type"),
@@ -1193,7 +1184,7 @@ class Storage(object):
         if name in self.names:
             raise ValueError("name already in use")
 
-        return LVMLogicalVolumeDevice(name, vg, *args, **kwargs)
+        return LVMLogicalVolumeDevice(name, *args, **kwargs)
 
     def newBTRFS(self, *args, **kwargs):
         """ Return a new BTRFSVolumeDevice or BRFSSubVolumeDevice. """
diff --git a/pyanaconda/storage/devices.py b/pyanaconda/storage/devices.py
index 8c2713b..8552179 100644
--- a/pyanaconda/storage/devices.py
+++ b/pyanaconda/storage/devices.py
@@ -1964,7 +1964,7 @@ class LVMVolumeGroupDevice(DMDevice):
     _type = "lvmvg"
     _packages = ["lvm2"]
 
-    def __init__(self, name, parents, size=None, free=None,
+    def __init__(self, name, parents=None, size=None, free=None,
                  peSize=None, peCount=None, peFree=None, pvCount=None,
                  uuid=None, exists=False, sysfsPath=''):
         """ Create a LVMVolumeGroupDevice instance.
@@ -2387,7 +2387,7 @@ class LVMLogicalVolumeDevice(DMDevice):
     _resizable = True
     _packages = ["lvm2"]
 
-    def __init__(self, name, vgdev, size=None, uuid=None,
+    def __init__(self, name, parents=None, size=None, uuid=None,
                  stripes=1, logSize=0, snapshotSpace=0,
                  format=None, exists=False, sysfsPath='',
                  grow=None, maxsize=None, percent=None,
@@ -2418,15 +2418,15 @@ class LVMLogicalVolumeDevice(DMDevice):
                     percent -- percent of VG space to take
 
         """
-        if isinstance(vgdev, list):
-            if len(vgdev) != 1:
+        if isinstance(parents, list):
+            if len(parents) != 1:
                 raise ValueError("constructor requires a single LVMVolumeGroupDevice instance")
-            elif not isinstance(vgdev[0], LVMVolumeGroupDevice):
+            elif not isinstance(parents[0], LVMVolumeGroupDevice):
                 raise ValueError("constructor requires a LVMVolumeGroupDevice instance")
-        elif not isinstance(vgdev, LVMVolumeGroupDevice):
+        elif not isinstance(parents, LVMVolumeGroupDevice):
             raise ValueError("constructor requires a LVMVolumeGroupDevice instance")
         DMDevice.__init__(self, name, size=size, format=format,
-                          sysfsPath=sysfsPath, parents=vgdev,
+                          sysfsPath=sysfsPath, parents=parents,
                           exists=exists)
 
         self.singlePVerr = ("%(mountpoint)s is restricted to a single "
diff --git a/pyanaconda/storage/partitioning.py b/pyanaconda/storage/partitioning.py
index 74eb685..7126a61 100644
--- a/pyanaconda/storage/partitioning.py
+++ b/pyanaconda/storage/partitioning.py
@@ -86,7 +86,7 @@ def _scheduleImplicitPartitions(storage, disks):
         part = storage.newPartition(fmt_type=fmt_type,
                                                 fmt_args=fmt_args,
                                                 grow=True,
-                                                disks=[disk])
+                                                parents=[disk])
         storage.createDevice(part)
         devs.append(part)
 
@@ -165,7 +165,7 @@ def _schedulePartitions(storage, disks):
                                             grow=request.grow,
                                             maxsize=request.maxSize,
                                             mountpoint=request.mountpoint,
-                                            disks=disks,
+                                            parents=disks,
                                             weight=request.weight)
 
         # schedule the device for creation
@@ -193,12 +193,10 @@ def _scheduleVolumes(storage, devs):
         new_container = storage.newVG
         new_volume = storage.newLV
         format_name = "lvmpv"
-        parent_kw = "pvs"
     else:
         new_container = storage.newBTRFS
         new_volume = storage.newBTRFS
         format_name = "btrfs"
-        parent_kw = "parents"
 
     if storage.encryptedAutoPart:
         pvs = []
@@ -213,7 +211,7 @@ def _scheduleVolumes(storage, devs):
         pvs = devs
 
     # create a vg containing all of the autopart pvs
-    container = new_container(**{parent_kw: pvs})
+    container = new_container(parents=pvs)
     storage.createDevice(container)
 
     #
@@ -252,7 +250,7 @@ def _scheduleVolumes(storage, devs):
         kwargs = {"mountpoint": request.mountpoint,
                   "fmt_type": request.fstype}
         if lv:
-            kwargs.update({"vg": container,
+            kwargs.update({"parents": [container],
                            "grow": request.grow,
                            "maxsize": request.maxSize,
                            "size": request.size,
-- 
1.7.7.6

