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

[master] iscsi: refactor the kickstart processing to use the new iscsi methods.



This gets us rid of iscsi.addTarget() completely.

Currently the kickstart iscsi support is limited to:
1) use the same credentials sets for both the discovery and the login,
i.e. user can't specify different sets
2) log into every discovered node (i.e. user can't specify only a
subset of discovered targets to log into)

Note that this change makes it easier to implement an enhancement removing
both these limitations.
---
 pyanaconda/kickstart.py     |   27 ++++++++++++++++---
 pyanaconda/storage/iscsi.py |   62 +------------------------------------------
 2 files changed, 24 insertions(+), 65 deletions(-)

diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
index bc1d8b6..b60086d 100644
--- a/pyanaconda/kickstart.py
+++ b/pyanaconda/kickstart.py
@@ -383,16 +383,35 @@ class IgnoreDisk(commands.ignoredisk.RHEL6_IgnoreDisk):
             anaconda.ksdata.skipSteps.extend(["filter", "filtertype"])
 
 class Iscsi(commands.iscsi.F10_Iscsi):
+    class Login(object):
+        def __init__(self, iscsi_obj, tg_data):
+            self.iscsi_obj = iscsi_obj
+            self.tg_data = tg_data
+        
+        def login(self, node):
+            (rc, _) = self.iscsi_obj.log_into_node(
+                node, self.tg_data.user, self.tg_data.password,
+                self.tg_data.user_in, self.tg_data.password_in)
+            return rc
+
     def parse(self, args):
         tg = commands.iscsi.F10_Iscsi.parse(self, args)
 
         try:
-            storage.iscsi.iscsi().addTarget(tg.ipaddr, tg.port,
-                tg.user, tg.password, tg.user_in, tg.password_in)
-            log.info("added iscsi target: %s" %(tg.ipaddr,))
-        except (IOError, ValueError), e:
+            iscsi_obj = storage.iscsi.iscsi()
+            discovered_nodes = iscsi_obj.discover(
+                tg.ipaddr, tg.port, tg.user, tg.password, 
+                tg.user_in, tg.password_in)
+            login = self.Login(iscsi_obj, tg)
+            logged_into_nodes = filter(login.login, discovered_nodes)
+            if len(logged_into_nodes) < 1:
+                msg = _("Could not log into any iSCSI nodes at the portal.")
+                raise KickstartValueError, formatErrorMsg(self.lineno,
+                                                          msg=msg)
+        except (IOError, ValueError) as e:
             raise KickstartValueError, formatErrorMsg(self.lineno,
                                                       msg=str(e))
+
         return tg
 
 class IscsiName(commands.iscsiname.FC6_IscsiName):
diff --git a/pyanaconda/storage/iscsi.py b/pyanaconda/storage/iscsi.py
index c9c21cc..a29fc36 100644
--- a/pyanaconda/storage/iscsi.py
+++ b/pyanaconda/storage/iscsi.py
@@ -79,7 +79,7 @@ class iscsi(object):
         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.
+        through the discover() and log_into_node() methods.
 
         As this class needs to make sure certain things like starting iscsid
         and logging in to firmware discovered disks only happens once 
@@ -265,66 +265,6 @@ class iscsi(object):
 
         return (rc, msg)
 
-    def addTarget(self, ipaddr, port="3260", user=None, pw=None,
-                  user_in=None, pw_in=None, intf=None):
-        authinfo = None
-        found = 0
-        logged_in = 0
-
-        if not has_iscsi():
-            raise IOError, _("iSCSI not available")
-        if self._initiator == "":
-            raise ValueError, _("No initiator name set")
-
-        if user or pw or user_in or pw_in:
-            # Note may raise a ValueError
-            authinfo = libiscsi.chapAuthInfo(username=user, password=pw,
-                                             reverse_username=user_in,
-                                             reverse_password=pw_in)
-        self.startup(intf)
-
-        # Note may raise an IOError
-        found_nodes = libiscsi.discover_sendtargets(address=ipaddr,
-                                                    port=int(port),
-                                                    authinfo=authinfo)
-        if found_nodes == None:
-            raise IOError, _("No iSCSI nodes discovered")
-
-        if intf:
-            w = intf.waitWindow(_("Logging in to iSCSI nodes"),
-                                _("Logging in to iSCSI nodes"))
-
-        for node in found_nodes:
-            # skip nodes we already have
-            if node in self.nodes:
-                continue
-
-            found = found + 1
-            try:
-                if (authinfo):
-                    node.setAuth(authinfo)
-                node.login()
-                log.info("iscsi.addTarget logged in to %s %s %s" % (node.name, node.address, node.port))
-                self.nodes.append(node)
-                logged_in = logged_in + 1
-            except IOError, e:
-                log.warning(
-                    "Could not log into discovered iscsi target %s: %s" %
-                    (node.name, str(e)))
-                # some nodes may require different credentials
-                pass
-
-        if intf:
-            w.pop()
-
-        if found == 0:
-            raise IOError, _("No new iSCSI nodes discovered")
-
-        if logged_in == 0:
-            raise IOError, _("Could not log in to any of the discovered nodes")
-
-        self.stabilize(intf)
-
     def writeKS(self, f):
         if not self.initiatorSet:
             return
-- 
1.7.1.1


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