Misc s/func/certmaster/ replacements
[certmaster.git] / certmaster / minion / modules / netapp / vol / __init__.py
1 ##
2 ## NetApp Filer 'Vol' Module
3 ##
4 ## Copyright 2008, Red Hat, Inc
5 ## John Eckersberg <jeckersb@redhat.com>
6 ##
7 ## This software may be freely redistributed under the terms of the GNU
8 ## general public license.
9 ##
10 ## You should have received a copy of the GNU General Public License
11 ## along with this program; if not, write to the Free Software
12 ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 ##
14
15 import re
16 from func.minion.modules import func_module
17 from func.minion.modules.netapp.common import *
18
19 class Vol(func_module.FuncModule):
20
21 # Update these if need be.
22 version = "0.0.1"
23 api_version = "0.0.1"
24 description = "Interface to the 'vol' command"
25
26 def create(self, filer, vol, aggr, size):
27 """
28 TODO: Document me ...
29 """
30 regex = """Creation of volume .* has completed."""
31 cmd_opts = ['vol', 'create', vol, aggr, size]
32 output = ssh(filer, cmd_opts)
33 return check_output(regex, output)
34
35 def destroy(self, filer, vol):
36 """
37 TODO: Document me ...
38 """
39 regex = """Volume .* destroyed."""
40 cmd_opts = ['vol', 'destroy', vol, '-f']
41 output = ssh(filer, cmd_opts)
42 return check_output(regex, output)
43
44 def offline(self, filer, vol):
45 """
46 TODO: Document me ...
47 """
48 regex = """Volume .* is now offline."""
49 cmd_opts = ['vol', 'offline', vol]
50 output = ssh(filer, cmd_opts)
51 return check_output(regex, output)
52
53 def online(self, filer, vol):
54 """
55 TODO: Document me ...
56 """
57 regex = """Volume .* is now online."""
58 cmd_opts = ['vol', 'online', vol]
59 output = ssh(filer, cmd_opts)
60 return check_output(regex, output)
61
62 def status(self, filer, vol=None):
63 """
64 TODO: Document me ...
65 """
66 cmd_opts = ['vol', 'status']
67 output = ssh(filer, cmd_opts)
68
69 output = output.replace(',', ' ')
70 lines = output.split('\n')[1:]
71
72 vols = []
73 current_vol = {}
74 for line in lines:
75 tokens = line.split()
76 if len(tokens) >= 2 and tokens[1] in ('online', 'offline', 'restricted'):
77 if current_vol: vols.append(current_vol)
78 current_vol = {'name': tokens[0],
79 'state': tokens[1],
80 'status': [foo for foo in tokens[2:] if '=' not in foo],
81 'options': [foo for foo in tokens[2:] if '=' in foo]}
82 else:
83 current_vol['status'].extend([foo for foo in tokens if '=' not in foo])
84 current_vol['options'].extend([foo for foo in tokens if '=' in foo])
85 vols.append(current_vol)
86
87 if vol:
88 try:
89 return [foo for foo in vols if foo['name'] == vol][0]
90 except:
91 raise NetappCommandError, "No such volume: %s" % vol
92 else:
93 return vols
94
95 def size(self, filer, vol, delta=None):
96 """
97 TODO: Document me ...
98 """
99 stat_regex = """vol size: Flexible volume .* has size .*."""
100 resize_regex = """vol size: Flexible volume .* size set to .*."""
101 cmd_opts = ['vol', 'size', vol]
102
103 if delta:
104 cmd_opts.append(delta)
105 output = ssh(filer, cmd_opts)
106 return check_output(resize_regex, output)
107 else:
108 output = ssh(filer, cmd_opts)
109 check_output(stat_regex, output)
110 return output.split()[-1][:-1]
111
112 def options(self, filer, args):
113 """
114 TODO: Document me ...
115 """
116 pass
117
118 def rename(self, filer, args):
119 """
120 TODO: Document me ...
121 """
122 pass
123
124 def restrict(self, filer, args):
125 """
126 TODO: Document me ...
127 """
128 pass