[PATCH 2/2] Make the fcoe, iscsi and zfcp classes singletons

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

 



The fcoe, iscsi and zfcp classes are designed to be instantiated only once,
currently this is not enforced. This is causing trouble as their single
instantiation currently is done in storage.__init__, which means they cannot
be used before instData is instantiated, as that instantiates storage.

However we need them to connect to fcoe, iscsi and/or zfcp drives while
parsing kickstart files (so the drivers can be referenced by UUID /
/dev/disk/by-path / whatever), and instData is not yet instantiated at that
time.

So this patch uses a very simple Singleton design pattern, so that we can
instantiate them where ever we need them, and all references returned will
will point to one shared global instance.
---
 storage/fcoe.py  |   19 +++++++++++++++++++
 storage/iscsi.py |   20 ++++++++++++++++++++
 storage/zfcp.py  |   18 ++++++++++++++++++
 3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/storage/fcoe.py b/storage/fcoe.py
index 906c8c0..5a09f5d 100644
--- a/storage/fcoe.py
+++ b/storage/fcoe.py
@@ -40,12 +40,28 @@ def has_fcoe():
     return os.access("/sys/module/fcoe", os.X_OK)
 
 class fcoe(object):
+    """ FCoE utility class.
+
+        This class will automatically discover and connect to EDD configured
+        FCoE SAN's when the startup() method gets called. It can also be
+        used to manually configure FCoE SAN's through the addSan() method.
+
+        As this class needs to make sure certain things like starting fcoe
+        daemons and connecting to firmware discovered SAN's only happens once
+        and as it keeps a global list of all FCoE devices it is
+        implemented as a Singleton.
+    """
+
     def __init__(self):
         self.started = False
         self.dcbdStarted = False
         self.fcoemonStarted = False
         self.nics = []
 
+    # So that users can write fcoe() to get the singleton instance
+    def __call__(self):
+        return self
+
     def _stabilize(self, intf = None):
         if intf:
             w = intf.waitWindow(_("Connecting to FCoE SAN"),
@@ -143,4 +159,7 @@ class fcoe(object):
 
         return
 
+# Create FCoE singleton
+fcoe = fcoe()
+
 # vim:tw=78:ts=4:et:sw=4
diff --git a/storage/iscsi.py b/storage/iscsi.py
index 5bf6d28..809e266 100644
--- a/storage/iscsi.py
+++ b/storage/iscsi.py
@@ -90,6 +90,19 @@ def stabilize(intf = None):
         w.pop()
 
 class iscsi(object):
+    """ iSCSI utility class.
+
+        This class will automatically discover and login to iBFT (or
+        other firmware) configured iscsi devices when the startup() method
+        gets called. It can also be used to manually configure iscsi devices
+        through the addTarget() method.
+
+        As this class needs to make sure certain things like starting iscsid
+        and logging in to firmware discovered disks only happens once 
+        and as it keeps a global list of all iSCSI devices it is implemented as
+        a Singleton.
+    """
+
     def __init__(self):
         # This list contains all nodes
         self.nodes = []
@@ -107,6 +120,10 @@ class iscsi(object):
             except:
                 pass
 
+    # So that users can write iscsi() to get the singleton instance
+    def __call__(self):
+        return self
+
     def _getInitiator(self):
         if self._initiator != "":
             return self._initiator
@@ -307,4 +324,7 @@ class iscsi(object):
 
         return nodeDisks
 
+# Create iscsi singleton
+iscsi = iscsi()
+
 # vim:tw=78:ts=4:et:sw=4
diff --git a/storage/zfcp.py b/storage/zfcp.py
index 47271b9..277ccec 100644
--- a/storage/zfcp.py
+++ b/storage/zfcp.py
@@ -323,11 +323,26 @@ class ZFCPDevice:
         return True
 
 class ZFCP:
+    """ ZFCP utility class.
+
+        This class will automatically online to ZFCP drives configured in
+        /tmp/fcpconfig when the startup() method gets called. It can also be
+        used to manually configure ZFCP devices through the addFCP() method.
+
+        As this class needs to make sure that /tmp/fcpconfig configured
+        drives are only onlined once and as it keeps a global list of all ZFCP
+        devices it is implemented as a Singleton.
+    """
+
     def __init__(self):
         self.fcpdevs = []
         self.hasReadConfig = False
         self.down = True
 
+    # So that users can write zfcp() to get the singleton instance
+    def __call__(self):
+        return self
+
     def readConfig(self):
         try:
             f = open("/tmp/fcpconfig", "r")
@@ -420,4 +435,7 @@ class ZFCP:
         f.write("alias scsi_hostadapter zfcp\n")
         f.close()
 
+# Create ZFCP singleton
+zfcp = zfcp()
+
 # vim:tw=78:ts=4:et:sw=4
-- 
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