diff options
author | Hans de Goede <hdegoede@redhat.com> | 2009-12-14 11:45:35 +0100 |
---|---|---|
committer | Hans de Goede <hdegoede@redhat.com> | 2009-12-15 03:59:22 +0100 |
commit | 3bc6873f1e9229114cafce1c05e30e7407606b5a (patch) | |
tree | 35243a98c251ca18ce2ef9ea95255ec65367e6a0 /storage | |
parent | 65a2ef051a842e09f374b77b14c6dc983a9bdfc8 (diff) | |
download | anaconda-3bc6873f1e9229114cafce1c05e30e7407606b5a.tar.gz anaconda-3bc6873f1e9229114cafce1c05e30e7407606b5a.tar.xz anaconda-3bc6873f1e9229114cafce1c05e30e7407606b5a.zip |
Make the fcoe, iscsi and zfcp classes singletons
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.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/fcoe.py | 19 | ||||
-rw-r--r-- | storage/iscsi.py | 20 | ||||
-rw-r--r-- | storage/zfcp.py | 18 |
3 files changed, 57 insertions, 0 deletions
diff --git a/storage/fcoe.py b/storage/fcoe.py index 906c8c013..5a09f5d27 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 3d391cd40..aac6e3b98 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 47271b96e..7692cad2b 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 |