summaryrefslogtreecommitdiffstats
path: root/func/minion/modules
diff options
context:
space:
mode:
authorJohn Eckersberg <jeckersb@redhat.com>2008-01-25 18:09:13 -0500
committerJohn Eckersberg <jeckersb@redhat.com>2008-01-25 18:09:13 -0500
commit474d1ce38fa15ce693aaf694d7d7e5ab397f8b98 (patch)
tree381a861626c198efe2f98198b17b20903784da50 /func/minion/modules
parentcf67b63b2c1a794a36cbe6d3149ff9c535fb0f95 (diff)
downloadfunc-474d1ce38fa15ce693aaf694d7d7e5ab397f8b98.tar.gz
func-474d1ce38fa15ce693aaf694d7d7e5ab397f8b98.tar.xz
func-474d1ce38fa15ce693aaf694d7d7e5ab397f8b98.zip
it actually works!
under vol, we now have: create offline online destroy
Diffstat (limited to 'func/minion/modules')
-rw-r--r--func/minion/modules/netapp/common.py28
-rw-r--r--func/minion/modules/netapp/vol.py52
2 files changed, 64 insertions, 16 deletions
diff --git a/func/minion/modules/netapp/common.py b/func/minion/modules/netapp/common.py
index d041336..b76dbf6 100644
--- a/func/minion/modules/netapp/common.py
+++ b/func/minion/modules/netapp/common.py
@@ -1,21 +1,41 @@
+import re
import subprocess
SSH = '/usr/bin/ssh'
class GenericSSHError(Exception): pass
class NetappCommandError(Exception): pass
+class NetappMissingParam(Exception): pass
class NetappNotImplementedError(Exception): pass
-def ssh(user, host, command):
- cmd = subprocess.Popen([SSH, "%s@%s" % (user, host), command],
+def ssh(user, host, cmdargs, input=None):
+ cmdline = [SSH, "-o forwardagent=no", "%s@%s" % (user, host)]
+ cmdline.extend(cmdargs)
+
+ cmd = subprocess.Popen(cmdline,
executable=SSH,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False)
- (out, err) = cmd.communicate()
+ (out, err) = cmd.communicate(input)
+
if cmd.wait() != 0:
raise GenericSSHError, err
else:
- return out
+ return out + err
+
+def param_check(args, required):
+ for r in required:
+ if not args.has_key(r):
+ raise NetappMissingParam, r
+
+def check_output(regex, output):
+ #strip newlines
+ output = output.replace('\n', ' ')
+ if re.search(regex, output):
+ return True
+ else:
+ raise NetappCommandError, output
+
diff --git a/func/minion/modules/netapp/vol.py b/func/minion/modules/netapp/vol.py
index 4719d5a..cb8cc48 100644
--- a/func/minion/modules/netapp/vol.py
+++ b/func/minion/modules/netapp/vol.py
@@ -23,19 +23,20 @@ class Vol(func_module.FuncModule):
api_version = "0.0.1"
description = "Interface to the 'vol' command"
- def create(self, filer, *args):
+ def create(self, filer, args):
"""
TODO: Document me ...
"""
regex = """Creation of volume .* has completed."""
+ param_check(args, ['name', 'aggr', 'size'])
+
+ cmd_opts = ['vol', 'create']
+ cmd_opts.extend([args['name'], args['aggr'], args['size']])
- output = ssh('root', filer, ' '.join(args))
- if re.search(regex, output):
- return True
- else:
- raise NetappCommandError, output
-
- def clone(self, filer, *args):
+ output = ssh('root', filer, cmd_opts)
+ return check_output(regex, output)
+
+ def clone(self, filer, args):
"""
TODO: Document me ...
"""
@@ -58,17 +59,44 @@ class Vol(func_module.FuncModule):
else:
raise NetappCommandError, output
- def destroy(self, filer, *args):
+ def destroy(self, filer, args):
"""
TODO: Document me ...
"""
- pass
+ regex = """Volume .* destroyed."""
+ param_check(args, ['name'])
+
+ cmd_opts = ['vol', 'destroy']
+ cmd_opts.extend([args['name']])
+
+ output = ssh('root', filer, cmd_opts, 'y')
+ return check_output(regex, output)
- def offline(self, filer, *args):
+ def offline(self, filer, args):
"""
TODO: Document me ...
"""
- pass
+ regex = """Volume .* is now offline."""
+ param_check(args, ['name'])
+
+ cmd_opts = ['vol', 'offline']
+ cmd_opts.extend([args['name']])
+
+ output = ssh('root', filer, cmd_opts)
+ return check_output(regex, output)
+
+ def online(self, filer, args):
+ """
+ TODO: Document me ...
+ """
+ regex = """Volume .* is now online."""
+ param_check(args, ['name'])
+
+ cmd_opts = ['vol', 'online']
+ cmd_opts.extend([args['name']])
+
+ output = ssh('root', filer, cmd_opts)
+ return check_output(regex, output)
def status(self, filer, *args):
"""