summaryrefslogtreecommitdiffstats
path: root/func/minion/modules/netapp/vol.py
blob: d0bb3d9a74ec8262a1ca67e153a466e66db51ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
##
## NetApp Filer 'Vol' Module
##
## Copyright 2007, Red Hat, Inc
## John Eckersberg <jeckersb@redhat.com>
##
## This software may be freely redistributed under the terms of the GNU
## general public license.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
##

import re
from func.minion.modules import func_module
from common import *

class Vol(func_module.FuncModule):

    # Update these if need be.
    version = "0.0.1"
    api_version = "0.0.1"
    description = "Interface to the 'vol' command"

    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, cmd_opts)
        return check_output(regex, output)
    
    def clone(self, filer, args):
        """
        TODO: Document me ...
        """
        pass

    def destroy(self, filer, args):
        """
        TODO: Document me ...
        """
        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):
        """
        TODO: Document me ...
        """
        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):
        """
        TODO: Document me ...
        """
        pass

    def size(self, filer, args):
        """
        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']]
        
        if len(args.keys()) == 1:
            output = ssh('root', filer, cmd_opts)
            check_output(stat_regex, output)
            return output.split()[-1][:-1]
        else:
            param_check(args, ['delta'])
            cmd_opts.append('%+d%s' % (int(args['delta'][:-1]), args['delta'][-1]))
            output = ssh('root', filer, cmd_opts)
            return check_output(resize_regex, output)

    def options(self, filer, args):
        """
        TODO: Document me ...
        """
        pass

    def rename(self, filer, args):
        """
        TODO: Document me ...
        """
        pass

    def restrict(self, filer, args):
        """
        TODO: Document me ...
        """
        pass

    def split(self, filer, args):
        """
        TODO: Document me ...
        """
        pass