diff --git a/pvc.py b/pvc.py index 4b4b3ffe..eaae4a20 100755 --- a/pvc.py +++ b/pvc.py @@ -467,6 +467,11 @@ def search(dom_name, dom_uuid, long_output): dom_name = pvcf.searchClusterByUUID(zk, dom_uuid) information = pvcf.getInformationFromXML(zk, dom_uuid, long_output) + + if information == None: + click.echo('Could not find a domain matching that name or UUID.') + return + click.echo(information) pvcf.stopZKConnection(zk) diff --git a/pvcf.py b/pvcf.py index 36ccc3e3..49dd17bd 100644 --- a/pvcf.py +++ b/pvcf.py @@ -67,10 +67,14 @@ def stopZKConnection(zk): # def getInformationFromXML(zk, uuid, long_output): # Obtain the contents of the XML from Zookeeper - xml = zk.get('/domains/%s/xml' % uuid)[0].decode('ascii') - dstate = zk.get('/domains/%s/state' % uuid)[0].decode('ascii') - dhypervisor = zk.get('/domains/%s/hypervisor' % uuid)[0].decode('ascii') - dlasthypervisor = zk.get('/domains/%s/lasthypervisor' % uuid)[0].decode('ascii') + try: + xml = zk.get('/domains/%s/xml' % uuid)[0].decode('ascii') + dstate = zk.get('/domains/%s/state' % uuid)[0].decode('ascii') + dhypervisor = zk.get('/domains/%s/hypervisor' % uuid)[0].decode('ascii') + dlasthypervisor = zk.get('/domains/%s/lasthypervisor' % uuid)[0].decode('ascii') + except: + return None + if dlasthypervisor == '': dlasthypervisor = 'N/A'