Add the iscsi.py module that has common code used by the iscsi gui and text install. diff -uprN -X /home/patman/dontdiff anaconda-10.91.12/dispatch.py iscsi-anaconda-10.91.12/dispatch.py --- anaconda-10.91.12/dispatch.py 2006-01-31 07:51:55.000000000 -0800 +++ iscsi-anaconda-10.91.12/dispatch.py 2006-02-02 12:53:06.000000000 -0800 @@ -65,6 +65,7 @@ installSteps = [ ("findrootparts", findRootParts, ("intf", "id", "dispatch", "dir", "instPath")), ("findinstall", ("dispatch", "intf", "id", "instPath")), ("installtype", ("dispatch", "id", "method", "intf")), + ("iscsi", ("id.iscsi", "intf")), ("zfcpconfig", ("id.zfcp", "id.diskset", "intf")), ("partitionobjinit", partitionObjectsInitialize, ("id.diskset", "id.partitions", diff -uprN -X /home/patman/dontdiff anaconda-10.91.12/iscsi.py iscsi-anaconda-10.91.12/iscsi.py --- anaconda-10.91.12/iscsi.py 1969-12-31 16:00:00.000000000 -0800 +++ iscsi-anaconda-10.91.12/iscsi.py 2006-02-02 12:53:06.000000000 -0800 @@ -0,0 +1,131 @@ +# +# iscsi.py - iscsi class +# +# Copyright 2005 IBM +# +# This software may be freely redistributed under the terms of the GNU +# library public license. +# +# You should have received a copy of the GNU Library Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import os +import re +import string +import signal +import iutil +from flags import flags +import logging +log = logging.getLogger("anaconda") + +ISCSID_NAME="iscsid" + +# Note that stage2 copies all files under /sbin to /usr/sbin +ISCSID_BIN = "/usr/sbin/iscsid" +ISCSIADM = "/usr/sbin/iscsiadm" +ISCSID_DB_DIR="/var/db/iscsi" +INITIATOR_FILE="/etc/initiatorname.iscsi" + +class iscsi: + + def __init__(self): + self.ipaddr = "" + self.port = "3260" + self.initiator = "" + self.iscsidStarted = False + return + + def login_out(self, action): + # + # login or logout from all iSCSI targets. + # + # For each record (line of output) in: + # iscsiadm -m node + # + # Where each line in the output of the form: + # [recnum] stuff + # + # Strip out off the braces and trailing text, strip the trailing + # newline, and issue the "action" request to recnum. + # + command = ("%s -m node" % (ISCSIADM, )) + log.info("Running %s" % (command, )) + records = os.popen(command, 'r').readlines() + + regex = re.compile('\[ ( [^\]]* ) ].*', re.VERBOSE) + for i in records: + recnum = regex.sub(r'\1', i) + recnum = re.sub('\n', '', recnum) + command = ("%s -m node -r %s %s" % (ISCSIADM, recnum, action)) + log.info("Running %s" % (command, )) + os.system(command) + + def shutdown(self): + + if not self.iscsidStarted: + return + + log.info("iSCSI shutdown") + self.login_out("--logout") + + # Note that iscsid has/had code to ignore 2 (SIGINT), hence the + # 9 (SIGKILL). + command = ("ps -C %s" % (ISCSID_NAME)) + log.debug("Running popen %s" % (command, )) + psout = os.popen(command) + # Skip header line + psout.readline() + for line in psout.readlines(): + pid = string.atoi(string.split(line)[0]) + log.info("Killing %s %d" % (ISCSID_NAME, pid)) + os.kill(pid, signal.SIGKILL) + self.iscsidStarted = False; + + return + + def startup(self): + + log.info("iSCSI IP address %s, port %s" % (self.ipaddr, self.port)) + log.info("iSCSI initiator name %s", self.initiator) + + if flags.test: + return + + self.shutdown() + + if not self.ipaddr: + log.info("iSCSI: Not starting, no iscsi IP address specified") + return + + log.debug("Setting up %s" % (INITIATOR_FILE, )) + if os.path.exists(INITIATOR_FILE): + os.unlink(INITIATOR_FILE) + fd = os.open(INITIATOR_FILE, os.O_RDWR | os.O_CREAT) + os.write(fd, "InitiatorName=") + os.write(fd, self.initiator) + os.write(fd, "\n") + os.close(fd) + + if not os.path.exists(ISCSID_DB_DIR): + iutil.mkdirChain(ISCSID_DB_DIR) + + log.info("Starting %s" % (ISCSID_BIN, )) + os.system(ISCSID_BIN) + + command = ("%s -m discovery -t st -p %s:%s" + % (ISCSIADM, self.ipaddr, self.port)) + log.info("Running %s" % (command, )) + os.system(command) + + self.login_out("--login") + self.iscsidStarted = True; + + return + + def writeKS(self,fcpdevices): + # XXX + return + +# vim:tw=78:ts=4:et:sw=4