root / rbd / create @ master
History | View | Annotate | Download (2.6 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 |
"""Create a new rbd Image inside a RADOS cluster |
21 |
|
22 |
This program creates a new rbd Image file inside 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 new Image file |
27 |
- POOL: The RADOS pool in which to put the Image |
28 |
- VOL_SIZE: The size of the new Image (in megabytes) |
29 |
|
30 |
Returns O after successfull creation, 1 on failure |
31 |
|
32 |
""" |
33 |
|
34 |
import os |
35 |
import sys |
36 |
|
37 |
sys.path.insert(0, "/etc/ganeti/share") |
38 |
|
39 |
from ganeti import utils |
40 |
|
41 |
|
42 |
def ReadEnv(): |
43 |
"""Read the mandatory enviromental variables |
44 |
|
45 |
""" |
46 |
name = os.getenv("VOL_NAME") |
47 |
if name is None: |
48 |
sys.stderr.write('The environment variable VOL_NAME is missing.\n') |
49 |
sys.exit(1) |
50 |
# pool = os.getenv("POOL") |
51 |
pool = "rbd" |
52 |
if pool is None: |
53 |
sys.stderr.write('The environment variable POOL is missing.\n') |
54 |
sys.exit(1) |
55 |
size = os.getenv("VOL_SIZE") |
56 |
if size is None: |
57 |
sys.stderr.write('The environment variable VOL_SIZE is missing.\n') |
58 |
sys.exit(1) |
59 |
test_param = os.getenv("EXTP_TEST") |
60 |
if test_param: |
61 |
sys.stderr.write('parameter test = %s\n' % test_param) |
62 |
|
63 |
|
64 |
return (name, pool, size) |
65 |
|
66 |
|
67 |
def main(): |
68 |
sys.stderr.write('Creation started...\n') |
69 |
env = ReadEnv() |
70 |
if env is None: |
71 |
sys.stderr.write('Wrong environment. Aborting...\n') |
72 |
sys.exit(1) |
73 |
|
74 |
rbd_name, rbd_pool, size = env |
75 |
|
76 |
sys.stderr.write('name: %s, pool: %s, size: %s\n' % (rbd_name, rbd_pool, size)) |
77 |
cmd = ["rbd", "create", "-p", "%s" % rbd_pool, |
78 |
"%s" % rbd_name, "--size", "%s" % size] |
79 |
sys.stderr.write('Before RunCmd') |
80 |
result = utils.RunCmd(cmd) |
81 |
sys.stderr.write('After RunCmd') |
82 |
if result.failed: |
83 |
sys.stderr.write('rbd creation failed (%s): %s\n' % |
84 |
(result.fail_reason, result.output)) |
85 |
sys.exit(1) |
86 |
|
87 |
sys.exit(0) |
88 |
|
89 |
|
90 |
if __name__ == "__main__": |
91 |
sys.exit(main()) |