-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrestartMgmt.py
36 lines (31 loc) · 1.11 KB
/
restartMgmt.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
from ConfigParser import ConfigParser
from optparse import OptionParser
import marvin
from marvin import configGenerator
from marvin import sshClient
from time import sleep as delay
import telnetlib
import socket
if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-c", "--config", action="store", default="xen.cfg",
dest="config", help="the path where the server configurations is stored")
(options, args) = parser.parse_args()
if options.config is None:
raise
cscfg = configGenerator.getSetupConfig(options.config)
mgmt_server = cscfg.mgtSvr[0].mgtSvrIp
ssh = sshClient.SshClient(mgmt_server, 22, "root", "password")
ssh.execute("service cloudstack-management stop;service cloudstack-management start")
#Telnet wait until api port is open
tn = None
timeout = 120
while timeout > 0:
try:
tn = telnetlib.Telnet(mgmt_server, 8096, timeout=120)
break
except Exception:
delay(1)
timeout = timeout - 1
if tn is None:
raise socket.error("Unable to reach API port")