summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2009-02-05 20:31:54 -0600
committerJames Cammarata <jimi@sngx.net>2009-02-05 20:31:54 -0600
commit54e462f3dca472d8bb8dc8a2b0a69c60ed9fe2ec (patch)
tree411162d6f35ec25f018ac093339a61049e9af264
parentaf7539b64e7a75e283b4321a3a64d94318bfcf01 (diff)
downloadcobbler-54e462f3dca472d8bb8dc8a2b0a69c60ed9fe2ec.tar.gz
cobbler-54e462f3dca472d8bb8dc8a2b0a69c60ed9fe2ec.tar.xz
cobbler-54e462f3dca472d8bb8dc8a2b0a69c60ed9fe2ec.zip
Added functions
-rw-r--r--cobbler/utils.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/cobbler/utils.py b/cobbler/utils.py
index d39378c1..23794a83 100644
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -930,6 +930,8 @@ def bindmount(src,dst):
except:
if not os.access(src,os.R_OK):
raise CX(_("Cannot read: %s") % src)
+ if not os.access(dst,os.R_OK):
+ raise CX(_("Cannot read: %s") % dst)
if not os.path.samefile(src,dst):
# accomodate for the possibility that we already copied
# the file as a symlink/hardlink
@@ -937,6 +939,49 @@ def bindmount(src,dst):
# traceback.print_exc()
# raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst})
+def check_openfiles(src):
+ """
+ Used to check for open files on a mounted partition.
+ """
+ try:
+ if not os.path.isdir(src):
+ raise CX(_("Error in check_openfiles: the source (%s) must be a directory") % src)
+ cmd = [ "/usr/sbin/lsof", "+D", src, "-Fn", "|", "wc", "-l" ]
+ handle = sub_process.Popen(cmd, shell=True, stdout=sub_process.PIPE, close_fds=True)
+ out = handle.stdout
+ results = out.read()
+ return int(results)
+ except:
+ if not os.access(src,os.R_OK):
+ raise CX(_("Cannot read: %s") % src)
+ if not os.path.samefile(src,dst):
+ # accomodate for the possibility that we already copied
+ # the file as a symlink/hardlink
+ raise
+ # traceback.print_exc()
+ # raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst})
+
+def umount(src):
+ """
+ Used for unmounting things created by bindmount
+ """
+ try:
+ if not os.path.isdir(src):
+ raise CX(_("Error in umount: the source (%s) must be a directory") % src)
+ cmd = [ "/bin/umount", "--force", src ]
+ rc = sub_process.call(cmd, shell=False, close_fds=True)
+ return rc
+ except:
+ if not os.access(src,os.R_OK):
+ raise CX(_("Cannot read: %s") % src)
+ if not os.path.samefile(src,dst):
+ # accomodate for the possibility that we already copied
+ # the file as a symlink/hardlink
+ raise
+ # traceback.print_exc()
+ # raise CX(_("Error bind-mounting %(src)s to %(dst)s") % { "src" : src, "dst" : dst})
+
+
def copyfile_pattern(pattern,dst,require_match=True,symlink_ok=False,api=None):
files = glob.glob(pattern)
if require_match and not len(files) > 0: