def swapoff(device): swapoff = "/sbin/swapoff '%s'" % device log.info1("Disable swap on '%s'.", device) if run_script(swapoff) != 0: log.error("swapoff failed.") return 1 return 0
def lolist(): used = 0 free = 0 for i in xrange(LOOP.LOOP_MAX): dev = "/dev/loop%d" % i try: mode = os.stat(dev).st_mode except: continue if mode and stat.S_ISBLK(mode): l = LOOP(dev) try: l._getInfo() except IOError: free += 1 continue except ValueError, msg: used += 1 log.info1(msg) continue used += 1 line = "%s: [%04x]:%d (%s)" % (dev, l.lo_device, l.lo_inode, l.lo_file_name) if l.lo_offset > 0: line += ", offset %d" % l.lo_offset if l.lo_sizelimit > 0: line += ", sizelimit %d" % l.lo_sizelimit if l.lo_flags & 1: line += ", readonly" log.info1(line)
def _addPkgByFilename(self, name, pkgs, description=""): for repo in self.repos: s = self.repos[repo].searchFilenames(name) if len(s) < 1: # import file list if not already imported and search again if not self.repos[repo]._matchesFile(name) and \ not self.repos[repo].isFilelistImported(): self.repos[repo].importFilelist() s = self.repos[repo].searchFilenames(name) if len(s) < 1: continue for pkg in s: if pkg["name"] in pkgs: # package is already in list return pkg = s[0] # take first package, which provides ... if description != "": log.info1("Adding package '%s' for %s.", pkg["name"], description) else: log.info1("Adding package '%s'.", pkg["name"]) pkgs.append(pkg["name"]) return if description != "": raise ValueError, "Could not find package providing '%s'" % \ (name) + "needed for %s." % (description) else: raise ValueError, "Could not find package providing '%s'" % (name)
def swapon(device): swapon = "/sbin/swapon '%s'" % device log.info1("Enable swap on '%s'.", device) if run_script(swapon) != 0: log.error("swapon failed.") return 1 return 0
def _addPkg(self, name, pkgs, description=""): for repo in self.repos: _pkgs = self.repos[repo].searchPkgs([name]) if len(_pkgs) > 0: if not name in pkgs: if description != "": log.info1("Adding package '%s' for %s.", name, description) else: log.info1("Adding package '%s'.", name) pkgs.append(name) return if description != "": raise ValueError, "Could not find package '%s'" % (name) + \ "needed for %s." % (description) else: raise ValueError, "Could not find package '%s'" % (name)
def print_info(self): if not self.has_disklabel(): return log.info1("") device = self["device"] if self.has_key("image"): device = self["image"] log.info1("Disk %s: %.1f GB, %d bytes", device, self["length"] / (1000 * 1000 * 1000), self["length"]) log.info1("%d heads, %d sectors/track, %d cylinders", self["heads"], self["sectors"], self["cylinders"]) units = self["units"] log.info1("Units = cylinders of %d * %d = %d bytes", units, self["sector_size"], units * self["sector_size"])
def print_info(self): if not self.has_disklabel(): return log.info1("") device = self["device"] if self.has_key("image"): device = self["image"] log.info1("Disk %s: %.1f GB, %d bytes", device, self["length"]/(1000*1000*1000), self["length"]) log.info1("%d heads, %d sectors/track, %d cylinders", self["heads"], self["sectors"], self["cylinders"]) units = self["units"] log.info1("Units = cylinders of %d * %d = %d bytes", units, self["sector_size"], units*self["sector_size"])
def _compsLangsupport(self, pkgs, comps, languages, group): if not comps.grouphash.has_key(group): return if not comps.grouphash[group].has_key("langonly") or \ not comps.grouphash[group]["langonly"] in languages: return # add grouplist if comps.grouphash[group].has_key("grouplist"): for _group in comps.grouphash[group]["grouplist"]["groupreqs"]: self._compsLangsupport(pkgs, comps, languages, _group) for _group in comps.grouphash[group]["grouplist"]["metapkgs"]: self._compsLangsupport(pkgs, comps, languages, _group) for name in comps.getPackageNames(group): self._addPkg(name, pkgs, "langsupport") # old style conditional optional_list = comps.getOptionalPackageNames(group) for (name, requires) in optional_list: if name in pkgs: continue for req in requires: if req in pkgs: log.info1("Adding package '%s' for langsupport.", name) pkgs.append(name) break # new style conditional conditional_list = comps.getConditionalPackageNames(group) for (name, requires) in conditional_list: if name in pkgs: continue for req in requires: if req in pkgs: log.info1("Adding package '%s' for langsupport.", name) pkgs.append(name) break
def print_partitions(self): if not self.has_disklabel(): return log.info1("") l = len("Device") for part in self["partition"]: partition = self["partition"][part] if partition["disk"].has_key("image"): device = "%s%d" % (self["image"], partition["id"]) else: device = partition["device"] if l < len(device): l = len(device) log.info1("%*s Boot Start End Blocks Id " "System", l, "Device") for part in self["partition"]: partition = self["partition"][part] blocks = partition["length"] * self["sector_size"] block_str = "%d" % (blocks / 1024) if partition["disk"].has_key("image"): device = "%s%d" % (self["image"], partition["id"]) else: device = partition["device"] if blocks % 1024 > 0: block_str += "+" else: block_str += " " if partition["boot"]: boot = "*" else: boot = " " ttype = "---" try: ttype = Partition.nativeType[partition["native_type"]] except: pass log.info1("%*s %s %10d %10d %11s %2x %s", l, device, boot, partition["unit-start"], partition["unit-end"], block_str, partition["native_type"], ttype)
def print_partitions(self): if not self.has_disklabel(): return log.info1("") l = len("Device") for part in self["partition"]: partition = self["partition"][part] if partition["disk"].has_key("image"): device = "%s%d" % (self["image"], partition["id"]) else: device = partition["device"] if l < len(device): l = len(device) log.info1( "%*s Boot Start End Blocks Id " "System", l, "Device") for part in self["partition"]: partition = self["partition"][part] blocks = partition["length"] * self["sector_size"] block_str = "%d" % (blocks / 1024) if partition["disk"].has_key("image"): device = "%s%d" % (self["image"], partition["id"]) else: device = partition["device"] if blocks % 1024 > 0: block_str += "+" else: block_str += " " if partition["boot"]: boot = "*" else: boot = " " ttype = "---" try: ttype = Partition.nativeType[partition["native_type"]] except: pass log.info1("%*s %s %10d %10d %11s %2x %s", l, device, boot, partition["unit-start"], partition["unit-end"], block_str, partition["native_type"], ttype)
log.error("Card not found in hardware database.") if not _card and ks["xconfig"].has_key("driver"): if os.path.exists(buildroot+'/usr/share/hwdata/videodrivers'): # There is no usable name in the videodrivers file, so fake it _driver = ks["xconfig"]["driver"] _card = _driver + ' (generic)' if not _card or not _driver: if ks["xconfig"].has_key("card") and \ not os.path.exists(buildroot+'/usr/share/hwdata/Cards'): log.warning("Cards database not found in '/usr/share/hwdata'.") if ks["xconfig"].has_key("driver") and \ not os.path.exists(buildroot+'/usr/share/hwdata/videodrivers'): log.warning("videodrivers database not found in " "'/usr/share/hwdata'.") log.info1("Using default X driver configuration.") else: card = _card driver = _driver options = _options if ks["xconfig"].has_key("videoram"): videoram = ks["xconfig"]["videoram"] _monitor = None _hsync = None _vsync = None _dpms = 0 if ks["xconfig"].has_key("monitor") or \ (ks.has_key("monitor") and ks["monitor"].has_key("monitor")): try: monitors = hwdata.Monitors(buildroot)
if mode and stat.S_ISBLK(mode): l = LOOP(dev) try: l._getInfo() except IOError: free += 1 continue except ValueError, msg: used += 1 log.info1(msg) continue used += 1 line = "%s: [%04x]:%d (%s)" % (dev, l.lo_device, l.lo_inode, l.lo_file_name) if l.lo_offset > 0: line += ", offset %d" % l.lo_offset if l.lo_sizelimit > 0: line += ", sizelimit %d" % l.lo_sizelimit if l.lo_flags & 1: line += ", readonly" log.info1(line) log.info1("%d/%d loop devices are in use.", used, used + free) def lofree(device): loop = LOOP(device) return loop.free() # vim:ts=4:sw=4:showmatch:expandtab
def network_config(ks, buildroot): if not os.path.exists(buildroot + "/etc/sysconfig/network-scripts"): os.mkdir(buildroot + "/etc/sysconfig/network-scripts") # generate loopback network configuration if it does not exist if not os.path.exists(buildroot+\ "/etc/sysconfig/network-scripts/ifcfg-lo"): log.info1("Adding missing /etc/sysconfig/network-scripts/ifcfg-lo.") create_file(buildroot, "/etc/sysconfig/network-scripts/ifcfg-lo", [ 'DEVICE=lo\n', 'IPADDR=127.0.0.1\n', 'NETMASK=255.0.0.0\n', 'NETWORK=127.0.0.0\n', "# If you're having problems with gated making 127.0.0.0/8 a martian,\n", "# you can change this to something else (255.255.255.255, for example)\n", 'BROADCAST=127.255.255.255\n', 'ONBOOT=yes\n', 'NAME=loopback\n' ]) _hostname = None _gateway = None if ks.has_key("network") and len(ks["network"]) > 0: # check network devices and set device for entries where no device # is specified network_devices = [] for net in ks["network"]: if net.has_key("device"): if net["device"] in network_devices: log.warning("'%s' is not unique.", net["device"]) else: network_devices.append(net["device"]) for net in ks["network"]: # get device or next free device device = None if net.has_key("device"): device = net["device"] if not device: i = 0 device = "eth%d" % i while device in network_devices: i += 1 device = "eth%d" % i net["device"] = device for net in ks["network"]: if not _hostname and net.has_key("hostname"): _hostname = 'HOSTNAME=%s\n' % net["hostname"] if not _gateway and net.has_key("gateway"): _gateway = 'GATEWAY=%s\n' % net["gateway"] device = net["device"] if device[:3] == "ctc": type = "CTC" elif device[:4] == "iucv": type = "IUCV" elif device[:2] == "tr": type = '"Token Ring"' else: type = "Ethernet" bootproto = "none" if net["bootproto"] and net["bootproto"] != "static": bootproto = net["bootproto"] try: fd = open(buildroot + \ "/etc/sysconfig/network-scripts/ifcfg-%s" % \ device, "w") except Exception, msg: log.error( "Configuration of '/etc/sysconfig/network-scripts/" "ifcfg-%s' failed: %s", device, msg) else: fd.write('DEVICE=%s\n' % device) fd.write('BOOTPROTO=%s\n' % bootproto) if net.has_key("gateway"): fd.write('GATEWAY=%s\n' % net["gateway"]) if net.has_key("netmask"): fd.write('NETMASK=%s\n' % net["netmask"]) if net.has_key("ip"): fd.write('IPADDR=%s\n' % net["ip"]) if net.has_key("essid"): fd.write('ESSID=%s\n' % net["essid"]) if net.has_key("ethtool"): fd.write('ETHTOOL_OPTS=%s\n' % net["ethtool"]) if net.has_key("class"): fd.write('DHCP_CLASSID=%s\n' % net["class"]) if net.has_key("onboot"): fd.write('ONBOOT=%s\n' % net["onboot"]) else: fd.write('ONBOOT=yes\n') fd.write('TYPE=%s\n' % type) fd.close() if net.has_key("wepkey"): try: fd = open(buildroot + \ "/etc/sysconfig/network-scripts/keys-%s" % \ device, "w") except Exception, msg: log.error( "Configuration of '/etc/sysconfig/network-" "scripts/keys-%s' failed: %s", device, msg) else: fd.write('KEY=%s\n' % net["wepkey"]) fd.close()
except: continue if mode and stat.S_ISBLK(mode): l = LOOP(dev) try: l._getInfo() except IOError: free += 1 continue except ValueError, msg: used += 1 log.info1(msg) continue used += 1 line = "%s: [%04x]:%d (%s)" % (dev, l.lo_device, l.lo_inode, l.lo_file_name) if l.lo_offset > 0: line += ", offset %d" % l.lo_offset if l.lo_sizelimit > 0: line += ", sizelimit %d" % l.lo_sizelimit if l.lo_flags & 1: line += ", readonly" log.info1(line) log.info1("%d/%d loop devices are in use.", used, used+free) def lofree(device): loop = LOOP(device) return loop.free() # vim:ts=4:sw=4:showmatch:expandtab
def load(self, ks, dir, beta_key_verify=False): self.dir = dir self.exclude = None # mount source to dir if ks.has_key("cdrom"): self.url = mount_cdrom(dir) if ks["cdrom"].has_key("exclude"): self.exclude = ks["cdrom"]["exclude"] elif ks.has_key("nfs"): opts = None if ks["nfs"].has_key("opts"): opts = ks["nfs"]["opts"] self.url = mount_nfs("nfs://%s:%s" % \ (ks["nfs"]["server"], ks["nfs"]["dir"]), dir, options=opts) if ks["nfs"].has_key("exclude"): self.exclude = ks["nfs"]["exclude"] else: self.url = ks["url"]["url"] if ks["url"].has_key("exclude"): self.exclude = ks["url"]["exclude"] # create network cache self.cache = NetworkCache([ self.url ], cachedir=rpmconfig.cachedir) # get source information via .discinfo file if not self.cache.cache(".discinfo"): log.error("No .discinfo for '%s'", self.url) return 0 di = get_discinfo(self.cache.cache(".discinfo")) if not di: log.error("Getting .discinfo for '%s' failed.", self.url) return 0 (self.name, self.version, self.arch) = di if self.name.startswith("Red Hat Enterprise Linux"): self.variant = self.name[24:].strip() self.id = "RHEL" self.prefix = "RedHat" elif self.name.startswith("Fedora"): self.variant = "" self.id = "FC" self.prefix = "Fedora" else: log.error("Unknown source '%s'.", self.name) return 0 self.release = "%s-%s" % (self.id, self.version) log.info1("Installation source: %s %s [%s]", self.name, self.version, self.arch) # load repos repos = [ ] self.yumconf = YumConf(self.version, self.arch, rpmdb=None, filenames=[ ], reposdirs=[ ]) if self.isRHEL() and self.cmpVersion("4.9") >= 0: # RHEL-5 key = None skip = False if ks.has_key("key"): key = ks["key"].keys()[0] if ks["key"][key].has_key("skip"): skip = True key = None inum = None if key and not skip and not beta_key_verify: if not instnum: log.warning("Unable to verify installation key, " "module instkey is missing.. using default" "installation.") else: try: inum = instnum.InstNum(key) except: log.error("Installation key '%s' is not valid.", key) return 0 if inum: if inum.get_product_string().lower() != \ self.variant.lower(): log.error("Installation key for '%s' does not match " "'%s' media.", inum.get_product_string().lower(), self.variant.lower()) return 0 for name, path in inum.get_repos_dict().items(): if path == "VT" and \ not self.arch in [ "i386", "x86_64", "ia64" ]: continue repos.append(path) else: # BETA if self.variant == "Server": repos.append("Server") if key and key.find("C") >= 0: repos.append("Cluster") if key and key.find("S") >= 0: repos.append("ClusterStorage") elif self.variant == "Client": repos.append("Client") if key and key.find("W") >= 0: repos.append("Workstation") if self.arch in [ "i386", "x86_64", "ia64" ]: if key and key.find("V") >= 0: repos.append("VT") for repo in repos: repo_name = "%s-%s" % (self.release, repo) if repo in self.repos: log.error("Repository '%s' already defined.", repo_name) return 0 log.info1("Loading repo '%s'", repo_name) # create yumconf self.yumconf[repo_name] = { } self.yumconf[repo_name]["baseurl"] = [ "%s/%s" % (self.url, repo) ] if self.exclude: self.yumconf[repo_name]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo_name) self.repos[repo_name] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo_name) return 0 else: # RHEL <= 4 # FC repo = self.release self.yumconf[repo] = { } self.yumconf[repo]["baseurl"] = [ self.url ] if self.exclude: self.yumconf[repo]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 if not _repo.comps: # every source repo has to have a comps log.error("Missing comps file for '%s'.", repo) return 0 self.base_repo_names = self.repos.keys() if not ks.has_key("repo"): return 1 for repo in ks["repo"]: if repo in self.repos: log.error("Repository '%s' already defined.", repo) return 0 log.info1("Loading repository '%s'", repo) self.yumconf[repo] = { } url = ks["repo"][repo]["baseurl"] if url[:6] == "nfs://": d = "%s/%s" % (dir, repo) create_dir("", d) url = mount_nfs(url, d) self.yumconf[repo]["baseurl"] = [ url ] if ks["repo"][repo].has_key("exclude"): self.yumconf[repo]["exclude"] = ks["repo"][repo]["exclude"] if ks["repo"][repo].has_key("mirrorlist"): self.yumconf[repo]["mirrorlist"] = \ ks["repo"][repo]["mirrorlist"] _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 return 1
def getPackages(self, ks, languages, all_comps, has_raid, fstypes): groups = [ ] pkgs = [ ] everything = False if ks.has_key("packages") and \ ks["packages"].has_key("groups") and \ len(ks["packages"]["groups"]) > 0: groups = ks["packages"]["groups"] # add default group "base" and "core if it is not in groups and # nobase is not set if not ks.has_key("packages") or not ks["packages"].has_key("nobase"): if not "base" in groups: groups.append("base") if not "core" in groups: groups.append("core") if all_comps: repos = self.repos.keys() else: repos = self.base_repo_names if "everything" in groups: for repo in repos: for group in self.repos[repo].comps.getGroups(): if not group in groups: groups.append(group) groups.remove("everything") everything = True if ks.has_key("packages") and ks["packages"].has_key("add") and \ "*" in ks["packages"]["add"]: # add all packages for repo in self.repos.keys(): pkgs.extend(self.repos[repo].getNames()) else: # add default desktop if ks.has_key("xconfig"): if ks["xconfig"].has_key("startxonboot"): if not "base-x" in groups: log.info1("Adding group 'base-x'.") groups.append("base-x") desktop = "GNOME" if ks["xconfig"].has_key("defaultdesktop"): desktop = ks["xconfig"]["defaultdesktop"] desktop = "%s-desktop" % desktop.lower() if not desktop in groups: log.info1("Adding group '%s'.", desktop) groups.append(desktop) normalizeList(groups) # test if groups are available repo_groups = { } for group in groups: found = False for repo in repos: if not self.repos[repo].comps: continue _group = self.repos[repo].comps.getGroup(group) if not _group: continue found = True if not _group in repo_groups.keys() or \ not repo in repo_groups[_group]: repo_groups.setdefault(_group, [ ]).append(repo) if not found: log.warning("Group '%s' does not exist.", group) del groups # add packages for groups for group in repo_groups: for repo in repo_groups[group]: comps = self.repos[repo].comps for pkg in comps.getPackageNames(group): if len(self.repos[repo].searchPkgs([pkg])) > 0: if not pkg in pkgs: pkgs.append(pkg) if everything: # add all packages in this group for (pkg, req) in \ comps.getConditionalPackageNames(group): if len(self.repos[repo].searchPkgs([pkg])) > 0: if not pkg in pkgs: pkgs.append(pkg) del repo_groups # add packages if ks.has_key("packages") and ks["packages"].has_key("add"): for name in ks["packages"]["add"]: if name == "*": continue found = False for repo in self.repos.keys(): _pkgs = self.repos[repo].searchPkgs([name]) if len(_pkgs) > 0: # silently add package if not name in pkgs: pkgs.append(name) found = True break if not found: log.warning("Package '%s' is not available.", pkg) # remove packages if ks.has_key("packages") and ks["packages"].has_key("drop"): for pkg in ks["packages"]["drop"]: if pkg in pkgs: log.info1("Removing package '%s'.", pkg) pkgs.remove(pkg) # add xorg driver package for past FC-5, RHEL-4 if ks.has_key("xconfig"): if (self.isRHEL() and self.cmpVersion("4.9") > 0) or \ (self.isFedora() and self.cmpVersion("4") > 0): if ks["xconfig"].has_key("driver"): self._addPkg("xorg-x11-drv-%s" % ks["xconfig"]["driver"], pkgs) else: if not "xorg-x11-drivers" in pkgs: self._addPkg("xorg-x11-drivers", pkgs) # add packages for needed filesystem types for fstype in fstypes: if fstype == "swap": continue self._addPkgByFilename("/sbin/mkfs.%s" % fstype, pkgs, "%s filesystem creation" % fstype) # add comps package if not "comps" in pkgs: try: self._addPkg("comps", pkgs) except: # ignore missing comps package pass # append mdadm if has_raid: self._addPkgByFilename("/sbin/mdadm", pkgs, "raid configuration") # append authconfig if ks.has_key("authconfig"): self._addPkgByFilename("/usr/sbin/authconfig", pkgs, "authentication configuration") # append iptables and config tool if ks.has_key("firewall") and \ not ks["firewall"].has_key("disabled"): self._addPkg("iptables", pkgs) # no firewall config tool in RHEL-3 if (self.isRHEL() and self.cmpVersion("4") >= 0) or \ (self.isFedora() and self.cmpVersion("3") >= 0): self._addPkgByFilename("/usr/sbin/lokkit", pkgs, "firewall configuration") # append lokkit if ks.has_key("selinux") and \ ((self.isRHEL() and self.cmpVersion("4") >= 0) or \ (self.isFedora() and self.cmpVersion("3") >= 0)): self._addPkgByFilename("/usr/sbin/lokkit", pkgs, "selinux configuration") # append kernel if not "kernel" in pkgs and not "kernel-smp" in pkgs: self._addPkg("kernel", pkgs) # append kernel-devel for FC-6 and RHEL-5 if "gcc" in pkgs and \ ((self.isRHEL() and self.cmpVersion("5") >= 0 and \ (self.getVariant() != "Client" or \ "%s-Workstation" % (self.release) in self.repos.keys())) or \ (self.isFedora() and self.cmpVersion("6") >= 0)): if "kernel" in pkgs: self._addPkg("kernel-devel", pkgs) elif "kernel-smp" in pkgs: self._addPkg("kernel-smp-devel", pkgs) # append firstboot if ks.has_key("firstboot") and \ not ks["firstboot"].has_key("disabled"): self._addPkg("firstboot", pkgs) # append dhclient if ks.has_key("bootloader"): self._addPkg("grub", pkgs) # if self.getArch() == "ia64": # self._addPkg("elilo", pkgs) # elif self.getArch in [ "s390", "s390x" ]: # self._addPkg("s390utils", pkgs) # elif self.getArch() in [ "ppc", "ppc64" ]: # self._addPkg("yaboot", pkgs) # else: # self._addPkg("grub", pkgs) # append grub if ks.has_key("network") and len(ks["network"]) > 0: for net in ks["network"]: if net["bootproto"] == "dhcp": self._addPkg("dhclient", pkgs) # languages (pre FC-6 and pre RHEL-5) if len(languages) > 0: for repo in repos: _repo = self.repos[repo] if not _repo.comps: continue for group in _repo.comps.grouphash.keys(): self._compsLangsupport(pkgs, _repo.comps, languages, group) normalizeList(pkgs) return pkgs
def parse(self, no_include=0): _fd = open(self["filename"], "r") swap_id = 0 in_packages = 0 in_post = -1 in_pre = 0 fd = [_fd] open_files = [self["filename"]] while 1: line = fd[0].readline() if not line: if len(fd) > 0: _fd = fd.pop(0) _fd.close() if len(fd) == 0: break line = line.rstrip() if len(line) < 1: continue if line[0] == '#': continue args = KickstartConfig.noquote_split(line) opt = args[0] if opt == "%packages": self.parseSimple( opt[1:], args[1:], ["resolvedeps", "ignoredeps", "ignoremissing", "nobase"]) in_packages = 1 in_post = -1 in_pre = 0 continue elif opt == "%post": # as much post scripts as you want to dict = self.parseMultiple( opt[1:], args[1:], ["nochroot", "interpreter=", "erroronfail"]) in_packages = 0 in_post = len(self["post"]) - 1 in_pre = 0 continue elif opt == "%pre": # maximum one pre script self.parseSimple(opt[1:], args[1:], ["erroronfail", "interpreter="]) in_packages = 0 in_post = -1 in_pre = 1 continue elif opt == "%include": if no_include: continue if len(args) == 2: try: _fd = open(args[1], "r") except Exception: log.info1("Unable to open '%s', ignoring.", args[1]) else: if args[1] in open_files: raise ValueError, \ "Include loop detected for '%s'" % args[1] fd.insert(0, _fd) open_files.append(args[1]) else: raise ValueError, "Error in line '%s'" % line continue if not in_packages and in_post < 0 and not in_pre: if len(args) == 1: if opt in [ "autopart", "autostep", "cmdline", "graphical", "halt", "install", "interactive", "poweroff", "shutdown", "skipx", "text", "upgrade", "mouse", "zerombr" ]: self[opt] = None else: log.info1("'%s' is unsupported.", line) continue if opt in ["keyboard", "lang", "zerombr"]: if len(args) > 2: raise ValueError, "Error in line '%s'" % line self[opt] = args[1] continue if opt == "auth" or opt == "authconfig": self.parseSimple("authconfig", args[1:], [ "enablemd5", "enablenis", "nisdomain=", "nisserver=", "useshadow", "enableshadow", "enableldap", "enableldapauth", "ldapserver=", "ldapbasedn=", "enableldaptls", "enablekrb5", "krb5realm=", "krb5kdc=", "disablekrb5kdcdns", "disablekrb5realmdns", "krb5adminserver=", "enablehesiod", "hesiodlhs=", "hesiodrhs=", "enablesmbauth", "smbservers=", "smbworkgroup=", "enablecache" ], {"useshadow": "enableshadow"}) elif opt == "bootloader": self.parseSimple(opt, args[1:], [ "append:", "driveorder:", "location:", "password:"******"md5pass:"******"lba32", "upgrade" ]) self.stringSplit(self["bootloader"], "driveorder") elif opt == "cdrom": self.parseSimple(opt, args[1:], ["exclude:"]) self.stringSplit(self[opt], "exclude") elif opt == "clearpart": self.parseSimple( opt, args[1:], ["all", "drives:", "initlabel", "linux", "none"]) self.stringSplit(self["bootloader"], "drives") elif opt == "device": (_dict, _args) = self.parseArgs(args[1:], ["opts:"]) if len(_args) != 2: raise ValueError, "'%s' is unsupported" % line if not self.has_key(opt): self[opt] = {} if not self[opt].has_key(_args[0]): self[opt][_args[0]] = {} self[opt][_args[0]][_args[1]] = _dict # TODO: dmraid # TODO: driverdisk elif opt == "firewall": # firewall is special, so we have to do it by hand if self.has_key(opt): raise ValueError, "%s already set." % opt (_opts, _args) = KickstartConfig.getopt(args[1:], "", [ "enabled", "enable", "disabled", "disable", "trust:", "ssh", "telnet", "smtp", "http", "ftp", "port:" ]) replace_tags = {"enable": "enabled", "disable": "disabled"} self[opt] = {} for (_opt, _val) in _opts: if replace_tags and replace_tags.has_key(_opt): _opt = replace_tags[_opt] if _opt == "--enabled" or _opt == "--enable": self[opt]["enabled"] = None elif _opt == "--disabled" or _opt == "--disable": self[opt]["disabled"] = None elif _opt == "--trust" and _val: if not self[opt].has_key("trust"): self[opt]["trusted"] = [] self[opt]["trusted"].append(_val) elif _opt in [ "--ssh", "--telnet", "--smtp", "--http", "--ftp" ]: if not self[opt].has_key("ports"): self[opt]["ports"] = [] if _opt == "--ftp": self[opt]["ports"].append([21, "tcp"]) elif _opt == "--ssh": self[opt]["ports"].append([22, "tcp"]) elif _opt == "--telnet": self[opt]["ports"].append([23, "tcp"]) elif _opt == "--smtp": self[opt]["ports"].append([25, "tcp"]) elif _opt == "--http": self[opt]["ports"].append([80, "tcp"]) elif _opt == "--port": _vals = KickstartConfig.noquote_split(_val, ",") for v in _vals: if not self[opt].has_key("ports"): self[opt]["ports"] = [] a = v.split(":") if len(a) != 2: raise ValueError, \ "port '%s' is invalid." % v self[opt]["ports"].append(a) else: log.info1("'%s': option '%s' not recognized.", line, _opt) for arg in _args: self[opt].setdefault("devices", []).append(arg) elif opt == "firstboot": self.parseSimple(opt, args[1:], [ "enable", "enabled", "disable", "disabled", "reconfig" ], { "enable": "enabled", "disable": "disabled" }) elif opt == "harddrive": self.parseSimple(opt, args[1:], ["partition:", "dir:"]) if not self[opt].has_key("partition") or \ not self[opt].has_key("dir"): raise ValueError, "Error in line '%s'" % line # TODO: ignoredisk # TODO: iscsi # TODO: iscsiname elif opt == "key": self.parseSub(opt, args[1:], ["skip"]) elif opt == "langsupport": (_dict, _args) = self.parseArgs(args[1:], ["default:"]) self[opt] = _dict if len(args) > 0: self[opt]["supported"] = _args if len(self[opt]) == 0: raise ValueError, "Error in line '%s'" % line # TODO: logging elif opt == "logvol": if args[1] == "swap": args[1] = "swap.%d" % swap_id swap_id += 1 dict = self.parseSub(opt, args[1:], [ "vgname:", "size:", "name:", "noformat", "useexisting", "fstype:", "fsoptions:", "bytes-per-inode:", "grow", "maxsize:", "recommended", "percent" ]) self.convertLong(dict, "bytes-per-inode") self.convertDouble(dict, "percent") # TODO: mediacheck elif opt == "monitor": self.parseSimple( opt, args[1:], ["noprobe", "monitor:", "hsync:", "vsync:"]) # TODO: multipath elif opt == "network": dict = self.parseMultiple(opt, args[1:], [ "bootproto:", "device:", "ip:", "gateway:", "nameserver:", "nodns", "netmask:", "hostname:", "ethtool:", "essid:", "wepkey:", "onboot:", "class:", "mtu:", "noipv4", "noipv6" ]) self.stringSplit(dict, "nameserver") elif opt == "nfs": self.parseSimple(opt, args[1:], ["server:", "dir:", "exclude:", "opts:"]) if not self[opt].has_key("server") or \ not self[opt].has_key("dir"): raise ValueError, "Error in line '%s'" % line self.stringSplit(self[opt], "exclude") elif opt == "part" or opt == "partition": if args[1] == "swap": args[1] = "swap.%d" % swap_id swap_id += 1 dict = self.parseSub("partition", args[1:], [ "size:", "grow", "maxsize:", "noformat", "onpart:", "usepart:", "ondisk:", "ondrive:", "asprimary", "fstype:", "fsoptions:", "label:", "start:", "end:", "bytes-per-inode:", "recommended", "onbiosdisk" ], { "usepart": "onpart", "ondrive": "ondisk" }) self.convertLong(dict, "size") self.convertLong(dict, "maxsize") self.convertLong(dict, "start") self.convertLong(dict, "end") self.convertLong(dict, "bytes-per-inode") elif opt == "raid": (_dict, _args) = self.parseArgs(args[1:], [ "level:", "device:", "bytes_per_inode:", "spares:", "fstype:", "fsoptions:", "noformat", "useexisting" ]) if len(_args) < 2: raise ValueError, "'%s' is unsupported" % line if not self.has_key(opt): self[opt] = {} if self[opt].has_key(_args[0]): raise ValueError, "raid '%s' is not unique.", _args[0] if _dict.has_key("level") and \ _dict["level"].lower()[:4] == "raid": _dict["level"] = _dict["level"][4:] self.convertLong(_dict, "level") self.convertLong(_dict, "spares") _dict["partitions"] = _args[1:] self[opt][_args[0]] = _dict elif opt == "reboot": self.parseSimple(opt, args[1:], ["eject"]) elif opt == "repo": (_dict, _args) = self.parseArgs( args[1:], ["name:", "baseurl:", "mirrorlist:", "exclude:"]) if not _dict.has_key("name"): raise ValueError, "repo name not specified in '%s'" % \ line if not self.has_key(opt): self[opt] = {} if self.has_key(opt) and _dict["name"] in self[opt]: raise ValueError, "repo name '%s' is not unique." % \ _dict["name"] self.stringSplit(_dict, "exclude") self[opt][_dict["name"]] = _dict del _dict["name"] elif opt == "rootpw": self.parseSub(opt, args[1:], ["iscrypted"]) elif opt == "selinux": self.parseSimple(opt, args[1:], ["enforcing", "permissive", "disabled"]) elif opt == "services": self.parseSimple(opt, args[1:], ["enabled:", "disabled:"]) self.stringSplit(self[opt], "enabled") self.stringSplit(self[opt], "disabled") elif opt == "timezone": self.parseSub(opt, args[1:], ["utc"]) elif opt == "url": self.parseSimple(opt, args[1:], ["url:", "exclude:", "mirrorlist:"]) if not self[opt].has_key("url") and \ not self[opt].has_key("mirrorlist"): raise ValueError, "Error in line '%s'" % line self.stringSplit(self[opt], "exclude") self.stringSplit(self[opt], "mirrorlist") elif opt == "user": dict = self.parseMultiple(opt, args[1:], [ "name:", "groups:", "homedir:", "password:"******"iscrypted", "shell:", "uid:", ]) self.stringSplit(dict, "groups") self.convertLong(dict, "uid") # TODO: vnc elif opt == "volgroup": (_dict, _args) = self.parseArgs( args[1:], ["noformat", "useexisting", "pesize:"]) if len(_args) < 2: raise ValueError, "'%s' is unsupported" % line _dict["partitions"] = _args[1:] if not self.has_key(opt): self[opt] = {} if self[opt].has_key(_args[0]): raise ValueError, \ "volgroup '%s' is already defined" % line self[opt][_args[0]] = _dict elif opt == "xconfig": self.parseSimple(opt, args[1:], [ "noprobe", "card:", "videoram:", "monitor:", "hsync:", "vsync:", "defaultdesktop:", "startxonboot", "resolution:", "depth:", "driver:" ], { "startX": "startxonboot", "videoRam": "videoram" }) else: log.info1("'%s' is unsupported.", line) elif in_packages: if len(args) == 1: # there was no space as delimiter args = [line[:1], line[1:]] opt = line if not self.has_key("packages"): self["packages"] = {} if opt[0] == "@": if not self["packages"].has_key("groups"): self["packages"]["groups"] = [] if not args[1] in self["packages"]["groups"]: self["packages"]["groups"].append(args[1]) elif opt[0] == "-": if not self["packages"].has_key("drop"): self["packages"]["drop"] = [] if not line in self["packages"]["drop"]: self["packages"]["drop"].append(args[1]) else: if not self["packages"].has_key("add"): self["packages"]["add"] = [] if not line in self["packages"]["add"]: self["packages"]["add"].append(opt) elif in_post >= 0: dict = self["post"][in_post] if not dict.has_key("script"): dict["script"] = "" dict["script"] += line + "\n" elif in_pre: if not self["pre"].has_key("script"): self["pre"]["script"] = "" self["pre"]["script"] += line + "\n" self.verify()
def network_config(ks, buildroot): if not os.path.exists(buildroot+"/etc/sysconfig/network-scripts"): os.mkdir(buildroot+"/etc/sysconfig/network-scripts") # generate loopback network configuration if it does not exist if not os.path.exists(buildroot+\ "/etc/sysconfig/network-scripts/ifcfg-lo"): log.info1("Adding missing /etc/sysconfig/network-scripts/ifcfg-lo.") create_file(buildroot, "/etc/sysconfig/network-scripts/ifcfg-lo", [ 'DEVICE=lo\n', 'IPADDR=127.0.0.1\n', 'NETMASK=255.0.0.0\n', 'NETWORK=127.0.0.0\n', "# If you're having problems with gated making 127.0.0.0/8 a martian,\n", "# you can change this to something else (255.255.255.255, for example)\n", 'BROADCAST=127.255.255.255\n', 'ONBOOT=yes\n', 'NAME=loopback\n' ]) _hostname = None _gateway = None if ks.has_key("network") and len(ks["network"]) > 0: # check network devices and set device for entries where no device # is specified network_devices = [ ] for net in ks["network"]: if net.has_key("device"): if net["device"] in network_devices: log.warning("'%s' is not unique.", net["device"]) else: network_devices.append(net["device"]) for net in ks["network"]: # get device or next free device device = None if net.has_key("device"): device = net["device"] if not device: i = 0 device = "eth%d" % i while device in network_devices: i += 1 device = "eth%d" % i net["device"] = device for net in ks["network"]: if not _hostname and net.has_key("hostname"): _hostname = 'HOSTNAME=%s\n' % net["hostname"] if not _gateway and net.has_key("gateway"): _gateway = 'GATEWAY=%s\n' % net["gateway"] device = net["device"] if device[:3] == "ctc": type = "CTC" elif device[:4] == "iucv": type = "IUCV" elif device[:2] == "tr": type = '"Token Ring"' else: type = "Ethernet" bootproto = "none" if net["bootproto"] and net["bootproto"] != "static": bootproto = net["bootproto"] try: fd = open(buildroot + \ "/etc/sysconfig/network-scripts/ifcfg-%s" % \ device, "w") except Exception, msg: log.error("Configuration of '/etc/sysconfig/network-scripts/" "ifcfg-%s' failed: %s", device, msg) else: fd.write('DEVICE=%s\n' % device) fd.write('BOOTPROTO=%s\n' % bootproto) if net.has_key("gateway"): fd.write('GATEWAY=%s\n' % net["gateway"]) if net.has_key("netmask"): fd.write('NETMASK=%s\n' % net["netmask"]) if net.has_key("ip"): fd.write('IPADDR=%s\n' % net["ip"]) if net.has_key("essid"): fd.write('ESSID=%s\n' % net["essid"]) if net.has_key("ethtool"): fd.write('ETHTOOL_OPTS=%s\n' % net["ethtool"]) if net.has_key("class"): fd.write('DHCP_CLASSID=%s\n' % net["class"]) if net.has_key("onboot"): fd.write('ONBOOT=%s\n' % net["onboot"]) else: fd.write('ONBOOT=yes\n') fd.write('TYPE=%s\n' % type) fd.close() if net.has_key("wepkey"): try: fd = open(buildroot + \ "/etc/sysconfig/network-scripts/keys-%s" % \ device, "w") except Exception, msg: log.error("Configuration of '/etc/sysconfig/network-" "scripts/keys-%s' failed: %s", device, msg) else: fd.write('KEY=%s\n' % net["wepkey"]) fd.close()
def getPackages(self, ks, languages, all_comps, has_raid, fstypes): groups = [] pkgs = [] everything = False if ks.has_key("packages") and \ ks["packages"].has_key("groups") and \ len(ks["packages"]["groups"]) > 0: groups = ks["packages"]["groups"] # add default group "base" and "core if it is not in groups and # nobase is not set if not ks.has_key("packages") or not ks["packages"].has_key("nobase"): if not "base" in groups: groups.append("base") if not "core" in groups: groups.append("core") if all_comps: repos = self.repos.keys() else: repos = self.base_repo_names if "everything" in groups: for repo in repos: for group in self.repos[repo].comps.getGroups(): if not group in groups: groups.append(group) groups.remove("everything") everything = True if ks.has_key("packages") and ks["packages"].has_key("add") and \ "*" in ks["packages"]["add"]: # add all packages for repo in self.repos.keys(): pkgs.extend(self.repos[repo].getNames()) else: # add default desktop if ks.has_key("xconfig"): if ks["xconfig"].has_key("startxonboot"): if not "base-x" in groups: log.info1("Adding group 'base-x'.") groups.append("base-x") desktop = "GNOME" if ks["xconfig"].has_key("defaultdesktop"): desktop = ks["xconfig"]["defaultdesktop"] desktop = "%s-desktop" % desktop.lower() if not desktop in groups: log.info1("Adding group '%s'.", desktop) groups.append(desktop) normalizeList(groups) # test if groups are available repo_groups = {} for group in groups: found = False for repo in repos: if not self.repos[repo].comps: continue _group = self.repos[repo].comps.getGroup(group) if not _group: continue found = True if not _group in repo_groups.keys() or \ not repo in repo_groups[_group]: repo_groups.setdefault(_group, []).append(repo) if not found: log.warning("Group '%s' does not exist.", group) del groups # add packages for groups for group in repo_groups: for repo in repo_groups[group]: comps = self.repos[repo].comps for pkg in comps.getPackageNames(group): if len(self.repos[repo].searchPkgs([pkg])) > 0: if not pkg in pkgs: pkgs.append(pkg) if everything: # add all packages in this group for (pkg, req) in \ comps.getConditionalPackageNames(group): if len(self.repos[repo].searchPkgs([pkg])) > 0: if not pkg in pkgs: pkgs.append(pkg) del repo_groups # add packages if ks.has_key("packages") and ks["packages"].has_key("add"): for name in ks["packages"]["add"]: if name == "*": continue found = False for repo in self.repos.keys(): _pkgs = self.repos[repo].searchPkgs([name]) if len(_pkgs) > 0: # silently add package if not name in pkgs: pkgs.append(name) found = True break if not found: log.warning("Package '%s' is not available.", pkg) # remove packages if ks.has_key("packages") and ks["packages"].has_key("drop"): for pkg in ks["packages"]["drop"]: if pkg in pkgs: log.info1("Removing package '%s'.", pkg) pkgs.remove(pkg) # add xorg driver package for past FC-5, RHEL-4 if ks.has_key("xconfig"): if (self.isRHEL() and self.cmpVersion("4.9") > 0) or \ (self.isFedora() and self.cmpVersion("4") > 0): if ks["xconfig"].has_key("driver"): self._addPkg("xorg-x11-drv-%s" % ks["xconfig"]["driver"], pkgs) else: if not "xorg-x11-drivers" in pkgs: self._addPkg("xorg-x11-drivers", pkgs) # add packages for needed filesystem types for fstype in fstypes: if fstype == "swap": continue self._addPkgByFilename("/sbin/mkfs.%s" % fstype, pkgs, "%s filesystem creation" % fstype) # add comps package if not "comps" in pkgs: try: self._addPkg("comps", pkgs) except: # ignore missing comps package pass # append mdadm if has_raid: self._addPkgByFilename("/sbin/mdadm", pkgs, "raid configuration") # append authconfig if ks.has_key("authconfig"): self._addPkgByFilename("/usr/sbin/authconfig", pkgs, "authentication configuration") # append iptables and config tool if ks.has_key("firewall") and \ not ks["firewall"].has_key("disabled"): self._addPkg("iptables", pkgs) # no firewall config tool in RHEL-3 if (self.isRHEL() and self.cmpVersion("4") >= 0) or \ (self.isFedora() and self.cmpVersion("3") >= 0): self._addPkgByFilename("/usr/sbin/lokkit", pkgs, "firewall configuration") # append lokkit if ks.has_key("selinux") and \ ((self.isRHEL() and self.cmpVersion("4") >= 0) or \ (self.isFedora() and self.cmpVersion("3") >= 0)): self._addPkgByFilename("/usr/sbin/lokkit", pkgs, "selinux configuration") # append kernel if not "kernel" in pkgs and not "kernel-smp" in pkgs: self._addPkg("kernel", pkgs) # append kernel-devel for FC-6 and RHEL-5 if "gcc" in pkgs and \ ((self.isRHEL() and self.cmpVersion("5") >= 0 and \ (self.getVariant() != "Client" or \ "%s-Workstation" % (self.release) in self.repos.keys())) or \ (self.isFedora() and self.cmpVersion("6") >= 0)): if "kernel" in pkgs: self._addPkg("kernel-devel", pkgs) elif "kernel-smp" in pkgs: self._addPkg("kernel-smp-devel", pkgs) # append firstboot if ks.has_key("firstboot") and \ not ks["firstboot"].has_key("disabled"): self._addPkg("firstboot", pkgs) # append dhclient if ks.has_key("bootloader"): self._addPkg("grub", pkgs) # if self.getArch() == "ia64": # self._addPkg("elilo", pkgs) # elif self.getArch in [ "s390", "s390x" ]: # self._addPkg("s390utils", pkgs) # elif self.getArch() in [ "ppc", "ppc64" ]: # self._addPkg("yaboot", pkgs) # else: # self._addPkg("grub", pkgs) # append grub if ks.has_key("network") and len(ks["network"]) > 0: for net in ks["network"]: if net["bootproto"] == "dhcp": self._addPkg("dhclient", pkgs) # languages (pre FC-6 and pre RHEL-5) if len(languages) > 0: for repo in repos: _repo = self.repos[repo] if not _repo.comps: continue for group in _repo.comps.grouphash.keys(): self._compsLangsupport(pkgs, _repo.comps, languages, group) normalizeList(pkgs) return pkgs
def parse(self, no_include=0): _fd = open(self["filename"], "r") swap_id = 0 in_packages = 0 in_post = -1 in_pre = 0 fd = [ _fd ] open_files = [ self["filename"] ] while 1: line = fd[0].readline() if not line: if len(fd) > 0: _fd = fd.pop(0) _fd.close() if len(fd) == 0: break line = line.rstrip() if len(line) < 1: continue if line[0] == '#': continue args = KickstartConfig.noquote_split(line) opt = args[0] if opt == "%packages": self.parseSimple(opt[1:], args[1:], [ "resolvedeps", "ignoredeps", "ignoremissing", "nobase" ]) in_packages = 1 in_post = -1 in_pre = 0 continue elif opt == "%post": # as much post scripts as you want to dict = self.parseMultiple(opt[1:], args[1:], [ "nochroot", "interpreter=", "erroronfail" ]) in_packages = 0 in_post = len(self["post"]) - 1 in_pre = 0 continue elif opt == "%pre": # maximum one pre script self.parseSimple(opt[1:], args[1:], [ "erroronfail", "interpreter=" ]) in_packages = 0 in_post = -1 in_pre = 1 continue elif opt == "%include": if no_include: continue if len(args) == 2: try: _fd = open(args[1], "r") except Exception: log.info1("Unable to open '%s', ignoring.", args[1]) else: if args[1] in open_files: raise ValueError, \ "Include loop detected for '%s'" % args[1] fd.insert(0, _fd) open_files.append(args[1]) else: raise ValueError, "Error in line '%s'" % line continue if not in_packages and in_post < 0 and not in_pre: if len(args) == 1: if opt in [ "autopart", "autostep", "cmdline", "graphical", "halt", "install", "interactive", "poweroff", "shutdown", "skipx", "text", "upgrade", "mouse", "zerombr" ]: self[opt] = None else: log.info1("'%s' is unsupported.", line) continue if opt in [ "keyboard", "lang", "zerombr" ]: if len(args) > 2: raise ValueError, "Error in line '%s'" % line self[opt] = args[1] continue if opt == "auth" or opt == "authconfig": self.parseSimple("authconfig", args[1:], [ "enablemd5", "enablenis", "nisdomain=", "nisserver=", "useshadow", "enableshadow", "enableldap", "enableldapauth", "ldapserver=", "ldapbasedn=", "enableldaptls", "enablekrb5", "krb5realm=", "krb5kdc=", "disablekrb5kdcdns", "disablekrb5realmdns", "krb5adminserver=", "enablehesiod", "hesiodlhs=", "hesiodrhs=", "enablesmbauth", "smbservers=", "smbworkgroup=", "enablecache" ], { "useshadow": "enableshadow" }) elif opt == "bootloader": self.parseSimple(opt, args[1:], [ "append:", "driveorder:", "location:", "password:"******"md5pass:"******"lba32", "upgrade" ]) self.stringSplit(self["bootloader"], "driveorder") elif opt == "cdrom": self.parseSimple(opt, args[1:], [ "exclude:" ]) self.stringSplit(self[opt], "exclude") elif opt == "clearpart": self.parseSimple(opt, args[1:], [ "all", "drives:", "initlabel", "linux", "none" ]) self.stringSplit(self["bootloader"], "drives") elif opt == "device": (_dict, _args) = self.parseArgs(args[1:], [ "opts:" ]) if len(_args) != 2: raise ValueError, "'%s' is unsupported" % line if not self.has_key(opt): self[opt] = { } if not self[opt].has_key(_args[0]): self[opt][_args[0]] = { } self[opt][_args[0]][_args[1]] = _dict # TODO: dmraid # TODO: driverdisk elif opt == "firewall": # firewall is special, so we have to do it by hand if self.has_key(opt): raise ValueError, "%s already set." % opt (_opts, _args) = KickstartConfig.getopt(args[1:], "", [ "enabled", "enable", "disabled", "disable", "trust:", "ssh", "telnet", "smtp", "http", "ftp", "port:" ]) replace_tags = { "enable": "enabled", "disable": "disabled" } self[opt] = { } for (_opt, _val) in _opts: if replace_tags and replace_tags.has_key(_opt): _opt = replace_tags[_opt] if _opt == "--enabled" or _opt == "--enable": self[opt]["enabled"] = None elif _opt == "--disabled" or _opt == "--disable": self[opt]["disabled"] = None elif _opt == "--trust" and _val: if not self[opt].has_key("trust"): self[opt]["trusted"] = [ ] self[opt]["trusted"].append(_val) elif _opt in [ "--ssh", "--telnet", "--smtp", "--http", "--ftp" ]: if not self[opt].has_key("ports"): self[opt]["ports"] = [ ] if _opt == "--ftp": self[opt]["ports"].append([21,"tcp"]) elif _opt == "--ssh": self[opt]["ports"].append([22,"tcp"]) elif _opt == "--telnet": self[opt]["ports"].append([23,"tcp"]) elif _opt == "--smtp": self[opt]["ports"].append([25,"tcp"]) elif _opt == "--http": self[opt]["ports"].append([80,"tcp"]) elif _opt == "--port": _vals = KickstartConfig.noquote_split(_val, ",") for v in _vals: if not self[opt].has_key("ports"): self[opt]["ports"] = [ ] a = v.split(":") if len(a) != 2: raise ValueError, \ "port '%s' is invalid." % v self[opt]["ports"].append(a) else: log.info1("'%s': option '%s' not recognized.", line, _opt) for arg in _args: self[opt].setdefault("devices", [ ]).append(arg) elif opt == "firstboot": self.parseSimple(opt, args[1:], [ "enable", "enabled", "disable", "disabled", "reconfig" ], { "enable": "enabled", "disable": "disabled" }) elif opt == "harddrive": self.parseSimple(opt, args[1:], [ "partition:", "dir:" ]) if not self[opt].has_key("partition") or \ not self[opt].has_key("dir"): raise ValueError, "Error in line '%s'" % line # TODO: ignoredisk # TODO: iscsi # TODO: iscsiname elif opt == "key": self.parseSub(opt, args[1:], [ "skip" ]) elif opt == "langsupport": (_dict, _args) = self.parseArgs(args[1:], [ "default:" ]) self[opt] = _dict if len(args) > 0: self[opt]["supported"] = _args if len(self[opt]) == 0: raise ValueError, "Error in line '%s'" % line # TODO: logging elif opt == "logvol": if args[1] == "swap": args[1] = "swap.%d" % swap_id swap_id += 1 dict = self.parseSub(opt, args[1:], [ "vgname:", "size:", "name:", "noformat", "useexisting", "fstype:", "fsoptions:", "bytes-per-inode:", "grow", "maxsize:", "recommended", "percent" ]) self.convertLong(dict, "bytes-per-inode") self.convertDouble(dict, "percent") # TODO: mediacheck elif opt == "monitor": self.parseSimple(opt, args[1:], [ "noprobe", "monitor:", "hsync:", "vsync:" ]) # TODO: multipath elif opt == "network": dict = self.parseMultiple(opt, args[1:], [ "bootproto:", "device:", "ip:", "gateway:", "nameserver:", "nodns", "netmask:", "hostname:", "ethtool:", "essid:", "wepkey:", "onboot:", "class:", "mtu:", "noipv4", "noipv6" ]) self.stringSplit(dict, "nameserver") elif opt == "nfs": self.parseSimple(opt, args[1:], [ "server:", "dir:", "exclude:", "opts:" ]) if not self[opt].has_key("server") or \ not self[opt].has_key("dir"): raise ValueError, "Error in line '%s'" % line self.stringSplit(self[opt], "exclude") elif opt == "part" or opt == "partition": if args[1] == "swap": args[1] = "swap.%d" % swap_id swap_id += 1 dict = self.parseSub("partition", args[1:], [ "size:", "grow", "maxsize:", "noformat", "onpart:", "usepart:", "ondisk:", "ondrive:", "asprimary", "fstype:", "fsoptions:", "label:", "start:", "end:", "bytes-per-inode:", "recommended", "onbiosdisk" ], { "usepart": "onpart", "ondrive": "ondisk" }) self.convertLong(dict, "size") self.convertLong(dict, "maxsize") self.convertLong(dict, "start") self.convertLong(dict, "end") self.convertLong(dict, "bytes-per-inode") elif opt == "raid": (_dict, _args) = self.parseArgs(args[1:], [ "level:", "device:", "bytes_per_inode:", "spares:", "fstype:", "fsoptions:", "noformat", "useexisting" ]) if len(_args) < 2: raise ValueError, "'%s' is unsupported" % line if not self.has_key(opt): self[opt] = { } if self[opt].has_key(_args[0]): raise ValueError, "raid '%s' is not unique.", _args[0] if _dict.has_key("level") and \ _dict["level"].lower()[:4] == "raid": _dict["level"] = _dict["level"][4:] self.convertLong(_dict, "level") self.convertLong(_dict, "spares") _dict["partitions"] = _args[1:] self[opt][_args[0]] = _dict elif opt == "reboot": self.parseSimple(opt, args[1:], [ "eject" ]) elif opt == "repo": (_dict, _args) = self.parseArgs(args[1:], [ "name:", "baseurl:", "mirrorlist:", "exclude:" ]) if not _dict.has_key("name"): raise ValueError, "repo name not specified in '%s'" % \ line if not self.has_key(opt): self[opt] = {} if self.has_key(opt) and _dict["name"] in self[opt]: raise ValueError, "repo name '%s' is not unique." % \ _dict["name"] self.stringSplit(_dict, "exclude") self[opt][_dict["name"]] = _dict del _dict["name"] elif opt == "rootpw": self.parseSub(opt, args[1:], [ "iscrypted" ]) elif opt == "selinux": self.parseSimple(opt, args[1:], [ "enforcing", "permissive", "disabled" ]) elif opt == "services": self.parseSimple(opt, args[1:], [ "enabled:", "disabled:" ]) self.stringSplit(self[opt], "enabled") self.stringSplit(self[opt], "disabled") elif opt == "timezone": self.parseSub(opt, args[1:], [ "utc" ]) elif opt == "url": self.parseSimple(opt, args[1:], [ "url:", "exclude:", "mirrorlist:"]) if not self[opt].has_key("url") and \ not self[opt].has_key("mirrorlist"): raise ValueError, "Error in line '%s'" % line self.stringSplit(self[opt], "exclude") self.stringSplit(self[opt], "mirrorlist") elif opt == "user": dict = self.parseMultiple(opt, args[1:], [ "name:", "groups:", "homedir:", "password:"******"iscrypted", "shell:", "uid:", ]) self.stringSplit(dict, "groups") self.convertLong(dict, "uid") # TODO: vnc elif opt == "volgroup": (_dict, _args) = self.parseArgs(args[1:], [ "noformat", "useexisting", "pesize:" ]) if len(_args) < 2: raise ValueError, "'%s' is unsupported" % line _dict["partitions"] = _args[1:] if not self.has_key(opt): self[opt] = { } if self[opt].has_key(_args[0]): raise ValueError, \ "volgroup '%s' is already defined" % line self[opt][_args[0]] = _dict elif opt == "xconfig": self.parseSimple(opt, args[1:], [ "noprobe", "card:", "videoram:", "monitor:", "hsync:", "vsync:", "defaultdesktop:", "startxonboot", "resolution:", "depth:", "driver:" ], { "startX": "startxonboot", "videoRam": "videoram" }) else: log.info1("'%s' is unsupported.", line) elif in_packages: if len(args) == 1: # there was no space as delimiter args = [ line[:1], line[1:] ] opt = line if not self.has_key("packages"): self["packages"] = { } if opt[0] == "@": if not self["packages"].has_key("groups"): self["packages"]["groups"] = [ ] if not args[1] in self["packages"]["groups"]: self["packages"]["groups"].append(args[1]) elif opt[0] == "-": if not self["packages"].has_key("drop"): self["packages"]["drop"] = [ ] if not line in self["packages"]["drop"]: self["packages"]["drop"].append(args[1]) else: if not self["packages"].has_key("add"): self["packages"]["add"] = [ ] if not line in self["packages"]["add"]: self["packages"]["add"].append(opt) elif in_post >= 0: dict = self["post"][in_post] if not dict.has_key("script"): dict["script"] = "" dict["script"] += line+"\n" elif in_pre: if not self["pre"].has_key("script"): self["pre"]["script"] = "" self["pre"]["script"] += line+"\n" self.verify()
def load(self, ks, dir, beta_key_verify=False): self.dir = dir self.exclude = None # mount source to dir if ks.has_key("cdrom"): self.url = mount_cdrom(dir) if ks["cdrom"].has_key("exclude"): self.exclude = ks["cdrom"]["exclude"] elif ks.has_key("nfs"): opts = None if ks["nfs"].has_key("opts"): opts = ks["nfs"]["opts"] self.url = mount_nfs("nfs://%s:%s" % \ (ks["nfs"]["server"], ks["nfs"]["dir"]), dir, options=opts) if ks["nfs"].has_key("exclude"): self.exclude = ks["nfs"]["exclude"] else: self.url = ks["url"]["url"] if ks["url"].has_key("exclude"): self.exclude = ks["url"]["exclude"] # create network cache self.cache = NetworkCache([self.url], cachedir=rpmconfig.cachedir) # get source information via .discinfo file if not self.cache.cache(".discinfo"): log.error("No .discinfo for '%s'", self.url) return 0 di = get_discinfo(self.cache.cache(".discinfo")) if not di: log.error("Getting .discinfo for '%s' failed.", self.url) return 0 (self.name, self.version, self.arch) = di if self.name.startswith("Red Hat Enterprise Linux"): self.variant = self.name[24:].strip() self.id = "RHEL" self.prefix = "RedHat" elif self.name.startswith("Fedora"): self.variant = "" self.id = "FC" self.prefix = "Fedora" else: log.error("Unknown source '%s'.", self.name) return 0 self.release = "%s-%s" % (self.id, self.version) log.info1("Installation source: %s %s [%s]", self.name, self.version, self.arch) # load repos repos = [] self.yumconf = YumConf(self.version, self.arch, rpmdb=None, filenames=[], reposdirs=[]) if self.isRHEL() and self.cmpVersion("4.9") >= 0: # RHEL-5 key = None skip = False if ks.has_key("key"): key = ks["key"].keys()[0] if ks["key"][key].has_key("skip"): skip = True key = None inum = None if key and not skip and not beta_key_verify: if not instnum: log.warning("Unable to verify installation key, " "module instkey is missing.. using default" "installation.") else: try: inum = instnum.InstNum(key) except: log.error("Installation key '%s' is not valid.", key) return 0 if inum: if inum.get_product_string().lower() != \ self.variant.lower(): log.error( "Installation key for '%s' does not match " "'%s' media.", inum.get_product_string().lower(), self.variant.lower()) return 0 for name, path in inum.get_repos_dict().items(): if path == "VT" and \ not self.arch in [ "i386", "x86_64", "ia64" ]: continue repos.append(path) else: # BETA if self.variant == "Server": repos.append("Server") if key and key.find("C") >= 0: repos.append("Cluster") if key and key.find("S") >= 0: repos.append("ClusterStorage") elif self.variant == "Client": repos.append("Client") if key and key.find("W") >= 0: repos.append("Workstation") if self.arch in ["i386", "x86_64", "ia64"]: if key and key.find("V") >= 0: repos.append("VT") for repo in repos: repo_name = "%s-%s" % (self.release, repo) if repo in self.repos: log.error("Repository '%s' already defined.", repo_name) return 0 log.info1("Loading repo '%s'", repo_name) # create yumconf self.yumconf[repo_name] = {} self.yumconf[repo_name]["baseurl"] = [ "%s/%s" % (self.url, repo) ] if self.exclude: self.yumconf[repo_name]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo_name) self.repos[repo_name] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo_name) return 0 else: # RHEL <= 4 # FC repo = self.release self.yumconf[repo] = {} self.yumconf[repo]["baseurl"] = [self.url] if self.exclude: self.yumconf[repo]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 if not _repo.comps: # every source repo has to have a comps log.error("Missing comps file for '%s'.", repo) return 0 self.base_repo_names = self.repos.keys() if not ks.has_key("repo"): return 1 for repo in ks["repo"]: if repo in self.repos: log.error("Repository '%s' already defined.", repo) return 0 log.info1("Loading repository '%s'", repo) self.yumconf[repo] = {} url = ks["repo"][repo]["baseurl"] if url[:6] == "nfs://": d = "%s/%s" % (dir, repo) create_dir("", d) url = mount_nfs(url, d) self.yumconf[repo]["baseurl"] = [url] if ks["repo"][repo].has_key("exclude"): self.yumconf[repo]["exclude"] = ks["repo"][repo]["exclude"] if ks["repo"][repo].has_key("mirrorlist"): self.yumconf[repo]["mirrorlist"] = \ ks["repo"][repo]["mirrorlist"] _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 return 1