2 ## NetApp Filer 'Vol' Module
4 ## Copyright 2008, Red Hat, Inc
5 ## John Eckersberg <jeckersb@redhat.com>
7 ## This software may be freely redistributed under the terms of the GNU
8 ## general public license.
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.
16 from func
.minion
.modules
import func_module
17 from func
.minion
.modules
.netapp
.common
import *
19 class Vol(func_module
.FuncModule
):
21 # Update these if need be.
24 description
= "Interface to the 'vol' command"
26 def create(self
, filer
, vol
, aggr
, size
):
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
)
35 def destroy(self
, filer
, vol
):
39 regex
= """Volume .* destroyed."""
40 cmd_opts
= ['vol', 'destroy', vol
, '-f']
41 output
= ssh(filer
, cmd_opts
)
42 return check_output(regex
, output
)
44 def offline(self
, filer
, vol
):
48 regex
= """Volume .* is now offline."""
49 cmd_opts
= ['vol', 'offline', vol
]
50 output
= ssh(filer
, cmd_opts
)
51 return check_output(regex
, output
)
53 def online(self
, filer
, vol
):
57 regex
= """Volume .* is now online."""
58 cmd_opts
= ['vol', 'online', vol
]
59 output
= ssh(filer
, cmd_opts
)
60 return check_output(regex
, output
)
62 def status(self
, filer
, vol
=None):
66 cmd_opts
= ['vol', 'status']
67 output
= ssh(filer
, cmd_opts
)
69 output
= output
.replace(',', ' ')
70 lines
= output
.split('\n')[1:]
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],
80 'status': [foo
for foo
in tokens
[2:] if '=' not in foo
],
81 'options': [foo
for foo
in tokens
[2:] if '=' in foo
]}
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
)
89 return [foo
for foo
in vols
if foo
['name'] == vol
][0]
91 raise NetappCommandError
, "No such volume: %s" % vol
95 def size(self
, filer
, vol
, delta
=None):
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
]
104 cmd_opts
.append(delta
)
105 output
= ssh(filer
, cmd_opts
)
106 return check_output(resize_regex
, output
)
108 output
= ssh(filer
, cmd_opts
)
109 check_output(stat_regex
, output
)
110 return output
.split()[-1][:-1]
112 def options(self
, filer
, args
):
114 TODO: Document me ...
118 def rename(self
, filer
, args
):
120 TODO: Document me ...
124 def restrict(self
, filer
, args
):
126 TODO: Document me ...