-
Notifications
You must be signed in to change notification settings - Fork 2
/
cloudstack_checkssvmalive.py
72 lines (60 loc) · 2.01 KB
/
cloudstack_checkssvmalive.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
#!/usr/bin/python
from marvin.asyncJobMgr import asyncJobMgr
from marvin.codes import (FAILED, PASS, ADMIN, DOMAIN_ADMIN,
USER, SUCCESS, XEN_SERVER)
from marvin.dbConnection import DbConnection
from marvin.cloudstackAPI import *
from marvin.cloudstackAPI.cloudstackAPIClient import CloudStackAPIClient
from marvin.cloudstackException import CloudstackAPIException
from marvin.cloudstackException import GetDetailExceptionInfo
from marvin.cloudstackConnection import CSConnection
from marvin.configGenerator import ConfigManager
from marvin.lib.utils import (random_gen, validateList)
from CSUtils import *
import json
import time
import sys
utils = CSUtils()
conn = utils.getConnection()
apiclient = CloudStackAPIClient(conn)
listsvm = listSystemVms.listSystemVmsCmd()
count = 40
while count > 0 :
# Sleep 15 seconds
time.sleep(15)
count = count - 1
ssvm = None
# Check if we have an ssvm
print "Looking for systemvm of type secondarystoragevm"
try:
resp = apiclient.listSystemVms(listsvm)
if resp == None or len(resp) == 0 :
continue
for svm in resp:
if svm.systemvmtype == "secondarystoragevm":
if not svm.state == "Running" :
print "SSVM has state " + svm.state + " waiting for it to become Running"
else :
ssvm = svm
except urllib2.HTTPError, e:
print "Cmd Failed : " + str(e.msg)
if ssvm :
print "Found " + ssvm.name
print "Determining state"
listhosts = listHosts.listHostsCmd()
listhosts.name = ssvm.name
try:
resp = apiclient.listHosts(listhosts)
if not resp == None and len(resp) == 1 :
ssvmstate = resp[0]
else :
continue
except urllib2.HTTPError, e:
print "Cmd Failed : " + str(e.msg)
if ssvmstate.state == "Up":
print "SSVM " + ssvm.name + " is " + ssvm.state + " and the agent is " + ssvmstate.state
break
else :
print "SSVM Agent not yet Up, current state is " + ssvmstate.state
if count == 0 :
sys.exit(1)