Very very very basic command line interface

This commit is contained in:
Joshua Boniface 2018-06-01 12:22:12 -04:00
parent c4595fd595
commit 7f87ac76fb
1 changed files with 27 additions and 1 deletions

28
pvc.py
View File

@ -1,6 +1,32 @@
#!/usr/bin/env python3
import kazoo.client, socket, time
from lxml import objectify
def help():
print("pvc - Parallel Virtual Cluster command-line utility")
help()
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')
try:
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()
except:
print('Failed to connect to local Zookeeper instance')
define_domain('/home/joshua/debsw1.xml')