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"