diff --git a/cobbler/action_import.py b/cobbler/action_import.py index 7672433..af228c6 100644 --- a/cobbler/action_import.py +++ b/cobbler/action_import.py @@ -37,6 +37,7 @@ WGET_CMD = "wget --mirror --no-parent --no-host-directories --directory-prefix % RSYNC_CMD = "rsync -a %s '%s' %s/ks_mirror/%s --exclude-from=/etc/cobbler/rsync.exclude --progress" TRY_LIST = [ + "pool", "Fedora", "Packages", "RedHat", "Client", "Server", "Centos", "CentOS", "Fedora/RPMS", "RedHat/RPMS", "Client/RPMS", "Server/RPMS", "Centos/RPMS", "CentOS/RPMS", "RPMS" @@ -68,6 +69,7 @@ class Importer: self.kickstart_file = kickstart_file self.rsync_flags = rsync_flags self.arch = arch + self.breed_guess = None # ---------------------------------------------------------------------- @@ -79,7 +81,8 @@ class Importer: if self.arch is not None: self.arch = self.arch.lower() if self.arch in utils.archmaps.keys(): - self.arch = utils.archmaps[self.arch] + if utils.archmaps[self.arch]: + self.arch = utils.archmaps[self.arch] if self.arch not in utils.validarchs: raise CX(_("arch must be one of %s") % ", ".join(utils.validarchs)) @@ -133,18 +136,17 @@ class Importer: if not self.network_root.endswith("/"): self.network_root = self.network_root + "/" self.path = self.mirror - found_root = False valid_roots = [ "nfs://", "ftp://", "http://" ] for valid_root in valid_roots: if self.network_root.startswith(valid_root): - found_root = True + break + else: + raise CX(_("Network root given to --available-as must be %s") % ", ".join(valid_roots)) if self.network_root.startswith("nfs://"): try: (a,b,rest) = self.network_root.split(":",3) except: raise CX(_("Network root given to --available-as is missing a colon, please see the manpage example.")) - if not found_root: - raise CX(_("Network root given to --available-as must be nfs://, ftp://, or http://")) self.processed_repos = {} @@ -352,6 +354,10 @@ class Importer: fullname = os.path.join(dirname,x) if os.path.islink(fullname) and os.path.isdir(fullname): + if os.path.realpath(fullname) == os.path.realpath(dirname): + print _("- found self-refering link, probably debian based distro") + self.breed_guess = "debian" + continue print "- following symlink: %s" % fullname os.path.walk(fullname, self.distro_adder, {}) @@ -504,6 +510,8 @@ class Importer: distro.set_kernel(kernel) distro.set_initrd(initrd) distro.set_arch(pxe_arch) + if self.breed_guess : + distro.set_breed(self.breed_guess) distro.source_repos = [] self.distros.add(distro,save=True) self.distros_added.append(distro) @@ -547,9 +555,12 @@ class Importer: name = name.replace("ks_mirror-","") name = name.replace("-pxeboot","") name = name.replace("--","-") - for separator in [ '-' , '_' ] : + for separator in [ '-' , '_' , '.' ] : for arch in utils.validarchs: name = name.replace("%s%s" % ( separator , arch ),"") + for separator in [ '-' , '_' , '.' ] : + for arch in utils.archmaps.keys(): + name = name.replace("%s%s" % ( separator , arch ),"") # ensure arch is on the end, regardless of path used. name = name + "-" + archname @@ -561,17 +572,15 @@ class Importer: """ # don't care about certain directories - match = False for x in TRY_LIST: if dirname.find(x) != -1: - match = True - continue - if not match: + break + else: return # try to find a kernel header RPM and then look at it's arch. for x in fnames: - if not x.endswith("rpm"): + if not x.endswith("rpm") and not x.endswith("deb"): continue if x.find("kernel-header") != -1: print _("- kernel header found: %s") % x @@ -580,15 +589,16 @@ class Importer: foo["result"] = arch return for arch in utils.archmaps.keys(): - if x.find(arch) != -1: - foo["result"] = utils.archmaps[arch] - return + if utils.archmaps[arch]: + if x.find(arch) != -1: + foo["result"] = utils.archmaps[arch] + return # This extra code block is a temporary fix for rhel4.x 64bit [x86_64] # distro ARCH identification-- L.M. # NOTE: eventually refactor to merge in with the above block for x in fnames: - if not x.endswith("rpm"): + if not x.endswith("rpm") and not x.endswith("deb"): continue if x.find("kernel-largesmp") != -1: print _("- kernel header found: %s") % x @@ -597,9 +607,10 @@ class Importer: foo["result"] = arch return for arch in utils.archmaps.keys(): - if x.find(arch) != -1: - foo["result"] = utils.archmaps[arch] - return + if utils.archmaps[arch]: + if x.find(arch) != -1: + foo["result"] = utils.archmaps[arch] + return def learn_arch_from_tree(self,dirname): """ @@ -608,10 +619,11 @@ class Importer: figure out the arch name. This is important for producing predictable distro names (and profile names) from differing import sources """ - dirname2 = "/".join(dirname.split("/")[:-2]) # up two from images, then down as many as needed - print _("- scanning %s for architecture info") % dirname2 + # FIXME : Some special handling for network_root might be required as in get_proposed_name, + rootdir = "/".join(dirname.split("/")[:6]) # up two from images, then down as many as needed + print _("- scanning %s for architecture info") % rootdir result = { "result" : "i386" } # default, but possibly not correct ... - os.path.walk(dirname2, self.arch_walker, result) + os.path.walk(rootdir, self.arch_walker, result) return result["result"] def get_pxe_arch(self,dirname): @@ -620,7 +632,8 @@ class Importer: if t.find(arch) != -1: return arch for arch in utils.archmaps.keys(): - if t.find(arch) != -1: - return utils.archmaps[arch] + if utils.archmaps[arch]: + if t.find(arch) != -1: + return utils.archmaps[arch] return self.learn_arch_from_tree(dirname) diff --git a/cobbler/utils.py b/cobbler/utils.py index 77f671f..fdbad2e 100644 --- a/cobbler/utils.py +++ b/cobbler/utils.py @@ -39,7 +39,8 @@ from cexceptions import * import codes validarchs = [ "i386", "ia64", "x86_64", "s390x" ] -archmaps = { "x86" : "i386" , "amd64" : "x86_68" } +# NOTE : archs keys mapping to empty strings are used only while replacing on filenames +archmaps = { "x86" : "i386" , "amd64" : "x86_68" , "386" : "" } CHEETAH_ERROR_DISCLAIMER=""" # There is a templating error preventing this file from rendering correctly.