summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorAdrian Likins <alikins@grimlock.devel.redhat.com>2008-02-04 14:19:42 -0500
committerAdrian Likins <alikins@grimlock.devel.redhat.com>2008-02-04 14:19:42 -0500
commit069bb8965e60e4a9461169748be841fbc5c7bcf6 (patch)
tree5e3608403c81b570890147d1974e3db71bf68437 /func
parent9efd48a2183c38776c3d3012b37c7e549351d881 (diff)
parentae4702fb3cddf93c5beb5b18c510c01becf13ceb (diff)
downloadfunc-069bb8965e60e4a9461169748be841fbc5c7bcf6.tar.gz
func-069bb8965e60e4a9461169748be841fbc5c7bcf6.tar.xz
func-069bb8965e60e4a9461169748be841fbc5c7bcf6.zip
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
Diffstat (limited to 'func')
-rw-r--r--func/minion/modules/netapp/common.py8
-rw-r--r--func/minion/modules/netapp/snap.py18
-rw-r--r--func/minion/modules/netapp/vol/__init__.py81
-rw-r--r--func/minion/modules/netapp/vol/clone.py15
4 files changed, 55 insertions, 67 deletions
diff --git a/func/minion/modules/netapp/common.py b/func/minion/modules/netapp/common.py
index ebe75ab..979c95c 100644
--- a/func/minion/modules/netapp/common.py
+++ b/func/minion/modules/netapp/common.py
@@ -20,7 +20,6 @@ SSH_USER = 'root'
SSH_OPTS = '-o forwardagent=no'
class GenericSSHError(Exception): pass
class NetappCommandError(Exception): pass
-class NetappMissingParam(Exception): pass
def ssh(host, cmdargs, input=None, user=SSH_USER):
cmdline = [SSH, SSH_OPTS, "%s@%s" % (user, host)]
@@ -34,17 +33,12 @@ def ssh(host, cmdargs, input=None, user=SSH_USER):
shell=False)
(out, err) = cmd.communicate(input)
-
+
if cmd.wait() != 0:
raise GenericSSHError, err
else:
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', ' ')
diff --git a/func/minion/modules/netapp/snap.py b/func/minion/modules/netapp/snap.py
index 08987b1..db94911 100644
--- a/func/minion/modules/netapp/snap.py
+++ b/func/minion/modules/netapp/snap.py
@@ -23,33 +23,25 @@ class Snap(func_module.FuncModule):
api_version = "0.0.1"
description = "Interface to the 'snap' command"
- def create(self, filer, args):
+ def create(self, filer, vol, snap):
"""
TODO: Document me ...
"""
regex = """creating snapshot..."""
- param_check(args, ['volname', 'snapname'])
-
- cmd_opts = ['snap', 'create']
- cmd_opts.extend([args['volname'], args['snapname']])
-
+ cmd_opts = ['snap', 'create', vol, snap]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def delete(self, filer, args):
+ def delete(self, filer, args, vol, snap):
"""
TODO: Document me ...
"""
regex = """deleting snapshot..."""
- param_check(args, ['volname', 'snapname'])
-
- cmd_opts = ['snap', 'delete']
- cmd_opts.extend([args['volname'], args['snapname']])
-
+ cmd_opts = ['snap', 'delete', vol, snap]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def list(self, filer, args):
+ def list(self, filer, vol):
"""
TODO: Document me ...
"""
diff --git a/func/minion/modules/netapp/vol/__init__.py b/func/minion/modules/netapp/vol/__init__.py
index 77ba28b..14ce0ac 100644
--- a/func/minion/modules/netapp/vol/__init__.py
+++ b/func/minion/modules/netapp/vol/__init__.py
@@ -23,82 +23,91 @@ 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, vol, aggr, size):
"""
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']])
-
+ cmd_opts = ['vol', 'create', vol, aggr, size]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def destroy(self, filer, args):
+ def destroy(self, filer, vol):
"""
TODO: Document me ...
"""
regex = """Volume .* destroyed."""
- param_check(args, ['name'])
-
- cmd_opts = ['vol', 'destroy']
- cmd_opts.extend([args['name']])
-
- output = ssh(filer, cmd_opts, 'y')
+ cmd_opts = ['vol', 'destroy', vol, '-f']
+ output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def offline(self, filer, args):
+ def offline(self, filer, vol):
"""
TODO: Document me ...
"""
regex = """Volume .* is now offline."""
- param_check(args, ['name'])
-
- cmd_opts = ['vol', 'offline']
- cmd_opts.extend([args['name']])
-
+ cmd_opts = ['vol', 'offline', vol]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def online(self, filer, args):
+ def online(self, filer, vol):
"""
TODO: Document me ...
"""
regex = """Volume .* is now online."""
- param_check(args, ['name'])
-
- cmd_opts = ['vol', 'online']
- cmd_opts.extend([args['name']])
-
+ cmd_opts = ['vol', 'online', vol]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def status(self, filer, args):
+ def status(self, filer, vol=None):
"""
TODO: Document me ...
"""
- pass
+ cmd_opts = ['vol', 'status']
+ output = ssh(filer, cmd_opts)
- def size(self, filer, args):
+ output = output.replace(',', ' ')
+ lines = output.split('\n')[1:]
+
+ vols = []
+ current_vol = {}
+ for line in lines:
+ tokens = line.split()
+ if len(tokens) >= 2 and tokens[1] in ('online', 'offline', 'restricted'):
+ if current_vol: vols.append(current_vol)
+ current_vol = {'name': tokens[0],
+ 'state': tokens[1],
+ 'status': [foo for foo in tokens[2:] if '=' not in foo],
+ 'options': [foo for foo in tokens[2:] if '=' in foo]}
+ else:
+ current_vol['status'].extend([foo for foo in tokens if '=' not in foo])
+ current_vol['options'].extend([foo for foo in tokens if '=' in foo])
+ vols.append(current_vol)
+
+ if vol:
+ try:
+ return [foo for foo in vols if foo['name'] == vol][0]
+ except:
+ raise NetappCommandError, "No such volume: %s" % vol
+ else:
+ return vols
+
+ def size(self, filer, vol, delta=None):
"""
TODO: Document me ...
"""
stat_regex = """vol size: Flexible volume .* has size .*."""
resize_regex = """vol size: Flexible volume .* size set to .*."""
- param_check(args, ['name'])
- cmd_opts = ['vol', 'size', args['name']]
+ cmd_opts = ['vol', 'size', vol]
- if len(args.keys()) == 1:
+ if delta:
+ cmd_opts.append(delta)
output = ssh(filer, cmd_opts)
- check_output(stat_regex, output)
- return output.split()[-1][:-1]
+ return check_output(resize_regex, output)
else:
- param_check(args, ['delta'])
- cmd_opts.append('%+d%s' % (int(args['delta'][:-1]), args['delta'][-1]))
output = ssh(filer, cmd_opts)
- return check_output(resize_regex, output)
+ check_output(stat_regex, output)
+ return output.split()[-1][:-1]
def options(self, filer, args):
"""
diff --git a/func/minion/modules/netapp/vol/clone.py b/func/minion/modules/netapp/vol/clone.py
index ab1071d..715d8a8 100644
--- a/func/minion/modules/netapp/vol/clone.py
+++ b/func/minion/modules/netapp/vol/clone.py
@@ -23,29 +23,22 @@ class Clone(func_module.FuncModule):
api_version = "0.0.1"
description = "Interface to the 'vol' command"
- def create(self, filer, args):
+ def create(self, filer, vol, parent, snap):
"""
TODO: Document me ...
"""
regex = """Creation of clone volume .* has completed."""
- param_check(args, ['name', 'parent', 'snapshot'])
-
- cmd_opts = ['vol', 'clone', 'create']
- cmd_opts.extend([args['name'], '-b', args['parent'], args['snapshot']])
-
+ cmd_opts = ['vol', 'clone', 'create', vol, '-b', parent, snap]
output = ssh(filer, cmd_opts)
return check_output(regex, output)
- def split(self, filer, args):
+ def split(self, filer, vol):
"""
TODO: Document me ...
"""
# only worry about 'start' now, I don't terribly care to automate the rest
regex = """Clone volume .* will be split from its parent."""
- param_check(args, ['name'])
-
- cmd_opts = ['vol', 'clone', 'split', 'start', args['name']]
-
+ cmd_opts = ['vol', 'clone', 'split', 'start', vol]
output = ssh(filer, cmd_opts)
return check_output(regex, output)