4 ## Copyright 2007, Red Hat, Inc
5 ## John Eckersberg <jeckersb@redhat.com>
7 ## This software may be freely redistributed under the terms of the GNU
8 ## general public license.
10 ## You should have received a copy of the GNU General Public License
11 ## along with this program; if not, write to the Free Software
12 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 import sub_process
, os
19 class MountModule(func_module
.FuncModule
):
23 description
= "Mounting, unmounting and getting information on mounted filesystems."
26 cmd
= sub_process
.Popen(["/bin/cat", "/proc/mounts"], executable
="/bin/cat", stdout
=sub_process
.PIPE
, shell
=False)
27 data
= cmd
.communicate()[0]
30 lines
= [l
for l
in data
.split("\n") if l
] #why must you append blank crap?
35 curmount
['device'] = tokens
[0]
36 curmount
['dir'] = tokens
[1]
37 curmount
['type'] = tokens
[2]
38 curmount
['options'] = tokens
[3]
39 mounts
.append(curmount
)
43 def mount(self
, device
, dir, type="auto", options
=None, createdir
=False):
44 cmdline
= ["/bin/mount", "-t", type]
47 cmdline
.append(options
)
48 cmdline
.append(device
)
55 cmd
= sub_process
.Popen(cmdline
, executable
="/bin/mount", stdout
=sub_process
.PIPE
, shell
=False)
61 def umount(self
, dir, killall
=False, force
=False, lazy
=False):
62 # succeed if its not mounted
63 if not os
.path
.ismount(dir):
67 cmd
= sub_process
.Popen(["/sbin/fuser", "-mk", dir], executable
="/sbin/fuser", stdout
=sub_process
.PIPE
, shell
=False)
70 cmdline
= ["/bin/umount"]
77 cmd
= sub_process
.Popen(cmdline
, executable
="/bin/umount", stdout
=sub_process
.PIPE
, shell
=False)
83 def inventory(self
, flatten
=True):