From 5da91f89c12b998a4e83db4d21ec6086aca37feb Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Fri, 11 Apr 2008 12:17:42 -0400 Subject: Import now takes an --arch, which is now a recommended field, to ensure best practices in naming. --- cobbler/action_check.py | 22 ++++++++++-------- cobbler/action_import.py | 23 ++++++++++++++++++- cobbler/api.py | 4 ++-- cobbler/modules/cli_misc.py | 8 ++++--- cobbler/utils.py | 56 +++++++++++++++++++++++++++++---------------- 5 files changed, 78 insertions(+), 35 deletions(-) (limited to 'cobbler') diff --git a/cobbler/action_check.py b/cobbler/action_check.py index 85084d7..e91396f 100644 --- a/cobbler/action_check.py +++ b/cobbler/action_check.py @@ -19,7 +19,6 @@ import sub_process import action_sync import utils from utils import _ - class BootCheck: def __init__(self,config): @@ -61,10 +60,18 @@ class BootCheck: return status def check_service(self, status, which): - if os.path.exists("/etc/rc.d/init.d/%s" % which): - rc = sub_process.call("/sbin/service %s status >/dev/null 2>/dev/null" % which, shell=True) - if rc != 0: - status.append(_("service %s is not running") % which) + if utils.check_dist() == "redhat": + if os.path.exists("/etc/rc.d/init.d/%s" % which): + rc = sub_process.call("/sbin/service %s status >/dev/null 2>/dev/null" % which, shell=True) + if rc != 0: + status.append(_("service %s is not running") % which) + elif utils.check_dist() == "debian": + if os.path.exists("/etc/init.d/%s" % which): + rc = sub_process.call("/etc/init.d/%s status /dev/null 2>/dev/null" % which, shell=True) + if rc != 0: + status.append(_("service %s is not running") % which) + else: + status.append(_("Unknown distribution type, cannot check for running service %s" % which)) def check_iptables(self, status): if os.path.exists("/etc/rc.d/init.d/iptables"): @@ -95,10 +102,7 @@ class BootCheck: """ Check if Apache is installed. """ - if not os.path.exists(self.settings.httpd_bin): - status.append(_("Apache doesn't appear to be installed")) - else: - self.check_service(status,"httpd") + self.check_service(status,"httpd") def check_dhcpd_bin(self,status): diff --git a/cobbler/action_import.py b/cobbler/action_import.py index d224e55..7f5409b 100644 --- a/cobbler/action_import.py +++ b/cobbler/action_import.py @@ -36,7 +36,7 @@ TRY_LIST = [ class Importer: - def __init__(self,api,config,mirror,mirror_name,network_root=None,kickstart_file=None,rsync_flags=None): + def __init__(self,api,config,mirror,mirror_name,network_root=None,kickstart_file=None,rsync_flags=None,arch=None): """ Performs an import of a install tree (or trees) from the given mirror address. The prefix of the distro is to be specified @@ -59,6 +59,7 @@ class Importer: self.distros_added = [] self.kickstart_file = kickstart_file self.rsync_flags = rsync_flags + self.arch = arch # ---------------------------------------------------------------------- @@ -67,6 +68,26 @@ class Importer: raise CX(_("import failed. no --mirror specified")) if self.mirror_name is None: raise CX(_("import failed. no --name specified")) + if self.arch is not None: + self.arch = self.arch.lower() + if self.arch not in [ "x86", "ia64", "x86_64" ]: + raise CX(_("arch must be x86, x86_64, or ia64")) + + mpath = os.path.join(self.settings.webdir, "ks_mirror", self.mirror_name) + if os.path.exists(mpath) and self.arch is None: + if not found: + raise CX(_("Something already exists at this import location (%s). You must specify --arch to avoid potentially overwriting existing files.") % mpath) + + if self.arch: + # append the arch path to the name if the arch is not already + # found in the name. + found = False + for x in [ "ia64", "i386", "x86_64", "x86" ]: + if self.mirror_name.lower().find(x) != -1: + found = True + break + if not found: + self.mirror_name = self.mirror_name + "-" + self.arch if self.mirror_name is None: raise CX(_("import failed. no --name specified")) diff --git a/cobbler/api.py b/cobbler/api.py index 0eacb78..ef6fa8e 100644 --- a/cobbler/api.py +++ b/cobbler/api.py @@ -336,7 +336,7 @@ class BootAPI: statusifier = action_status.BootStatusReport(self._config, mode) return statusifier.run() - def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=None,rsync_flags=None): + def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=None,rsync_flags=None,arch=None): """ Automatically import a directory tree full of distribution files. mirror_url can be a string that represents a path, a user@host @@ -346,7 +346,7 @@ class BootAPI: """ self.log("import_tree",[mirror_url, mirror_name, network_root, kickstart_file, rsync_flags]) importer = action_import.Importer( - self, self._config, mirror_url, mirror_name, network_root, kickstart_file, rsync_flags + self, self._config, mirror_url, mirror_name, network_root, kickstart_file, rsync_flags, arch ) return importer.run() diff --git a/cobbler/modules/cli_misc.py b/cobbler/modules/cli_misc.py index 0fd44a6..f8b0a7d 100644 --- a/cobbler/modules/cli_misc.py +++ b/cobbler/modules/cli_misc.py @@ -73,11 +73,12 @@ class ImportFunction(commands.CobblerFunction): return "import" def add_options(self, p, args): + p.add_option("--arch", dest="arch", help="explicitly specify the architecture being imported (RECOMENDED)") p.add_option("--path", dest="mirror", help="local path or rsync location (REQUIRED)") p.add_option("--mirror", dest="mirror_alt", help="alias for --path") p.add_option("--name", dest="name", help="name, ex 'RHEL-5', (REQUIRED)") - p.add_option("--available-as", dest="available_as", help="do not mirror, use this as install tree") - p.add_option("--kickstart", dest="kickstart_file", help="use the kickstart file specified as the profile's kickstart file") + p.add_option("--available-as", dest="available_as", help="do not mirror, use this as install tree base") + p.add_option("--kickstart", dest="kickstart_file", help="use the kickstart file specified as the profile's kickstart file, do not auto-assign") p.add_option("--rsync-flags", dest="rsync_flags", help="pass additional flags to rsync") def run(self): @@ -92,7 +93,8 @@ class ImportFunction(commands.CobblerFunction): self.options.name, network_root=self.options.available_as, kickstart_file=self.options.kickstart_file, - rsync_flags=self.options.rsync_flags + rsync_flags=self.options.rsync_flags, + arch=self.options.arch ) diff --git a/cobbler/utils.py b/cobbler/utils.py index 8757762..d8cf6fc 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -487,28 +487,44 @@ def fix_mod_python_select_submission(repos): repos = repos.replace('"',"") repos = repos.lstrip().rstrip() return repos +def check_dist(): + if os.path.exists("/etc/debian_version"): + return "debian" + else: + return "redhat" def redhat_release(): - if not os.path.exists("/bin/rpm"): - return ("unknown", 0) - args = ["/bin/rpm", "-q", "--whatprovides", "redhat-release"] - cmd = sub_process.Popen(args,shell=False,stdout=sub_process.PIPE) - data = cmd.communicate()[0] - data = data.rstrip().lower() - make = "other" - if data.find("redhat") != -1: - make = "redhat" - elif data.find("centos") != -1: - make = "centos" - elif data.find("fedora") != -1: - make = "fedora" - version = data.split("release-")[-1] - rest = 0 - if version.find("-"): - parts = version.split("-") - version = parts[0] - rest = parts[1] - return (make, float(version), rest) + if check_dist() == "redhat": + + if not os.path.exists("/bin/rpm"): + return ("unknown", 0) + args = ["/bin/rpm", "-q", "--whatprovides", "redhat-release"] + cmd = sub_process.Popen(args,shell=False,stdout=sub_process.PIPE) + data = cmd.communicate()[0] + data = data.rstrip().lower() + make = "other" + if data.find("redhat") != -1: + make = "redhat" + elif data.find("centos") != -1: + make = "centos" + elif data.find("fedora") != -1: + make = "fedora" + version = data.split("release-")[-1] + rest = 0 + if version.find("-"): + parts = version.split("-") + version = parts[0] + rest = parts[1] + return (make, float(version), rest) + elif check_dist() == "debian": + fd = open("/etc/debian_version") + parts = fd.read().split(".") + version = parts[0] + rest = parts[1] + make = "debian" + return (make, float(version), rest) + else: + return ("unknown",0) def tftpboot_location(): -- cgit