summaryrefslogtreecommitdiffstats
path: root/iscsi.py
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2006-02-09 18:43:41 +0000
committerJeremy Katz <katzj@redhat.com>2006-02-09 18:43:41 +0000
commit9d73cbacc7cde3c4a8bad96bffb6190c927dc30b (patch)
tree3615ea940cc54c03b114623702fbe2359622ac6b /iscsi.py
parentc7d5222375e20b6eeba938b91d0db1904774f235 (diff)
downloadanaconda-9d73cbacc7cde3c4a8bad96bffb6190c927dc30b.tar.gz
anaconda-9d73cbacc7cde3c4a8bad96bffb6190c927dc30b.tar.xz
anaconda-9d73cbacc7cde3c4a8bad96bffb6190c927dc30b.zip
2006-02-09 Patrick Mansfield <patmans@us.ibm.com>
* anaconda: Add handling of iscsi flag * flags.py: Add iscsi flag * installclass.py: Add iscsi step * dispatch.py: Add iscsi step. * gui.py: Add iscsi step. * text.py: Add iscsi step * instdata.py: Add iscsi object * iscsi.py: Add main iscsi code * iw/iscsi_gui.py: Add graphical iSCSI configuration * ui/iscsi-config.glade: Glade-file for iSCSI config * textw/iscsi_text.py: Add text mode iSCSI configuration * scripts/mk-images (SCSIMODS): Add iscsi modules * scripts/upd-instroot: Add iscsi tools
Diffstat (limited to 'iscsi.py')
-rw-r--r--iscsi.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/iscsi.py b/iscsi.py
new file mode 100644
index 000000000..f9f396d26
--- /dev/null
+++ b/iscsi.py
@@ -0,0 +1,124 @@
+#
+# iscsi.py - iscsi class
+#
+# Copyright 2005, 2006 IBM, Inc.
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General 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 string
+import signal
+import iutil
+from flags import flags
+import logging
+log = logging.getLogger("anaconda")
+
+
+# Note that stage2 copies all files under /sbin to /usr/sbin
+ISCSID="iscsid"
+ISCSIADM = "iscsiadm"
+ISCSID_DB_DIR="/var/db/iscsi"
+INITIATOR_FILE="/etc/initiatorname.iscsi"
+
+class iscsi:
+ def __init__(self):
+ if flags.iscsi:
+ self.ipaddr = ""
+ self.port = "3260"
+ self.initiator = ""
+ self.iscsidStarted = False
+
+
+
+ def action(self, action):
+ #
+ # run action for all iSCSI targets.
+ #
+ # For each record (line of output) in:
+ # iscsiadm -m node
+ #
+ # Where each line in the output is of the form:
+ # [recnum] stuff
+ #
+ # Issue the "action" request to recnum.
+ #
+ argv = [ ISCSIADM, "-m", "node" ]
+ records = iutil.execWithCapture(argv[0], argv, searchPath = 1)
+ for line in records.split("\n"):
+ if line:
+ recnum = line.split()[0][1:-1]
+ argv = [ ISCSIADM, "-m", "node", "-r", "%s" % (recnum,),
+ "%s" % (action,) ]
+ iutil.execWithRedirect(argv[0], argv, searchPath = 1,
+ stdout = "/dev/tty5",
+ stderr = "/dev/tty5")
+
+
+ def shutdown(self):
+ if not self.iscsidStarted:
+ return
+
+ log.info("iSCSI shutdown")
+ self.action("--logout")
+
+ # XXX use iscsiadm shutdown when it's available.
+ argv = [ "ps", "--no-headers", "-C", "%s" % (ISCSID,) ]
+ psout = iutil.execWithCapture(argv[0], argv, searchPath = 1)
+ for line in psout.split("\n"):
+ if line:
+ pid = string.atoi(string.split(line)[0])
+ log.info("Killing %s %d" % (ISCSID, pid))
+ os.kill(pid, signal.SIGKILL)
+ self.iscsidStarted = False;
+
+
+ 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=%s\n" %(self.initiator))
+ os.close(fd)
+
+ if not os.path.exists(ISCSID_DB_DIR):
+ iutil.mkdirChain(ISCSID_DB_DIR)
+
+ argv = [ ISCSID ]
+ iutil.execWithRedirect(argv[0], argv, searchPath = 1)
+
+ argv = [ ISCSIADM, "-m", "discovery", "-t", "st", "-p",
+ "%s:%s" % (self.ipaddr, self.port) ]
+ iutil.execWithRedirect(argv[0], argv, searchPath = 1,
+ stdout = "/dev/tty5", stderr="/dev/tty5")
+
+ self.action("--login")
+ self.iscsidStarted = True;
+
+ def writeKS(self):
+ # XXX Useful if we have auto-generated kickstart files.
+ return
+
+ def write(self):
+ # XXX copy config files and any files needed by mkinitrd, depends on
+ # mkinitrd and open-iscsi work in progress.
+ return
+
+# vim:tw=78:ts=4:et:sw=4