#!/usr/bin/env python
import sys
import csha
import time
import subprocess

csha.log.debug('HA ha_propose_master')

timeout = 30

arg = ["/usr/libexec/xapi/cluster-stack/corosync/corosync_ha_master_lock.py"]
ha_master_lock_process = subprocess.Popen(arg)

sf = csha.Statefile()
host_uuid = csha.util.get_current_host_uuid()

for i in range(timeout):
    master = sf.get_master()
    if master.uuid == host_uuid:
        print "TRUE"
        sys.exit(0)
    else:
        time.sleep(1)

print "FALSE"
