[blivet:master 2/3] Move mixin class from devices.py to devices_lib.py

mulhern amulhern at redhat.com
Thu Oct 2 16:08:15 UTC 2014


Make it officially abstract on the way.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/__init__.py    |  4 ++--
 blivet/devices.py     | 38 +++++++-------------------------------
 blivet/devices_lib.py | 27 +++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/blivet/__init__.py b/blivet/__init__.py
index c015fb7..7e82b7d 100644
--- a/blivet/__init__.py
+++ b/blivet/__init__.py
@@ -67,8 +67,8 @@ from pykickstart.constants import AUTOPART_TYPE_LVM, CLEARPART_TYPE_ALL, CLEARPA
 
 from .storage_log import log_exception_info, log_method_call
 from .errors import DeviceError, DirtyFSError, FSResizeError, FSTabTypeMismatchError, UnknownSourceDeviceError, StorageError, UnrecognizedFSTabEntryError
-from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice, DirectoryDevice, FileDevice, LVMLogicalVolumeDevice, LVMThinLogicalVolumeDevice, LVMThinPoolDevice, LVMVolumeGroupDevice, MDRaidArrayDevice, NetworkStorageDevice, NFSDevice, NoDevice, OpticalDevice, PartitionDevice, TmpFSDevice
-from .devices_lib import devicePathToName
+from .devices import BTRFSDevice, BTRFSSubVolumeDevice, BTRFSVolumeDevice, DirectoryDevice, FileDevice, LVMLogicalVolumeDevice, LVMThinLogicalVolumeDevice, LVMThinPoolDevice, LVMVolumeGroupDevice, MDRaidArrayDevice, NFSDevice, NoDevice, OpticalDevice, PartitionDevice, TmpFSDevice
+from .devices_lib import devicePathToName, NetworkStorageDevice
 from .devicetree import DeviceTree
 from .deviceaction import ActionCreateDevice, ActionCreateFormat, ActionDestroyDevice, ActionDestroyFormat, ActionResizeDevice, ActionResizeFormat
 from .formats import getFormat
diff --git a/blivet/devices.py b/blivet/devices.py
index 227e4a5..e2c1aa2 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -337,30 +337,6 @@ class Device(util.ObjectID):
         # By default anything goes
         return True
 
-
-class NetworkStorageDevice(object):
-    """ Virtual base class for network backed storage devices """
-
-    def __init__(self, host_address=None, nic=None):
-        """ Note this class is only to be used as a baseclass and then only with
-            multiple inheritance. The only correct use is:
-            class MyStorageDevice(StorageDevice, NetworkStorageDevice):
-
-            The sole purpose of this class is to:
-            1) Be able to check if a StorageDevice is network backed
-               (using isinstance).
-            2) To be able to get the host address of the host (server) backing
-               the storage *or* the NIC through which the storage is connected
-
-            :keyword host_address: host address of the backing server
-            :type host_address: str
-            :keyword nic: NIC to which the block device is bound
-            :type nic: str
-        """
-        self.host_address = host_address
-        self.nic = nic
-
-
 class StorageDevice(Device):
     """ A generic storage device.
 
@@ -4481,7 +4457,7 @@ class LoopDevice(StorageDevice):
         return self.parents[0]
 
 
-class iScsiDiskDevice(DiskDevice, NetworkStorageDevice):
+class iScsiDiskDevice(DiskDevice, devices_lib.NetworkStorageDevice):
     """ An iSCSI disk. """
     _type = "iscsi"
     _packages = ["iscsi-initiator-utils", "dracut-network"]
@@ -4521,14 +4497,14 @@ class iScsiDiskDevice(DiskDevice, NetworkStorageDevice):
             address = kwargs.pop("fw_address")
             port = kwargs.pop("fw_port")
             DiskDevice.__init__(self, device, **kwargs)
-            NetworkStorageDevice.__init__(self,
+            devices_lib.NetworkStorageDevice.__init__(self,
                                           host_address=address,
                                           nic=self.nic)
             log.debug("created new iscsi disk %s %s:%s using fw initiator %s",
                       name, address, port, self.initiator)
         else:
             DiskDevice.__init__(self, device, **kwargs)
-            NetworkStorageDevice.__init__(self, host_address=self.node.address,
+            devices_lib.NetworkStorageDevice.__init__(self, host_address=self.node.address,
                                           nic=self.nic)
             log.debug("created new iscsi disk %s %s:%d via %s:%s", self.node.name,
                                                                    self.node.address,
@@ -4569,7 +4545,7 @@ class iScsiDiskDevice(DiskDevice, NetworkStorageDevice):
 
         return set([netroot, initiator])
 
-class FcoeDiskDevice(DiskDevice, NetworkStorageDevice):
+class FcoeDiskDevice(DiskDevice, devices_lib.NetworkStorageDevice):
     """ An FCoE disk. """
     _type = "fcoe"
     _packages = ["fcoe-utils", "dracut-network"]
@@ -4592,7 +4568,7 @@ class FcoeDiskDevice(DiskDevice, NetworkStorageDevice):
         self.nic = kwargs.pop("nic")
         self.identifier = kwargs.pop("identifier")
         DiskDevice.__init__(self, device, **kwargs)
-        NetworkStorageDevice.__init__(self, nic=self.nic)
+        devices_lib.NetworkStorageDevice.__init__(self, nic=self.nic)
         log.debug("created new fcoe disk %s (%s) @ %s",
                   device, self.identifier, self.nic)
 
@@ -4790,7 +4766,7 @@ class DASDDevice(DiskDevice):
         else:
             return set(["rd.dasd=%s" % self.busid])
 
-class NFSDevice(StorageDevice, NetworkStorageDevice):
+class NFSDevice(StorageDevice, devices_lib.NetworkStorageDevice):
     """ An NFS device """
     _type = "nfs"
     _packages = ["dracut-network"]
@@ -4806,7 +4782,7 @@ class NFSDevice(StorageDevice, NetworkStorageDevice):
         """
         # we could make host/ip, path, &c but will anything use it?
         StorageDevice.__init__(self, device, fmt=fmt, parents=parents)
-        NetworkStorageDevice.__init__(self, device.split(":")[0])
+        devices_lib.NetworkStorageDevice.__init__(self, device.split(":")[0])
 
     @property
     def path(self):
diff --git a/blivet/devices_lib.py b/blivet/devices_lib.py
index 079600d..2f66c7f 100644
--- a/blivet/devices_lib.py
+++ b/blivet/devices_lib.py
@@ -21,6 +21,10 @@
 #                    Anne Mulhern <amulhern at redhat.com>
 #
 
+import abc
+
+from six import add_metaclass
+
 from . import errors
 from . import udev
 
@@ -159,3 +163,26 @@ class ParentList(object):
 
         self.removefunc(y)
         self.items.remove(y)
+
+ at add_metaclass(abc.ABCMeta)
+class NetworkStorageDevice(object):
+    """ Virtual base class for network backed storage devices """
+
+    def __init__(self, host_address=None, nic=None):
+        """ Note this class is only to be used as a baseclass and then only with
+            multiple inheritance. The only correct use is:
+            class MyStorageDevice(StorageDevice, NetworkStorageDevice):
+
+            The sole purpose of this class is to:
+            1) Be able to check if a StorageDevice is network backed
+               (using isinstance).
+            2) To be able to get the host address of the host (server) backing
+               the storage *or* the NIC through which the storage is connected
+
+            :keyword host_address: host address of the backing server
+            :type host_address: str
+            :keyword nic: NIC to which the block device is bound
+            :type nic: str
+        """
+        self.host_address = host_address
+        self.nic = nic
-- 
1.9.3



More information about the anaconda-patches mailing list