diff --git a/src/util.py b/src/util.py index c8adf060c7077ef4995c323a2368e3d3ca2e5696..3ef298efe91209a61a80c18cbb7e35fb50672d51 100644 --- a/src/util.py +++ b/src/util.py @@ -96,7 +96,12 @@ class FutureCache: def clear_cache(self): self._cache = None pass - + + def __repr__(self): + return 'FutureCache(%s)' % self._cache + + pass + class InvalidHostException(Exception): def __init__(self, allowed=[]): diff --git a/src/vm.py b/src/vm.py index b1726a883ca2b24d276a8e5d6706ddfac79e26ff..1a0651a5b36d6e379a528a7be0117678661d2912 100644 --- a/src/vm.py +++ b/src/vm.py @@ -118,10 +118,9 @@ class Hypervisor: def __init__(self, host, db): self.host = host self.db = db - self.libvirt = libvirt.open('qemu+ssh://root@%s/system' % host) - def get_storage_pool(name): - return self.libvirt.storagePoolLookupByName(name) - pass + def libvirt_open(): + return libvirt.open('qemu+ssh://root@%s/system' % host) + self.libvirt = util.FutureCache(libvirt_open) def get_storage_pool_list(): return dict([ (p.name(), p) for p in self.libvirt.listAllStoragePools() ]) @@ -150,8 +149,14 @@ class Hypervisor: if not attr.startswith('__'): return getattr(self.libvirt, attr) raise AttributeError() - - + + def __repr__(self): + return 'Hypervisor(%s, libvirt=%s)' % ( + self.host, + self.libvirt._cache) + + pass + def get_hypervisors(db): hosts = set() for d in db.tree._host_._qemu_._disk_: