summaryrefslogtreecommitdiffstats
path: root/iscsi.py
diff options
context:
space:
mode:
authorHans de Goede <hans@localhost.localdomain>2008-09-15 10:01:41 +0200
committerHans de Goede <hans@localhost.localdomain>2008-09-15 10:01:41 +0200
commit71ff6b4602db9c033221772fe49a190a0732a82e (patch)
tree00e740a648034a61564bfcd5e196a99d2bfb0bcb /iscsi.py
parent5a21c1580eaed10c95bef003f460546d79265109 (diff)
downloadanaconda-71ff6b4602db9c033221772fe49a190a0732a82e.tar.gz
anaconda-71ff6b4602db9c033221772fe49a190a0732a82e.tar.xz
anaconda-71ff6b4602db9c033221772fe49a190a0732a82e.zip
Make iscsi/ibft work
Make iscsi/ibft work; with this it at least detects the iBFT and finds the disks. This is a forward port of a rhel-5 patch by pjones. commit id: d410362972805fa50444f9bd4bbfd4c985ae0313
Diffstat (limited to 'iscsi.py')
-rw-r--r--iscsi.py193
1 files changed, 108 insertions, 85 deletions
diff --git a/iscsi.py b/iscsi.py
index 02d661490..177647a34 100644
--- a/iscsi.py
+++ b/iscsi.py
@@ -35,64 +35,39 @@ _ = lambda x: gettext.ldgettext("anaconda", x)
# Note that stage2 copies all files under /sbin to /usr/sbin
-ISCSID="/usr/sbin/iscsid"
-ISCSIADM = "/usr/sbin/iscsiadm"
+global ISCSID
+ISCSID=""
+global ISCSIADM
+ISCSIADM = ""
INITIATOR_FILE="/etc/iscsi/initiatorname.iscsi"
+def find_iscsi_files():
+ global ISCSID
+ if ISCSID == "":
+ for dir in ("/usr/sbin", "/tmp/updates", "/mnt/source/RHupdates"):
+ path="%s/iscsid" % (dir,)
+ if os.access(path, os.X_OK):
+ ISCSID=path
+ global ISCSIADM
+ if ISCSIADM == "":
+ for dir in ("/usr/sbin", "/tmp/updates", "/mnt/source/RHupdates"):
+ path="%s/iscsiadm" % (dir,)
+ if os.access(path, os.X_OK):
+ ISCSIADM=path
def has_iscsi():
- if not os.access(ISCSID, os.X_OK) or not os.access(ISCSIADM, os.X_OK):
+ find_iscsi_files()
+ if ISCSID == "" or ISCSIADM == "":
return False
+
+ log.info("ISCSID is %s" % (ISCSID,))
+ log.info("ISCSIADM is %s" % (ISCSIADM,))
+
# make sure the module is loaded
if not os.access("/sys/module/iscsi_tcp", os.X_OK):
return False
return True
-def queryFirmware():
- # Example:
- # [root@elm3b87 ~]# iscsiadm -m fw
- # iface.initiatorname = iqn.2007-05.com.ibm.beaverton.elm3b87:01
- # iface.hwaddress = 00:14:5e:b3:8e:b2
- # node.name = iqn.1992-08.com.netapp:sn.84183797
- # node.conn[0].address = 9.47.67.152
- # node.conn[0].port = 3260
-
- retval = {}
-
- argv = [ "-m", "fw" ]
- result = iutil.execWithCapture(ISCSIADM, argv)
- result = result.strip()
- for line in result.split("\n"):
- SPLIT = " = "
- idx = line.find(SPLIT)
- if idx != -1:
- lhs = line[:idx]
- rhs = line[idx+len(SPLIT):]
- retval[lhs] = rhs
-
- return retval
-
-def loginToDefaultDrive():
- # Example:
- # [root@elm3b87 ~]# iscsiadm -m fw -l
- # Logging in to [iface: default, target: iqn.1992-08.com.netapp:sn.84183797, portal: 9.47.67.152,3260]
-
- argv = [ "-m", "fw", "-l" ]
- result = iutil.execWithCapture(ISCSIADM, argv)
-
- TARGET = "target: "
- PORTAL = ", portal: "
- END = "]"
- idxTarget = result.find (TARGET)
- idxPortal = result.find (PORTAL)
- idxEnd = result.find (END)
-
- if idxTarget == -1 or idxPortal == -1 or idxEnd == -1:
- return None
-
- return (result[idxTarget + len (TARGET) : idxPortal],
- result[idxPortal + len (PORTAL) : idxEnd].replace (',',':'))
-
class iscsiTarget:
def __init__(self, ipaddr, port = None, user = None, pw = None):
# FIXME: validate ipaddr
@@ -198,17 +173,16 @@ def randomIname():
class iscsi(object):
def __init__(self):
- self.fwinfo = queryFirmware()
+ self.fwinfo = self._queryFirmware()
self.targets = []
self._initiator = ""
self.initiatorSet = False
- self.iscsidStarted = False
- self.weStartedScsid = False
self.oldInitiatorFile = None
if self.fwinfo.has_key("iface.initiatorname"):
- self._initiator = self.fwinfo["iface.initiatorname"]
- self.initiatorSet = True
+ self._initiator = self.fwinfo["iface.initiatorname"]
+ self.initiatorSet = True
+ self.startup()
def _getInitiator(self):
if self._initiator != "":
@@ -229,6 +203,60 @@ class iscsi(object):
initiator = property(_getInitiator, _setInitiator)
+ def _queryFirmware(self):
+ # Example:
+ # [root@elm3b87 ~]# iscsiadm -m fw
+ # iface.initiatorname = iqn.2007-05.com.ibm.beaverton.elm3b87:01
+ # iface.hwaddress = 00:14:5e:b3:8e:b2
+ # node.name = iqn.1992-08.com.netapp:sn.84183797
+ # node.conn[0].address = 9.47.67.152
+ # node.conn[0].port = 3260
+
+ find_iscsi_files()
+
+ retval = {}
+
+ argv = [ "-m", "fw" ]
+ log.debug("queryFirmware: ISCSIADM is %s" % (ISCSIADM,))
+ result = iutil.execWithCapture(ISCSIADM, argv)
+ result = result.strip()
+ for line in result.split("\n"):
+ SPLIT = " = "
+ idx = line.find(SPLIT)
+ if idx != -1:
+ lhs = line[:idx]
+ rhs = line[idx+len(SPLIT):]
+ retval[lhs] = rhs
+
+ return retval
+
+
+ def _startIscsiDaemon(self):
+ psout = iutil.execWithCapture("/usr/bin/pidof", ["iscsid"])
+ if psout.strip() == "":
+ log.info("iSCSI startup")
+ iutil.execWithRedirect(ISCSID, [],
+ stdout="/dev/tty5", stderr="/dev/tty5")
+ time.sleep(2)
+
+ def _stopIscsiDaemon(self):
+ result = iutil.execWithCapture(ISCSIADM, ["-k", "0"])
+ result.strip()
+ if result == "":
+ return
+
+ psout = iutil.execWithCapture("/usr/bin/pidof", ["iscsid"])
+ if psout.strip() != "":
+ log.info("iSCSI shutdown")
+ for t in self.targets:
+ t.logout()
+
+ for pidstr in psout.split():
+ pid = string.atoi(pidstr)
+ login.info("killing %s %d" % (ISCSID, pid))
+
+ os.kill(pid, signal.SIGKILL)
+
def shutdown(self):
if flags.test:
if self.oldInitiatorFile != None:
@@ -237,37 +265,36 @@ class iscsi(object):
f.write(line)
f.close ()
self.oldInitiatorFile = None
+ self._stopIscsiDaemon()
- if not self.iscsidStarted:
- return
+ def loginToDefaultDrive(self):
+ # Example:
+ # [root@elm3b87 ~]# iscsiadm -m fw -l
+ # Logging in to [iface: default, target: iqn.1992-08.com.netapp:sn.84183797, portal: 9.47.67.152,3260]
- log.info("iSCSI shutdown")
- for t in self.targets:
- t.logout()
+ find_iscsi_files()
- if self.weStartedScsid:
- self.weStartedScsid = False
+ argv = [ "-m", "fw", "-l" ]
+ result = iutil.execWithCapture(ISCSIADM, argv)
+ #result = result.strip()
- # XXX use iscsiadm shutdown when it's available.
- psout = iutil.execWithCapture("/usr/bin/pidof", ["iscsiadm"])
- if psout.strip() != "":
- pid = string.atoi(psout.split()[0])
- log.info("Killing %s %d" % (ISCSID, pid))
- os.kill(pid, signal.SIGKILL)
+ TARGET = "target: "
+ PORTAL = ", portal: "
+ END = "]"
+ idxTarget = result.find (TARGET)
+ idxPortal = result.find (PORTAL)
+ idxEnd = result.find (END)
+
+ if idxTarget == -1 or idxPortal == -1 or idxEnd == -1:
+ return None
- self.iscsidStarted = False;
+ return (result[idxTarget + len (TARGET) : idxPortal],
+ result[idxPortal + len (PORTAL) : idxEnd].replace (',',':'))
def startup(self, intf = None):
- if self.iscsidStarted:
- return
if not has_iscsi():
return
- # If there is a default drive in the iSCSI configuration, then automatically
- # attach to it. Do this before testing the initiator name, because it
- # is provided by the iBFT too
- loginToDefaultDrive()
-
if not self.initiatorSet:
log.info("no initiator set")
return
@@ -279,6 +306,13 @@ class iscsi(object):
log.info("iSCSI initiator name %s", self.initiator)
+ self._startIscsiDaemon()
+
+ # If there is a default drive in the iSCSI configuration, then
+ # automatically attach to it. Do this before testing the initiator
+ # name, because it is provided by the iBFT too
+ self.loginToDefaultDrive()
+
if intf:
w = intf.waitWindow(_("Initializing iSCSI initiator"),
_("Initializing iSCSI initiator"))
@@ -292,17 +326,6 @@ class iscsi(object):
os.write(fd, "InitiatorName=%s\n" %(self.initiator))
os.close(fd)
- psout = iutil.execWithCapture("/usr/bin/pidof", ["iscsiadm"])
- if psout.strip() == "":
- self.weStartedScsid = False
-
- log.info("ISCSID is %s" % (ISCSID,))
- iutil.execWithRedirect(ISCSID, [],
- stdout="/dev/tty5", stderr="/dev/tty5")
- time.sleep(2)
-
- self.iscsidStarted = True
-
for t in self.targets:
if not t.discover():
continue