[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
[Fedora-livecd-list] [PATCH] livecd-creator : implement kickstart "network" command
- From: Mark McLoughlin <markmc redhat com>
- To: fedora-livecd-list <fedora-livecd-list redhat com>
- Subject: [Fedora-livecd-list] [PATCH] livecd-creator : implement kickstart "network" command
- Date: Wed, 11 Apr 2007 14:41:10 +0100
Hey,
Here's a patch which takes a stab at implementing kickstart's network
command in livecd-creator.
Cheers,
Mark.
Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -20,6 +20,7 @@ import os
import os.path
import sys
import errno
+import string
import tempfile
import time
import traceback
@@ -460,6 +461,130 @@ class InstallationTarget:
finally:
self.ayum.closeRpmDB()
+ def writeNetworkIfCfg(self, instroot, network):
+ path = instroot + "/etc/sysconfig/network-scripts/ifcfg-" + network.device
+
+ f = file(path, "w+")
+ os.chmod(path, 0644)
+
+ f.write("DEVICE=%s\n" % network.device)
+ f.write("BOOTPROTO=%s\n" % network.bootProto)
+
+ if network.bootProto.lower() == "static":
+ if network.ip:
+ f.write("IPADDR=%s\n" % network.ip)
+ if network.netmask:
+ f.write("NETMASK=%s\n" % network.netmask)
+
+ if network.onboot:
+ f.write("ONBOOT=on\n")
+ else:
+ f.write("ONBOOT=off\n")
+
+ if network.essid:
+ f.write("ESSID=%s\n" % network.essid)
+
+ if network.ethtool:
+ if network.ethtool.find("autoneg") == -1:
+ network.ethtool = "autoneg off " + network.ethtool
+ f.write("ETHTOOL_OPTS=%s\n" % network.ethtool)
+
+ if network.bootProto.lower() == "dhcp":
+ if network.hostname:
+ f.write("DHCP_HOSTNAME=%s\n" % network.hostname)
+ if network.dhcpclass:
+ f.write("DHCP_CLASSID=%s\n" % network.dhcpclass)
+
+ if network.mtu:
+ f.write("MTU=%s\n" % network.mtu)
+
+ f.close()
+
+ def writeNetworkKey(self, instroot, network):
+ if not network.wepkey:
+ return
+
+ path = instroot + "/etc/sysconfig/network-scripts/keys-" + network.device
+ f = file(path, "w+")
+ os.chmod(path, 0600)
+ f.write("KEY=%s\n" % network.wepkey)
+ f.close()
+
+ def writeNetworkConfig(self, instroot, netwrok):
+ path = instroot + "/etc/sysconfig/network"
+ f = file(path, "w+")
+ os.chmod(path, 0644)
+
+ f.write("NETWORKING=yes\n")
+
+ if network.ipv6:
+ f.write("NETWORKING_IPV6=yes\n")
+ else:
+ f.write("NETWORKING_IPV6=no\n")
+
+ if network.hostname:
+ f.write("HOSTNAME=%s\n" % network.hostname)
+ else:
+ f.write("HOSTNAME=localhost.localdomain\n")
+
+ if network.gateway:
+ f.write("GATEWAY=%s\n" % network.gateway)
+
+ f.close()
+
+ def writeNetworkHosts(self, instroot, network):
+ localline = ""
+ if network.hostname and network.hostname != "localhost.localdomain":
+ localline += network.hostname + " "
+ l = string.split(network.hostname, ".")
+ if len(l) > 1:
+ localline += l[0] + " "
+ localline += "localhost.localdomain localhost"
+
+ path = instroot + "/etc/sysconfig/hosts"
+ f = file(path, "w+")
+ os.chmod(path, 0644)
+ f.write("127.0.0.1\t\t%s\n" % localline)
+ f.write("::1\t\tlocalhost6.localdomain6 localhost6\n")
+ f.close()
+
+ def writeNetworkResolv(self, instroot, network):
+ if network.nodns or not network.nameserver:
+ return
+
+ path = instroot + "/etc/resolv.conf"
+ f = file(path, "w+")
+ os.chmod(path, 0644)
+
+ for ns in string.split(network.nameserver, ",")[0:2]:
+ f.write("nameserver %s\n" % ns)
+
+ f.close()
+
+ def configureNetwork(self):
+ instroot = self.build_dir + "/install_root"
+
+ try:
+ os.makedirs(instroot + "/etc/sysconfig/network-scripts")
+ except OSError, (err, msg):
+ if err != errno.EEXIST:
+ raise
+
+ for network in self.ksparser.handler.network.network:
+ if not network.device:
+ raise InstallationError("No --device specified with network kickstart command")
+
+ if network.onboot and network.bootProto.lower() != "dhcp" and \
+ not (network.ip and network.netmask):
+ raise InstallationError("No IP address and/or netmask specified with static " +
+ "configuration for '%s'" % network.device)
+
+ self.writeNetworkIfCfg(instroot, network)
+ self.writeNetworkKey(instroot, network)
+ self.writeNetworkConfig(instroot, network)
+ self.writeNetworkHosts(instroot, network)
+ self.writeNetworkResolv(instroot, network)
+
def configureSystem(self):
instroot = "%s/install_root" %(self.build_dir,)
@@ -490,16 +615,6 @@ class InstallationTarget:
f.write("UTC=%s\n" %(utc,))
f.close()
- # FIXME: we should handle network bits better
- f = open("%s/etc/sysconfig/network" %(instroot,), "w+")
- f.write("NETWORKING=yes\n")
- f.write("HOSTNAME=localhost.localdomain\n")
- f.close()
- f = open("/%s/etc/hosts" %(instroot,), "w+")
- f.write("127.0.0.1\t\tlocalhost.localdomain localhost\n")
- f.write("::1\t\tlocalhost6.localdomain6 localhost6\n")
- f.close()
-
# do any authconfig bits
auth = self.ksparser.handler.authconfig.authconfig or "--useshadow --enablemd5"
if os.path.exists("%s/usr/sbin/authconfig" %(instroot,)):
@@ -694,6 +809,7 @@ label runfromram
self.installPackages(self.packages, self.epackages, self.groups)
self.configureSystem()
+ self.configureNetwork()
self.relabelSystem()
if not self.skip_prelink:
self.prelinkSystem()
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]