$OpenBSD: patch-salt_modules_mount_py,v 1.6 2015/02/13 07:03:44 ajacoutot Exp $

https://github.com/saltstack/salt/commit/7edae80cce6e34c36ac8f5572aaa011e8ed527ba

--- salt/modules/mount.py.orig	Thu Feb 12 18:55:39 2015
+++ salt/modules/mount.py	Fri Feb 13 07:49:14 2015
@@ -124,6 +124,24 @@ def _active_mounts_solaris(ret):
     return ret
 
 
+def _active_mounts_openbsd(ret):
+    '''
+    List active mounts on OpenBSD systems
+    '''
+    for line in __salt__['cmd.run_stdout']('mount -v').split('\n'):
+        comps = re.sub(r"\s+", " ", line).split()
+        nod = __salt__['cmd.run_stdout']('ls -l {0}'.format(comps[0]))
+        nod = ' '.join(nod.split()).split(" ")
+        parens = re.findall(r'\((.*?)\)', line, re.DOTALL)
+        ret[comps[3]] = {'device': comps[0],
+                         'fstype': comps[5],
+                         'opts': parens[1].split(", "),
+                         'major': str(nod[4].strip(",")),
+                         'minor': str(nod[5]),
+                         'device_uuid': parens[0]}
+    return ret
+
+
 def active(extended=False):
     '''
     List the active mounts.
@@ -139,6 +157,8 @@ def active(extended=False):
         _active_mounts_freebsd(ret)
     elif __grains__['os'] == 'Solaris':
         _active_mounts_solaris(ret)
+    if __grains__['os'] == 'OpenBSD':
+        _active_mounts_openbsd(ret)
     else:
         if extended:
             try:
@@ -396,13 +416,16 @@ def remount(name, device, mkmnt=False, fstype='', opts
     mnts = active()
     if name in mnts:
         # The mount point is mounted, attempt to remount it with the given data
-        if 'remount' not in opts:
+        if 'remount' not in opts and __grains__['os'] != 'OpenBSD':
             opts.append('remount')
         lopts = ','.join(opts)
         args = '-o {0}'.format(lopts)
         if fstype:
             args += ' -t {0}'.format(fstype)
-        cmd = 'mount {0} {1} {2} '.format(args, device, name)
+        if __grains__['os'] != 'OpenBSD':
+            cmd = 'mount {0} {1} {2} '.format(args, device, name)
+        else:
+            cmd = 'mount -u {0} {1} {2} '.format(args, device, name)
         out = __salt__['cmd.run_all'](cmd, python_shell=False)
         if out['retcode']:
             return out['stderr']
@@ -465,15 +488,28 @@ def swaps():
         salt '*' mount.swaps
     '''
     ret = {}
-    with salt.utils.fopen('/proc/swaps') as fp_:
-        for line in fp_:
-            if line.startswith('Filename'):
+    if __grains__['os'] != 'OpenBSD':
+        with salt.utils.fopen('/proc/swaps') as fp_:
+            for line in fp_:
+               if line.startswith('Filename'):
+                  continue
+               comps = line.split()
+               ret[comps[0]] = {'type': comps[1],
+                                'size': comps[2],
+                                'used': comps[3],
+                                'priority': comps[4]}
+    else:
+        for line in __salt__['cmd.run_stdout']('swapctl -kl').splitlines():
+            type = "file"
+            if line.startswith(('Device', 'Total')):
                 continue
             comps = line.split()
-            ret[comps[0]] = {'type': comps[1],
-                             'size': comps[2],
-                             'used': comps[3],
-                             'priority': comps[4]}
+            if comps[0].startswith('/dev/'):
+                type = "partition"
+            ret[comps[0]] = {'type': type,
+                             'size': comps[1],
+                             'used': comps[2],
+                             'priority': comps[5]}
     return ret
 
 
@@ -517,7 +553,10 @@ def swapoff(name):
     '''
     on_ = swaps()
     if name in on_:
-        __salt__['cmd.run']('swapoff {0}'.format(name), python_shell=False)
+        if __grains__['os'] != 'OpenBSD':
+            __salt__['cmd.run']('swapoff {0}'.format(name), python_shell=False)
+        else:
+            __salt__['cmd.run']('swapctl -d {0}'.format(name), python_shell=False)
         on_ = swaps()
         if name in on_:
             return False
