summaryrefslogtreecommitdiffstats
path: root/func/minion/modules/mount.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-12-17 11:48:37 -0500
committerMichael DeHaan <mdehaan@redhat.com>2007-12-17 11:48:37 -0500
commit169e4f8e7466e0144d05489a8a53a54180e654f9 (patch)
treee3778c985946a28193bb38b21be9e36b6d82b998 /func/minion/modules/mount.py
parentf5fe02b311193e4c03ce57e706ae668192cb501e (diff)
downloadthird_party-func-169e4f8e7466e0144d05489a8a53a54180e654f9.tar.gz
third_party-func-169e4f8e7466e0144d05489a8a53a54180e654f9.tar.xz
third_party-func-169e4f8e7466e0144d05489a8a53a54180e654f9.zip
Check in John Eckersberg's new mount module.
Diffstat (limited to 'func/minion/modules/mount.py')
-rw-r--r--func/minion/modules/mount.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/func/minion/modules/mount.py b/func/minion/modules/mount.py
new file mode 100644
index 0000000..bbaf7c7
--- /dev/null
+++ b/func/minion/modules/mount.py
@@ -0,0 +1,84 @@
+#!/usr/bin/python
+
+##
+## Mount manager
+##
+## Copyright 2007, Red Hat, Inc
+## John Eckersberg <jeckersb@redhat.com>
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+
+import sub_process, os.path
+from modules import func_module
+
+
+class MountModule(func_module.FuncModule):
+ def __init__(self):
+ self.methods = {
+ "list": self.list,
+ "mount": self.mount,
+ "umount": self.umount
+ }
+ func_module.FuncModule.__init__(self)
+
+ def list(self):
+ cmd = sub_process.Popen(["/bin/cat", "/proc/mounts"], executable="/bin/cat", stdout=sub_process.PIPE, shell=False)
+ data = cmd.communicate()[0]
+
+ mounts = []
+ lines = [l for l in data.split("\n") if l] #why must you append blank crap?
+
+ for line in lines:
+ curmount = {}
+ tokens = line.split()
+ curmount['device'] = tokens[0]
+ curmount['dir'] = tokens[1]
+ curmount['type'] = tokens[2]
+ curmount['options'] = tokens[3]
+ mounts.append(curmount)
+
+ return mounts
+
+ def mount(self, device, dir, type="auto", options=None, createdir=False):
+ cmdline = ["/bin/mount", "-t", type]
+ if options:
+ cmdline.append("-o")
+ cmdline.append(options)
+ cmdline.append(device)
+ cmdline.append(dir)
+ cmd = sub_process.Popen(cmdline, executable="/bin/mount", stdout=sub_process.PIPE, shell=False)
+ if cmd.wait() == 0:
+ return True
+ else:
+ return False
+
+ def umount(self, dir, killall=False, force=False, lazy=False):
+ # succeed if its not mounted
+ if not os.path.ismount(dir):
+ return True
+
+ if killall:
+ cmd = sub_process.Popen(["/sbin/fuser", "-mk", dir], executable="/sbin/fuser", stdout=sub_process.PIPE, shell=False)
+ cmd.wait()
+
+ cmdline = ["/bin/umount"]
+ if force:
+ cmdline.append("-f")
+ if lazy:
+ cmdline.append("-l")
+ cmdline.append(dir)
+
+ cmd = sub_process.Popen(cmdline, executable="/bin/umount", stdout=sub_process.PIPE, shell=False)
+ if cmd.wait() == 0:
+ return True
+ else:
+ return False
+
+methods = MountModule()
+register_rpc = methods.register_rpc