[PATCH] Add a dracutSetupString method to network.py

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

 



Add a dracutSetupString method to network.py, this can be used to
ask the Network class to get a dracut setup string to setup the interface
needed for a connection to a certain host.

This patch also adds code to booty to use this to get kernel cmdline dracut
setup commands for any NIC's needed to connect to devices needed for /
---
 booty/__init__.py       |   16 ++++++++--------
 booty/alpha.py          |    4 ++--
 booty/bootloaderInfo.py |   15 ++++++++++-----
 booty/ia64.py           |    4 ++--
 booty/ppc.py            |    4 ++--
 booty/s390.py           |    4 ++--
 booty/sparc.py          |    4 ++--
 booty/x86.py            |    6 +++---
 instdata.py             |    2 +-
 network.py              |   34 ++++++++++++++++++++++++++++++++++
 10 files changed, 66 insertions(+), 27 deletions(-)

diff --git a/booty/__init__.py b/booty/__init__.py
index 9ee6398..8f2d6a7 100644
--- a/booty/__init__.py
+++ b/booty/__init__.py
@@ -28,25 +28,25 @@ class BootyNoKernelWarning:
         return self.value
 
 # return instance of the appropriate bootloader for our arch
-def getBootloader(storage):
+def getBootloader(storage, network):
     """Get the bootloader info object for your architecture"""
     if iutil.isX86():
         import x86
-        return x86.x86BootloaderInfo(storage)
+        return x86.x86BootloaderInfo(storage, network)
     elif iutil.isIA64():
         import ia64
-        return ia64.ia64BootloaderInfo(storage)
+        return ia64.ia64BootloaderInfo(storage, network)
     elif iutil.isS390():
         import s390
-        return s390.s390BootloaderInfo(storage)
+        return s390.s390BootloaderInfo(storage, network)
     elif iutil.isAlpha():
         import alpha
-        return alpha.alphaBootloaderInfo(storage)
+        return alpha.alphaBootloaderInfo(storage, network)
     elif iutil.isPPC():
         import ppc
-        return ppc.ppcBootloaderInfo(storage)
+        return ppc.ppcBootloaderInfo(storage, network)
     elif iutil.isSparc():
         import sparc
-        return sparc.sparcBootloaderInfo(storage)
+        return sparc.sparcBootloaderInfo(storage, network)
     else:
-        return bootloaderInfo(storage)
+        return bootloaderInfo(storage, network)
diff --git a/booty/alpha.py b/booty/alpha.py
index 33cef82..9f7c7cf 100644
--- a/booty/alpha.py
+++ b/booty/alpha.py
@@ -142,8 +142,8 @@ class alphaBootloaderInfo(bootloaderInfo):
         return self.writeAboot(instRoot, bl, kernelList,
                                chainList, defaultDev, justConfig)
 
-    def __init__(self, storage):
-        bootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        bootloaderInfo.__init__(self, storage, network)
         self.useGrubVal = 0
         self.configfile = "/etc/aboot.conf"
         # self.kernelLocation is already set to what we need.
diff --git a/booty/bootloaderInfo.py b/booty/bootloaderInfo.py
index 3c1ed06..7f226c3 100644
--- a/booty/bootloaderInfo.py
+++ b/booty/bootloaderInfo.py
@@ -94,6 +94,10 @@ class KernelArguments:
                 dracutSetupString = d.dracutSetupString()
                 if len(dracutSetupString):
                     args += " %s" % dracutSetupString
+                import storage
+                if isinstance(d, storage.devices.NetworkStorageDevice):
+                    args += " "
+                    args += self.network.dracutSetupString(d.host_address)
 
         return args
 
@@ -115,7 +119,7 @@ class KernelArguments:
         self.args = self.args + "%s" % (args,)
         
 
-    def __init__(self, storage):
+    def __init__(self, storage, network):
         newArgs = []
         cfgFilename = "/tmp/install.cfg"
 
@@ -153,6 +157,7 @@ class KernelArguments:
 
         self.args = " ".join(newArgs)
         self.storage = storage
+        self.network = network
 
 
 class BootImages:
@@ -476,8 +481,8 @@ class bootloaderInfo:
         self._drivelist = val
     drivelist = property(_getDriveList, _setDriveList)
 
-    def __init__(self, storage):
-        self.args = KernelArguments(storage)
+    def __init__(self, storage, network):
+        self.args = KernelArguments(storage, network)
         self.images = BootImages()
         self.device = None
         self.defaultDevice = None  # XXX hack, used by kickstart
@@ -614,9 +619,9 @@ class efiBootloaderInfo(bootloaderInfo):
             return rc
         return self.addNewEfiEntry(instRoot)
 
-    def __init__(self, storage, initialize = True):
+    def __init__(self, storage, network, initialize = True):
         if initialize:
-            bootloaderInfo.__init__(self, storage)
+            bootloaderInfo.__init__(self, storage, network)
         else:
             self.storage = storage
 
diff --git a/booty/ia64.py b/booty/ia64.py
index 6c9cdc2..c5bd42e 100644
--- a/booty/ia64.py
+++ b/booty/ia64.py
@@ -36,7 +36,7 @@ class ia64BootloaderInfo(efiBootloaderInfo):
     def makeInitrd(self, kernelTag):
         return "/boot/efi/EFI/redhat/initrd%s.img" % kernelTag
 
-    def __init__(self, storage):
-        efiBootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        efiBootloaderInfo.__init__(self, storage, network)
         self._configname = "elilo.conf"
         self._bootloader = "elilo.efi"
diff --git a/booty/ppc.py b/booty/ppc.py
index e5320c3..2143c14 100644
--- a/booty/ppc.py
+++ b/booty/ppc.py
@@ -174,8 +174,8 @@ class ppcBootloaderInfo(bootloaderInfo):
 
         return 0
 
-    def __init__(self, storage):
-        bootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        bootloaderInfo.__init__(self, storage, network)
         self.useYabootVal = 1
         self.kernelLocation = "/boot"
         self.configfile = "/etc/yaboot.conf"
diff --git a/booty/s390.py b/booty/s390.py
index 9b62600..8e46fab 100644
--- a/booty/s390.py
+++ b/booty/s390.py
@@ -171,8 +171,8 @@ class s390BootloaderInfo(bootloaderInfo):
 
         return self.writeChandevConf(bl, instRoot)
 
-    def __init__(self, storage):
-        bootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        bootloaderInfo.__init__(self, storage, network)
         self.useZiplVal = 1      # only used on s390
         self.kernelLocation = "/boot/"
         self.configfile = "/etc/zipl.conf"
diff --git a/booty/sparc.py b/booty/sparc.py
index b12b207..9154ac3 100644
--- a/booty/sparc.py
+++ b/booty/sparc.py
@@ -121,8 +121,8 @@ class sparcBootloaderInfo(bootloaderInfo):
         else:
             raise BootyNoKernelWarning
 
-    def __init__(self, storage):
-        bootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        bootloaderInfo.__init__(self, storage, network)
         self.useSiloVal = 1
         self.kernelLocation = "/boot"
         self._configdir = "/etc"
diff --git a/booty/x86.py b/booty/x86.py
index f90cb86..97354fc 100644
--- a/booty/x86.py
+++ b/booty/x86.py
@@ -578,15 +578,15 @@ class x86BootloaderInfo(efiBootloaderInfo):
 
         return args
 
-    def __init__(self, storage):
-        bootloaderInfo.__init__(self, storage)
+    def __init__(self, storage, network):
+        bootloaderInfo.__init__(self, storage, network)
 
         # these have to be set /before/ efiBootloaderInfo.__init__(), or
         # they'll be overwritten.
         self._configdir = "/boot/grub"
         self._configname = "grub.conf"
 
-        efiBootloaderInfo.__init__(self, storage, initialize=False)
+        efiBootloaderInfo.__init__(self, storage, network, initialize=False)
 
         # XXX use checkbootloader to determine what to default to
         self.useGrubVal = 1
diff --git a/instdata.py b/instdata.py
index 6700528..b3497b3 100644
--- a/instdata.py
+++ b/instdata.py
@@ -74,7 +74,7 @@ class InstallData:
         if flags.cmdline.has_key("preupgrade"):
             self.upgrade = True
         self.storage = storage.Storage(self.anaconda)
-        self.bootloader = booty.getBootloader(self.storage)
+        self.bootloader = booty.getBootloader(self.storage, self.network)
         self.upgradeRoot = None
         self.rootParts = None
         self.upgradeSwapInfo = None
diff --git a/network.py b/network.py
index 9a8d7d2..1d069fd 100644
--- a/network.py
+++ b/network.py
@@ -779,3 +779,37 @@ class Network:
             return True
 
         return False
+
+    # get a kernel cmdline string for dracut needed for access to host host
+    def dracutSetupString(self, host):
+        if not host:
+            return ""
+
+        # First of all find out which interface leads to host
+        route = iutil.execWithCapture("ip", [ "route", "get", "to", host ])
+        if not route:
+            log.error("Could net get interface for route to %s" % host)
+            return ""
+
+        routeInfo = route.split()
+        if routeInfo[0] != host or len(routeInfo) < 5:
+            log.error('Unexpected "ip route get to %s" reply: %s' % 
+                      (host, routeInfo))
+            return ""
+
+        if routeInfo[2] not in self.netdevices.keys():
+            log.error('Unknown network interface: %s' % routeInfo[2])
+            return ""
+
+        dev = self.netdevices[routeInfo[2]]
+        if dev.get('bootproto').lower() == 'dhcp':
+            return "ip=%s:dhcp" % routeInfo[2]
+
+        if self.hostname:
+            hostname = self.hostname
+        else:
+            hostname = ""
+
+        ip = "ip=%s::%s:%s:%s:none" % (dev.get('ipaddr'),
+             dev.get('GATEWAY', ''), dev.get('netmask'), hostname,
+             routeInfo[2])
-- 
1.6.2.2

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux