forked from DSI-Universite-Rennes2/hpeva
-
Notifications
You must be signed in to change notification settings - Fork 1
/
create
executable file
·109 lines (81 loc) · 3.08 KB
/
create
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Version : 0.1
# Author : [email protected] for KENET
# Derived from Uni Rennes 2 work
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
# Based on Ganeti EXtStorageProviders code (https://code.grnet.gr/projects/extstorage)
"""Create a new LUN
This program creates a new LUN inside a EMC Clariion
It takes its input from environment variables. Specifically the
following variables should be present:
- VOL_NAME : The UUID of the new Image file
- VOL_SIZE : The size of the new Image (in megabytes)
Return O after successfull creation, 1 on failure
"""
import os
import sys
import ConfigParser
sys.path.append("/usr/share/ganeti/default")
from ganeti import utils
#Config
#config_file = "/etc/ganeti/extstorage/clariion.conf"
config_file = "./clariion.conf.local"
config = ConfigParser.SafeConfigParser()
if not config.read(config_file):
raise ConfigParser.Error("Unable to read config file")
e_storage = config.get('clariion','storage')
e_poolname = config.get('clariion','poolname')
e_naviseccli_path = config.get('clariion','naviseccli_path')
e_sp = config.get('clariion','sp')
e_type = config.get('clariion','type')
def ReadEnv():
"""Read the mandatory enviromental variables
"""
if os.getenv("EXTP_NAME") is None :
name = os.getenv("VOL_NAME")
else :
name = os.getenv("EXTP_NAME")
if name is None:
sys.stderr.write('The environment variable VOL_NAME is missing.\n')
sys.exit(1)
# XXX we don't need to divide by 1024, since the size spec is in MB
size = str(int(os.getenv("VOL_SIZE")) // 1)
if size is None:
sys.stderr.write('The environment variable VOL_SIZE is missing.\n')
sys.exit(1)
return (name, size)
def main():
sys.stderr.write('Creation started...\n')
env = ReadEnv()
if env is None:
sys.stderr.write('Wrong environment. Aborting...\n')
sys.exit(1)
vd_name, vd_size = env
sys.stderr.write('name: %s, size: %s\n' % (vd_name, vd_size))
# Create VD
cmd = "%s -h %s lun -create -type %s -capacity %s -sq mb -sp %s -poolname %s -name %s" % (e_naviseccli_path, e_storage, e_type, vd_size, e_sp, e_poolname, vd_name)
# Debug output
# print(cmd)
result = utils.RunCmd(cmd)
if result.failed:
sys.stderr.write('VD creation failed (%s): %s\n' %
(result.fail_reason, result.output))
return 1
return 0
if __name__ == "__main__":
sys.exit(main())