Permalink
Browse files

Fixes to import_tree() to actually copy files to a safe place when --…

…available-as is specified.

Also some cleanup to the debian/ubuntu import module for when --available-as is specified.
  • Loading branch information...
1 parent 53dc281 commit 494d36ff5053958a90fc71c48a5b038b6b1907b0 @jimi-c jimi-c committed Nov 6, 2011
Showing with 41 additions and 42 deletions.
  1. +37 −39 cobbler/api.py
  2. +4 −3 cobbler/modules/manage_import_debian_ubuntu.py
View
@@ -22,6 +22,7 @@
02110-1301 USA
"""
+import sys
import yaml
import config
import utils
@@ -749,7 +750,7 @@ def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=Non
"""
self.log("import_tree",[mirror_url, mirror_name, network_root, kickstart_file, rsync_flags])
- # both --import and --name are required arguments
+ # both --path and --name are required arguments
if mirror_url is None:
self.log("import failed. no --path specified")
return False
@@ -765,55 +766,49 @@ def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=Non
arch = "i386"
path += ("-%s" % arch)
- if network_root is None:
- # we need to mirror (copy) the files
- self.log("importing from a network location, running rsync to fetch the files first")
+ # we need to mirror (copy) the files
+ self.log("importing from a network location, running rsync to fetch the files first")
- utils.mkdir(path)
+ utils.mkdir(path)
- # prevent rsync from creating the directory name twice
- # if we are copying via rsync
+ # prevent rsync from creating the directory name twice
+ # if we are copying via rsync
- if not mirror_url.endswith("/"):
- mirror_url = "%s/" % mirror_url
-
- if mirror_url.startswith("http://") or mirror_url.startswith("ftp://") or mirror_url.startswith("nfs://"):
- # http mirrors are kind of primative. rsync is better.
- # that's why this isn't documented in the manpage and we don't support them.
- # TODO: how about adding recursive FTP as an option?
- self.log("unsupported protocol")
- return False
- else:
- # good, we're going to use rsync..
- # we don't use SSH for public mirrors and local files.
- # presence of user@host syntax means use SSH
- spacer = ""
- if not mirror_url.startswith("rsync://") and not mirror_url.startswith("/"):
- spacer = ' -e "ssh" '
- rsync_cmd = RSYNC_CMD
- if rsync_flags:
- rsync_cmd = rsync_cmd + " " + rsync_flags
-
- # kick off the rsync now
-
- utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)
+ if not mirror_url.endswith("/"):
+ mirror_url = "%s/" % mirror_url
+ if mirror_url.startswith("http://") or mirror_url.startswith("ftp://") or mirror_url.startswith("nfs://"):
+ # http mirrors are kind of primative. rsync is better.
+ # that's why this isn't documented in the manpage and we don't support them.
+ # TODO: how about adding recursive FTP as an option?
+ self.log("unsupported protocol")
+ return False
else:
-
- # rather than mirroring, we're going to assume the path is available
+ # good, we're going to use rsync..
+ # we don't use SSH for public mirrors and local files.
+ # presence of user@host syntax means use SSH
+ spacer = ""
+ if not mirror_url.startswith("rsync://") and not mirror_url.startswith("/"):
+ spacer = ' -e "ssh" '
+ rsync_cmd = RSYNC_CMD
+ if rsync_flags:
+ rsync_cmd = rsync_cmd + " " + rsync_flags
+
+ # kick off the rsync now
+ utils.run_this(rsync_cmd, (spacer, mirror_url, path), self.logger)
+
+ if network_root is not None:
+ # in addition to mirroring, we're going to assume the path is available
# over http, ftp, and nfs, perhaps on an external filer. scanning still requires
- # --mirror is a filesystem path, but --available-as marks the network path
-
- if not os.path.exists(mirror_url):
- self.log("path does not exist: %s" % mirror_url)
- return False
+ # --mirror is a filesystem path, but --available-as marks the network path.
+ # this allows users to point the path at a directory containing just the network
+ # boot files while the rest of the distro files are available somewhere else.
# find the filesystem part of the path, after the server bits, as each distro
# URL needs to be calculated relative to this.
if not network_root.endswith("/"):
network_root = network_root + "/"
- path = os.path.normpath( mirror_url )
valid_roots = [ "nfs://", "ftp://", "http://" ]
for valid_root in valid_roots:
if network_root.startswith(valid_root):
@@ -838,9 +833,12 @@ def import_tree(self,mirror_url,mirror_name,network_root=None,kickstart_file=Non
self.log("running import manager: %s" % manager.what())
return manager.run(pkgdir,mirror_name,path,network_root,kickstart_file,rsync_flags,arch,breed,os_version)
except:
- self.log("an error occured while running the import manager")
+ self.log("an exception occured while running the import manager")
+ self.log("error was: %s" % sys.exc_info()[1])
continue
self.log("No import managers found a valid signature at the location specified")
+ # FIXME: since we failed, we should probably remove the
+ # path tree we created above so we don't leave cruft around
return False
# ==========================================================================
@@ -211,7 +211,7 @@ def get_tree_location(self, distro):
# and the input start directory in the crawl. We find the path segments
# between and tack them on the network source path to find the explicit
# network path to the distro that Anaconda can digest.
- tail = self.path_tail(self.path, base)
+ tail = utils.path_tail(self.path, base)
tree = self.network_root[:-1] + tail
self.set_install_tree(distro, tree)
@@ -282,7 +282,8 @@ def add_entry(self,dirname,kernel,initrd):
proposed_arch = self.get_proposed_arch(dirname)
if self.arch and proposed_arch and self.arch != proposed_arch:
- utils.die(self.logger,"Arch from pathname (%s) does not match with supplied one %s"%(proposed_arch,self.arch))
+ self.logger.error("Arch from pathname (%s) does not match with supplied one (%s)"%(proposed_arch,self.arch))
+ return
archs = self.learn_arch_from_tree()
if not archs:
@@ -374,7 +375,7 @@ def get_proposed_name(self,dirname,kernel=None):
"""
if self.network_root is not None:
- name = self.name + "-".join(self.path_tail(os.path.dirname(self.path),dirname).split("/"))
+ name = self.name #+ "-".join(utils.path_tail(os.path.dirname(self.path),dirname).split("/"))
else:
# remove the part that says /var/www/cobbler/ks_mirror/name
name = "-".join(dirname.split("/")[5:])

0 comments on commit 494d36f

Please sign in to comment.