>> I've been revisiting the previous import code, and I'm working in a
>> small refactoring that will probably re-enable importing of multiple
>> distros at the same time, at the price of all of them sharing a single
>> breed specified at command line, and will also make easier to add
>> other distros.
>>
Actually recover the multi-import has been much easier than I expected. The
patch attached works, at least for me.
I can import three distros as
cobbler import --mirror=/media/distros/rhas/4.6 --name=rhas
cobbler import --path=/media/distros/Fedora9/i386/ --name=f9_32
cobbler import --mirror=/media/distros/Fedora9/x86_64 --name=f9_64
or issue a single command
cobbler import --mirror=/media/distros --name=allinone --breed=redhat
and all of them work.
Regarding the patch itself, a couple of comments. I've moved distro_adder method
close to the distro add related method, but there is no change there.
I have also
modified item_distro.py, to remove breed and arch defaults. It was
difficult to know
why (and where) was the distro flavor set without os version until I
realize that the
redhat flavor was given on instantiation. It might be safer not to
move that change
into HEAD, but at least for devel branch I believe it is a good idea
to have no such
hardcoded defaults.
The remaining changes are mostly intended as a first step to the real
refactor, to
make easier understand the changes than submitting the patch in the final form
Javier Palacios
diff --git a/Makefile b/Makefile
index 85b6f8b..d0c3e89 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ test: devinstall
-cp /var/lib/cobbler/profiles* /tmp/cobbler_test_bak
-cp /var/lib/cobbler/systems* /tmp/cobbler_test_bak
-cp /var/lib/cobbler/repos* /tmp/cobbler_test_bak
- -cp /var/lib/cobbler/repos* /tmp/cobbler_test_bak
+ -cp /var/lib/cobbler/images* /tmp/cobbler_test_bak
python tests/tests.py
-cp /tmp/cobbler_test_bak/* /var/lib/cobbler
diff --git a/cobbler/action_import.py b/cobbler/action_import.py
index e4c0836..aade99f 100644
--- a/cobbler/action_import.py
+++ b/cobbler/action_import.py
@@ -33,15 +33,14 @@ import utils
import shutil
from utils import _
-WGET_CMD = "wget --mirror --no-parent --no-host-directories --directory-prefix
%s/%s %s"
-RSYNC_CMD = "rsync -a %s '%s' %s/ks_mirror/%s
--exclude-from=/etc/cobbler/rsync.exclude --progress"
+RSYNC_CMD = "rsync --quiet -a %s '%s' %s/ks_mirror/%s
--exclude-from=/etc/cobbler/rsync.exclude --progress"
-TRY_LIST = [
- "pool",
- "Fedora", "Packages", "RedHat", "Client", "Server", "Centos", "CentOS",
+TRY_DICT = {
+ 'debian': [ "pool" ],
+ 'redhat': [ "Fedora", "Packages", "RedHat", "Client", "Server", "Centos",
"CentOS",
"Fedora/RPMS", "RedHat/RPMS", "Client/RPMS", "Server/RPMS", "Centos/RPMS",
- "CentOS/RPMS", "RPMS"
-]
+ "CentOS/RPMS", "RPMS" ]
+}
class Importer:
@@ -208,12 +207,13 @@ class Importer:
if self.kickstart_file == None:
kdir = os.path.dirname(distro.kernel)
- # FIXME : Some special handling for network_root might be
required as in get_proposed_name,
- base_dir = "/".join(kdir.split("/")[:6])
+ base_dir = self.get_new_tree_root(kdir)
- for try_entry in TRY_LIST:
+ for try_key in TRY_DICT.keys():
+ for try_entry in TRY_DICT[try_key]:
try_dir = os.path.join(base_dir, try_entry)
if os.path.exists(try_dir):
+ if try_key == "redhat":
rpms = glob.glob(os.path.join(try_dir, "*release-*"))
for rpm in rpms:
if rpm.find("notes") != -1:
@@ -224,7 +224,7 @@ class Importer:
(flavor, major, minor) = results
# print _("- finding default kickstart template for
%(flavor)s %(major)s") % { "flavor" : flavor, "major" : major }
kickstart = self.set_variance(profile, flavor,
major, minor, distro)
- if not rpms:
+ elif try_key == "debian":
# search for base-files or base-installer ?
rpms = glob.glob(os.path.join(try_dir,
"main/b/base-files" , "base-files_*"))
for rpm in rpms:
@@ -255,6 +255,8 @@ class Importer:
base = "/".join(tokens)
dest_link = os.path.join(self.settings.webdir, "links", distro.name)
+ meta = distro.ks_meta
+
# create the links directory only if we are mirroring because with
# SELinux Apache can't symlink to NFS (without some doing)
@@ -265,14 +267,7 @@ class Importer:
except:
# this shouldn't happen but I've seen it ... debug ...
print _("- symlink creation failed: %(base)s, %(dest)s") %
{ "base" : base, "dest" : dest_link }
-
- # FIXME: looks like "base" isn't used later. remove?
- base = base.replace(self.settings.webdir,"")
-
- meta = distro.ks_meta
-
- # how we set the tree depends on whether an explicit network_root was
specified
- if self.network_root is None:
+ # how we set the tree depends on whether an explicit network_root
was specified
meta["tree"] = "http://@@http_server@@/cblr/links/%s" %
(distro.name)
else:
# where we assign the kickstart source is relative to our current
directory
@@ -374,6 +369,7 @@ class Importer:
"""
rpm = os.path.basename(rpm)
+ print "- processing rpm : %s" % rpm
# if it looks like a RHEL RPM we'll cheat.
# it may be slightly wrong, but it will be close enough
@@ -390,7 +386,7 @@ class Importer:
return ("redhat", 2, 0)
# now get the flavor:
- flavor = "redhat"
+ flavor = None
if rpm.lower().find("fedora") != -1:
flavor = "fedora"
if rpm.lower().find("centos") != -1:
@@ -418,6 +414,7 @@ class Importer:
"""
deb = os.path.basename(deb)
+ print "- processing deb : %s" % deb
# now get the flavor:
flavor = "debian"
@@ -442,41 +439,6 @@ class Importer:
return (flavor, accum[0], accum[1])
# ----------------------------------------------------------------------
-
- def distro_adder(self,foo,dirname,fnames):
-
- initrd = None
- kernel = None
-
- for x in fnames:
-
- 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):
- if not self.breed:
- self.breed = x
- elif self.breed != x:
- print "- WARNING - symlink name (%s) does not fit the breed
(%s)" % ( x , self.breed )
- continue
- print "- following symlink: %s" % fullname
- os.path.walk(fullname, self.distro_adder, {})
-
- if x.startswith("initrd"):
- initrd = os.path.join(dirname,x)
- if x.startswith("vmlinuz") or x.startswith("kernel.img"):
- # This ugly trick is to avoid inclusion of powerpc kernels from
debian distros
- if x.find("initrd") != -1:
- continue
- kernel = os.path.join(dirname,x)
- if initrd is not None and kernel is not None and
dirname.find("isolinux") == -1:
- self.add_entry(dirname,kernel,initrd)
- # The values are reset because debian media has extra initrd
images
- initrd = None
- kernel = None
-
-
-
- # ----------------------------------------------------------------------
def repo_finder(self):
@@ -484,8 +446,7 @@ class Importer:
print _("- traversing distro %s") % distro.name
if distro.kernel.find("ks_mirror") != -1:
basepath = os.path.dirname(distro.kernel)
- # FIXME : Some special handling for network_root might be
required as in get_proposed_name,
- top = "/".join(basepath.split("/")[:6])
+ top = self.get_new_tree_root(basepath)
print _("- descent into %s") % top
os.path.walk(top, self.repo_scanner, distro)
else:
@@ -496,9 +457,9 @@ class Importer:
def repo_scanner(self,distro,dirname,fnames):
matches = {}
- print "- processing: %s" % dirname
for x in fnames:
if x == "base" or x == "repodata":
+ print "- processing repo at : %s" % dirname
# only run the repo scanner on directories that contain a
comps.xml
gloob1 = glob.glob("%s/%s/*comps*.xml" % (dirname,x))
if len(gloob1) >= 1:
@@ -598,6 +559,39 @@ class Importer:
traceback.print_exc()
+ # ----------------------------------------------------------------------
+
+ def distro_adder(self,foo,dirname,fnames):
+
+ initrd = None
+ kernel = None
+
+ for x in fnames:
+
+ 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):
+ if not self.breed:
+ self.breed = x
+ elif self.breed != x:
+ print "- WARNING - symlink name (%s) does not fit the breed
(%s)" % ( x , self.breed )
+ continue
+ print "- following symlink: %s" % fullname
+ os.path.walk(fullname, self.distro_adder, {})
+
+ if x.startswith("initrd"):
+ initrd = os.path.join(dirname,x)
+ if x.startswith("vmlinuz") or x.startswith("kernel.img"):
+ # This ugly trick is to avoid inclusion of powerpc kernels from
debian distros
+ if x.find("initrd") != -1:
+ continue
+ kernel = os.path.join(dirname,x)
+ if initrd is not None and kernel is not None and
dirname.find("isolinux") == -1:
+ self.add_entry(dirname,kernel,initrd)
+ # The values are reset because debian media has extra initrd
images
+ initrd = None
+ kernel = None
+
def add_entry(self,dirname,kernel,initrd):
for pxe_arch in self.get_pxe_arch(dirname):
name = self.get_proposed_name(dirname, pxe_arch)
@@ -675,16 +669,21 @@ class Importer:
return name
+ def match_try_list(self,dirname):
+ for try_key in TRY_DICT.keys():
+ for x in TRY_DICT[try_key]:
+ if dirname.find(x) != -1:
+ return x
+ return False
+
def arch_walker(self,foo,dirname,fnames):
"""
See docs on learn_arch_from_tree
"""
# don't care about certain directories
- for x in TRY_LIST:
- if dirname.find(x) != -1:
- break
- else:
+ x = self.match_try_list(dirname)
+ if not x:
return
# try to find a kernel header RPM and then look at it's arch.
@@ -692,14 +691,13 @@ class Importer:
if not x.endswith("rpm") and not x.endswith("deb"):
continue
if x.find("kernel-header") != -1 or x.find("linux-headers-") != -1:
- print _("- kernel header found: %s") % x
+ # print _("- kernel header found: %s") % x
for arch in [ "i386" , "x86_64" , "ia64" , "s390x" ]:
if x.find(arch) != -1:
foo[arch] = 1
- if x.find("amd64") != -1:
- foo["x86_64"] = 1
- if x.find("i686") != -1:
- foo["i386"] = 1
+ for arch in [ "i686" , "amd64" ]:
+ if x.find(arch) != -1:
+ foo[arch] = 1
if foo.keys():
return
@@ -711,14 +709,21 @@ class Importer:
if not x.endswith("rpm") and not x.endswith("deb"):
continue
if x.find("kernel-largesmp") != -1 or x.find("kernel-hugemem") != -1
or x.find("linux-headers-") != -1:
- print _("- kernel header found: %s") % x
+ # print _("- kernel header found: %s") % x
for arch in [ "i386" , "x86_64" , "ia64" , "s390x" ]:
if x.find(arch) != -1:
foo[arch] = 1
- if x.find("amd64") != -1:
- foo["x86_64"] = 1
- if x.find("i686") != -1:
- foo["i386"] = 1
+ for arch in [ "i686" , "amd64" ]:
+ if x.find(arch) != -1:
+ foo[arch] = 1
+
+ def get_new_tree_root(self,dirname):
+ # FIXME : Some special handling for network_root might be required as
in get_proposed_name,
+ if self.breed == "redhat":
+ rootdir = "/".join(dirname.split("/")[:-2])
+ else:
+ rootdir = "/".join(dirname.split("/")[:6])
+ return rootdir
def learn_arch_from_tree(self,dirname):
"""
@@ -727,11 +732,15 @@ class Importer:
figure out the arch name. This is important for producing predictable
distro names (and profile names)
from differing import sources
"""
- # FIXME : Some special handling for network_root might be required as
in get_proposed_name,
- dirname2 = "/".join(dirname.split("/")[:6])
+ dirname2 = self.get_new_tree_root(dirname)
print _("- scanning %s for architecture info") % dirname2
result = {}
os.path.walk(dirname2, self.arch_walker, result)
+ print _("- architectures found : %s") % ( result.keys() )
+ if result.pop("amd64",False):
+ result["x86_64"] = 1
+ if result.pop("i686",False):
+ result["i386"] = 1
return result.keys()
def get_pxe_arch(self,dirname):
diff --git a/cobbler/item_distro.py b/cobbler/item_distro.py
index d5b2a32..f498d96 100644
--- a/cobbler/item_distro.py
+++ b/cobbler/item_distro.py
@@ -47,8 +47,8 @@ class Distro(item.Item):
self.kernel_options = {}
self.kernel_options_post = {}
self.ks_meta = {}
- self.arch = 'i386'
- self.breed = 'redhat'
+ self.arch = None
+ self.breed = None
self.os_version = ''
self.source_repos = []
self.mgmt_classes = []
@@ -79,8 +79,8 @@ class Distro(item.Item):
self.kernel_options =
self.load_item(seed_data,'kernel_options')
self.kernel_options_post =
self.load_item(seed_data,'kernel_options_post')
self.ks_meta = self.load_item(seed_data,'ks_meta')
- self.arch = self.load_item(seed_data,'arch','i386')
- self.breed =
self.load_item(seed_data,'breed','redhat')
+ self.arch = self.load_item(seed_data,'arch',None)
+ self.breed = self.load_item(seed_data,'breed',None)
self.os_version = self.load_item(seed_data,'os_version','')
self.source_repos =
self.load_item(seed_data,'source_repos',[])
self.depth = self.load_item(seed_data,'depth',0)
_______________________________________________
cobbler mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/cobbler