root / rbd / remove @ 35acd6c9
History | View | Annotate | Download (2.1 kB)
1 |
#!/usr/bin/env python |
---|---|
2 |
# |
3 |
# Copyright (C) 2011 Greek Research and Technology Network |
4 |
# |
5 |
# This program is free software; you can redistribute it and/or modify |
6 |
# it under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 2 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# This program is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 |
# General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with this program; if not, write to the Free Software |
17 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 |
# 02110-1301, USA. |
19 |
|
20 |
"""Remove an existing rbd Image from a RADOS cluster |
21 |
|
22 |
This program removes an rbd Image file from a RADOS cluster. |
23 |
It takes it's input from environment variables. Specifically the |
24 |
following variables should be present: |
25 |
|
26 |
- VOL_NAME: The name of the Image file to remove |
27 |
- POOL: The RADOS pool in which the Image resides |
28 |
|
29 |
Returns O upon successfull removal, 1 upon failure |
30 |
|
31 |
""" |
32 |
|
33 |
import os |
34 |
import sys |
35 |
|
36 |
sys.path.append("/usr/share/ganeti") |
37 |
|
38 |
from ganeti import utils |
39 |
|
40 |
|
41 |
def ReadEnv(): |
42 |
"""Read the mandatory enviromental variables |
43 |
|
44 |
""" |
45 |
name = os.getenv("VOL_NAME") |
46 |
if name is None: |
47 |
sys.stderr.write('The environment variable VOL_NAME is missing.\n') |
48 |
return None |
49 |
# pool = os.getenv("POOL") |
50 |
pool = "rbd" |
51 |
if pool is None: |
52 |
sys.stderr.write('The environment variable POOL is missing.\n') |
53 |
return None |
54 |
|
55 |
return (name, pool) |
56 |
|
57 |
|
58 |
def main(): |
59 |
env = ReadEnv() |
60 |
if env is None: |
61 |
sys.stderr.write('Wrong environment. Aborting...\n') |
62 |
return 1 |
63 |
|
64 |
rbd_name, rbd_pool = env |
65 |
|
66 |
cmd = ["rbd", "rm", "-p", "%s" % rbd_pool, "%s" % rbd_name] |
67 |
result = utils.RunCmd(cmd) |
68 |
if result.failed: |
69 |
sys.stderr.write("Can't remove Image %s from cluster with rbd rm: " |
70 |
"%s - %s" % |
71 |
(rbd_name, result.fail_reason, result.output)) |
72 |
return 1 |
73 |
|
74 |
return 0 |
75 |
|
76 |
|
77 |
if __name__ == "__main__": |
78 |
sys.exit(main()) |