This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
forked from kmova/zfs-utilities
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_patch_steps.py
116 lines (103 loc) · 3.86 KB
/
generate_patch_steps.py
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
#!/usr/local/bin/python
import eventlet
eventlet.monkey_patch()
import os
import sys
#If ../cloudbyte/__init__.py exists, add ../ to Python search path, so that
# it will override what happens to be installed in /usr/(local/)lib/python...
POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
os.pardir,
os.pardir))
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cloudbyte', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)
from cloudbyte import flags
from cloudbyte import log as logging
from cloudbyte import utils
from cloudbyte import hautils
from cloudbyte import cbcutils
LOG = None
def getListOfVsms():
vsmConfigList = None
vsms = []
haPools = hautils.getAllPools()
for haPool in haPools:
vsmConfigList = hautils.getListTSMElementsByPoolElement(haPool)
for vsmConfig in vsmConfigList:
vsm = {}
vsm['uuid'] = vsmConfig['uuid']
vsm['fibid'] = vsmConfig['fibid']
vsm['jid'] = cbcutils.getJailIdByUuid(vsmConfig['uuid'])
vsms.append(vsm)
return vsms
def generatePatchSteps(vsms):
patchDir = "/cbdir/patch_1098_iscsi/"
patchScript = patchDir+"patch_steps.sh"
newLine = "\n"
with open(patchScript, "w") as f:
entry = "#!/bin/sh"+newLine
f.write(entry)
for vsm in vsms:
entry = "jexec "+str(vsm['jid'])+" service istgt onestatus"+newLine
f.write(entry)
entry = "sleep 1"+newLine
f.write(entry)
entry = "connbefore=`jexec "+str(vsm['jid'])+" netstat -an | grep 3260 | grep EST | wc -l`"+newLine
f.write(entry)
entry = "sleep 1"+newLine
f.write(entry)
entry = "jexec "+str(vsm['jid'])+" service istgt onestop"+newLine
f.write(entry)
entry = "/bin/cp istgt /tenants/"+vsm['uuid'].replace("-","")+"/usr/local/bin/istgt"+newLine
f.write(entry)
entry = "/bin/cp istgtcontrol /tenants/"+vsm['uuid'].replace("-","")+"/usr/local/bin/istgtcontrol"+newLine
f.write(entry)
entry = "jexec "+str(vsm['jid'])+" setfib "+str(vsm['fibid'])+" service istgt onestart"+newLine
f.write(entry)
entry = "sleep 1"+newLine
f.write(entry)
entry = "md5sum /tenants/"+vsm['uuid'].replace("-","")+"/usr/local/bin/istgt"+newLine
f.write(entry)
entry = "md5sum /tenants/"+vsm['uuid'].replace("-","")+"/usr/local/bin/istgtcontrol"+newLine
f.write(entry)
entry = "sleep 5"+newLine
f.write(entry)
entry = "jexec "+str(vsm['jid'])+" service istgt onestatus"+newLine
f.write(entry)
entry = "sleep 1"+newLine
f.write(entry)
entry = "connafter=`jexec "+str(vsm['jid'])+" netstat -an | grep 3260 | grep EST | wc -l`"+newLine
f.write(entry)
entry = "sleep 1"+newLine
f.write(entry)
entry = "echo $connbefore $connafter"+newLine
f.write(entry)
entry = "echo \"\""+newLine
f.write(entry)
entry = "sleep 10"+newLine+newLine
f.write(entry)
entry = "/bin/cp tsmutils.py /usr/local/agent/cloudbyte/tsmutils.py"+newLine
f.write(entry)
entry = "service cbc_storageconfiguration onerestart"+newLine
f.write(entry)
entry = "sleep 3"+newLine
f.write(entry)
entry = "service cbc_storageconfiguration onestatus"+newLine
f.write(entry)
return 0
if __name__ == '__main__':
utils.default_flagfile()
flags.FLAGS(sys.argv)
#Set rabbit retries to 3. Default is 0, which will try infinitely for connecting rabbitmq server.
flags.FLAGS.rabbit_max_retries = 3
LOG_DIR = flags.FLAGS.logdir
flags.FLAGS.logfile = 'generate_patch_steps.log'
if not os.path.exists(LOG_DIR):
os.mkdir(LOG_DIR)
logging.setup()
utils.monkey_patch()
LOG = logging.getLogger("cloudbyte.generate_patch_steps")
LOG.info(_("Generating patch steps..."))
# Get list of VSMs and their fibids.
vsms = getListOfVsms()
# Generate patch_steps.sh
generatePatchSteps(vsms)