Use a transaction for node creation
This commit is contained in:
parent
2ff531cc3c
commit
09113882ac
28
pvcd.py
28
pvcd.py
|
@ -183,21 +183,23 @@ if zk_conn.exists('/nodes/{}'.format(myhostname)):
|
||||||
else:
|
else:
|
||||||
print("Node is " + ansiiprint.red() + "absent" + ansiiprint.end() + " in Zookeeper; adding new node")
|
print("Node is " + ansiiprint.red() + "absent" + ansiiprint.end() + " in Zookeeper; adding new node")
|
||||||
keepalive_time = int(time.time())
|
keepalive_time = int(time.time())
|
||||||
zk_conn.create('/nodes/{}'.format(myhostname), 'hypervisor'.encode('ascii'))
|
transaction = zk_conn.transaction()
|
||||||
|
transaction.create('/nodes/{}'.format(myhostname), 'hypervisor'.encode('ascii'))
|
||||||
# Basic state information
|
# Basic state information
|
||||||
zk_conn.create('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii'))
|
transaction.create('/nodes/{}/daemonstate'.format(myhostname), 'stop'.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/domainstate'.format(myhostname), 'ready'.encode('ascii'))
|
transaction.create('/nodes/{}/domainstate'.format(myhostname), 'ready'.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/staticdata'.format(myhostname), ' '.join(staticdata).encode('ascii'))
|
transaction.create('/nodes/{}/staticdata'.format(myhostname), ' '.join(staticdata).encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/memfree'.format(myhostname), '0'.encode('ascii'))
|
transaction.create('/nodes/{}/memfree'.format(myhostname), '0'.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/memused'.format(myhostname), '0'.encode('ascii'))
|
transaction.create('/nodes/{}/memused'.format(myhostname), '0'.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/cpuload'.format(myhostname), '0.0'.encode('ascii'))
|
transaction.create('/nodes/{}/cpuload'.format(myhostname), '0.0'.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/runningdomains'.format(myhostname), ''.encode('ascii'))
|
transaction.create('/nodes/{}/runningdomains'.format(myhostname), ''.encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/domainscount'.format(myhostname), '0'.encode('ascii'))
|
transaction.create('/nodes/{}/domainscount'.format(myhostname), '0'.encode('ascii'))
|
||||||
# Keepalives and fencing information
|
# Keepalives and fencing information
|
||||||
zk_conn.create('/nodes/{}/keepalive'.format(myhostname), str(keepalive_time).encode('ascii'))
|
transaction.create('/nodes/{}/keepalive'.format(myhostname), str(keepalive_time).encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/ipmihostname'.format(myhostname), config['ipmi_hostname'].encode('ascii'))
|
transaction.create('/nodes/{}/ipmihostname'.format(myhostname), config['ipmi_hostname'].encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/ipmiusername'.format(myhostname), config['ipmi_username'].encode('ascii'))
|
transaction.create('/nodes/{}/ipmiusername'.format(myhostname), config['ipmi_username'].encode('ascii'))
|
||||||
zk_conn.create('/nodes/{}/ipmipassword'.format(myhostname), config['ipmi_password'].encode('ascii'))
|
transaction.create('/nodes/{}/ipmipassword'.format(myhostname), config['ipmi_password'].encode('ascii'))
|
||||||
|
transaction.commit()
|
||||||
|
|
||||||
zk_conn.set('/nodes/{}/daemonstate'.format(myhostname), 'init'.encode('ascii'))
|
zk_conn.set('/nodes/{}/daemonstate'.format(myhostname), 'init'.encode('ascii'))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue