2018-05-31 20:26:44 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2018-06-01 12:22:12 -04:00
|
|
|
import kazoo.client, socket, time
|
|
|
|
from lxml import objectify
|
|
|
|
|
2018-05-31 20:26:44 -04:00
|
|
|
def help():
|
|
|
|
print("pvc - Parallel Virtual Cluster command-line utility")
|
|
|
|
|
2018-06-01 12:22:12 -04:00
|
|
|
def define_domain(domxmlfile):
|
|
|
|
with open(domxmlfile, 'r') as f_domxmlfile:
|
|
|
|
data = f_domxmlfile.read()
|
|
|
|
f_domxmlfile.close()
|
|
|
|
|
|
|
|
parsed_xml = objectify.fromstring(data)
|
|
|
|
domuuid = parsed_xml.uuid
|
|
|
|
print('Adding domain %s to database' % domuuid)
|
|
|
|
|
|
|
|
zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181')
|
2018-06-02 14:32:59 -04:00
|
|
|
zk.start()
|
|
|
|
transaction = zk.transaction()
|
|
|
|
transaction.create('/domains/%s' % domuuid, "".encode('ascii'))
|
|
|
|
transaction.create('/domains/%s/state' % domuuid, "stop".encode('ascii'))
|
|
|
|
transaction.create('/domains/%s/hypervisor' % domuuid, socket.gethostname().encode('ascii'))
|
|
|
|
transaction.create('/domains/%s/xml' % domuuid, data.encode('ascii'))
|
|
|
|
results = transaction.commit()
|
|
|
|
zk.stop()
|
|
|
|
zk.close()
|
2018-06-01 12:22:12 -04:00
|
|
|
|
2018-06-02 14:32:59 -04:00
|
|
|
def migrate_domain(domuuid, target):
|
|
|
|
zk = kazoo.client.KazooClient(hosts='127.0.0.1:2181')
|
|
|
|
zk.start()
|
|
|
|
transaction = zk.transaction()
|
|
|
|
# transaction.set_data('/domains/%s/state' % domuuid, 'migrate'.encode('ascii'))
|
|
|
|
transaction.set_data('/domains/%s/hypervisor' % domuuid, target.encode('ascii'))
|
|
|
|
results = transaction.commit()
|
|
|
|
zk.stop()
|
|
|
|
zk.close()
|
|
|
|
|
|
|
|
|
|
|
|
#define_domain('/var/home/joshua/debian9.xml')
|
2018-06-02 15:29:42 -04:00
|
|
|
#migrate_domain('b1dc4e21-544f-47aa-9bb7-8af0bc443b78', 'test1.i.bonilan.net')
|
|
|
|
migrate_domain('b1dc4e21-544f-47aa-9bb7-8af0bc443b78', 'test2.i.bonilan.net')
|