[et-mgmt-tools] [PATCH] Let users keep images in /tftpboot

Jack Neely jjneely at ncsu.edu
Mon Oct 15 15:24:34 UTC 2007


I tend to keep images in the /tftpboot space ordered by support group.
This makes cobbler use hard/soft links in that case and does some simple
testing for filesystem suckiness.

Jack Neely

---
 cobbler/action_sync.py |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/cobbler/action_sync.py b/cobbler/action_sync.py
index 3de38a8..ee707f3 100644
--- a/cobbler/action_sync.py
+++ b/cobbler/action_sync.py
@@ -302,8 +302,14 @@ class BootSync:
                 raise CX(_("initrd not found: %(file)s, distro: %(distro)s") % { "file" : d.initrd, "distro" : d.name })
             b_kernel = os.path.basename(kernel)
             b_initrd = os.path.basename(initrd)
-            self.copyfile(kernel, os.path.join(distro_dir, b_kernel))
-            self.copyfile(initrd, os.path.join(distro_dir, b_initrd))
+            if kernel.startswith(dirtree):
+                self.linkfile(kernel, os.path.join(distro_dir, b_kernel))
+            else:
+                self.copyfile(kernel, os.path.join(distro_dir, b_kernel))
+            if initrd.startswith(dirtree):
+                self.linkfile(initrd, os.path.join(distro_dir, b_initrd))
+            else:
+                self.copyfile(initrd, os.path.join(distro_dir, b_initrd))
 
     def validate_kickstarts(self):
         """
@@ -840,6 +846,25 @@ class BootSync:
         fd.write(yaml.dump(blended))
         fd.close()
 
+    def linkfile(self, src, dst):
+        """
+        Attempt to create a link dst that points to src.  Because file
+        systems suck we attempt several different methods or bail to
+        self.copyfile()
+        """
+
+        try:
+            return os.link(src, dst)
+        except (IOError, OSError):
+            pass
+
+        try:
+            return os.symlink(src, dst)
+        except (IOError, OSError):
+            pass
+
+        return self.copyfile(src, dst)
+
     def copyfile(self,src,dst):
         try:
             return shutil.copyfile(src,dst)
-- 
1.5.3.1


-- 
Jack Neely <jjneely at ncsu.edu>
NCSU Campus Linux Services Lead
Office of Information Technology, NC State University
GPG Fingerprint: 1917 5AC1 E828 9337 7AA4  EA6B 213B 765F 3B6A 5B89




More information about the et-mgmt-tools mailing list