From d316373e599dd397ba12414337442c9ee7c5398c Mon Sep 17 00:00:00 2001 From: John Eckersberg Date: Fri, 1 Feb 2008 17:44:29 -0500 Subject: get rid of all the fancy parameter packing and checking and just keep things simple. also implemented vol.status --- func/minion/modules/netapp/snap.py | 18 ++----- func/minion/modules/netapp/vol/__init__.py | 77 ++++++++++++++++-------------- func/minion/modules/netapp/vol/clone.py | 15 ++---- 3 files changed, 50 insertions(+), 60 deletions(-) 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..84c7ea1 100644 --- a/func/minion/modules/netapp/vol/__init__.py +++ b/func/minion/modules/netapp/vol/__init__.py @@ -23,82 +23,87 @@ 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]) + + if vol: + return [foo for foo in vols if foo['name'] == vol][0] + 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) -- cgit