-
Notifications
You must be signed in to change notification settings - Fork 4
/
detach
executable file
·117 lines (89 loc) · 3.74 KB
/
detach
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
110
111
112
113
114
115
116
117
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Version : 0.1
# Author : Sylvain Costard <at> univ-rennes2.fr
# Université Rennes 2
#
# 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)
"""Detach an existing EVA VD
This program detahc an existing Image to a block device
- VOL_NAME : UUID of the Image to map
- EXTP_NAME : VD_NAME
Returns the block device path (which maps the Image) as a string
upon success, or 1 upon failure
"""
import os
import sys
import ConfigParser
sys.path.append("/usr/share/ganeti/default")
from ganeti import utils
# Config
config_file = "/etc/ganeti/extstorage/eva.conf"
config = ConfigParser.SafeConfigParser()
if not config.read(config_file):
raise ConfigParser.Error("Unable to read config file")
manap = config.get('eva','manap')
login = config.get('eva','login')
password = config.get('eva','password')
array = config.get('eva','array')
cluiclient_path = config.get('eva','cluiclient_path')
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)
return (name)
def main():
sys.stderr.write('Depresent %s ...\n' % os.getenv("VOL_NAME"))
env = ReadEnv()
if env is None:
sys.stderr.write('Wrong environment. Aborting...\n')
sys.exit(1)
vd_name = env
sys.stderr.write('name: %s\n' % (vd_name))
#Get VD uuid
cmd = "%s/sbin/clui.sh -c -u %s -p %s -h %s -s %s sho vd %s | awk -F ',' '{print tolower($4)}' | grep -v 'WW Lun Name' | grep - | sed 's/-//g'" % (cluiclient_path,login,password,manap,array,vd_name)
result = utils.RunCmd(cmd)
uuid = result.output
#Get multipath device
cmd = "multipath -ll 3%s | head -1 | awk '{print $1}'" % uuid.strip()
result = utils.RunCmd(cmd)
device = result.output
#Remove device
cmd = "multipath -f %s" % device
result = utils.RunCmd(cmd)
#Depresent
dom0 = utils.RunCmd("hostname | sed 's/^./\u&/;'")
cmd = ["%s/sbin/clui.sh" % cluiclient_path , "-c", "-u", "%s" % login, "-p", "%s" % password, "-h", "%s" % manap, "-s", "%s" % array, "set vd %s rp=%s" % (vd_name,dom0.output.strip())]
result = utils.RunCmd(cmd)
if result.failed:
sys.stderr.write('VD unmap failed (%s): %s\n' %
(result.fail_reason, result.output))
return
#clean PV from sd devices
utils.RunCmd("for i in `pvs 2>&1 | grep 'read failed' | awk '{print $1}' | sed 's/://' | sed 's/\/dev\///' | uniq` ; do echo 1 > /sys/block/$i/device/delete; done")
#result = utils.RunCmd('ls -d /sys/class/fc_host/host*/issue_lip | xargs -i echo "echo 1 > {}" | sh')
#device = utils.RunCmd("((pvs | grep mpath | awk '{print $1}' | sed 's#/dev/mapper/##' | sed 's/-part1//')&& (multipath -l | grep mpath | awk '{print $1}')) | sort | uniq -u")
#sys.stdout.write("/dev/mapper/%s" % device.output.strip())
sys.exit(0)
if __name__ == "__main__":
sys.exit(main())