backend: auto detect libvirt instances from other pools
This commit is contained in:
parent
8c3cd1895e
commit
f54c597aa7
1 changed files with 22 additions and 15 deletions
|
@ -40,25 +40,32 @@ def _main():
|
|||
# Gather the list of all domains here
|
||||
vm_names = set()
|
||||
|
||||
# List all the volumes in the 'images' pool that seem to be related to given
|
||||
# Pool name
|
||||
pool = conn.storagePoolLookupByName("images")
|
||||
|
||||
# Some of those suffixes are used by Red Hat Copr
|
||||
known_suffixes = ["_root_disk$", "_config_cd$", "_swap$", "_root$", "_config$"]
|
||||
volume_pool_names = ["images", "swap-space"]
|
||||
|
||||
for volume in pool.listVolumes():
|
||||
if volume.startswith(pool_id):
|
||||
for suffix in known_suffixes:
|
||||
volume = re.sub(suffix, "", volume)
|
||||
vm_names.add(volume)
|
||||
for pool_name in volume_pool_names:
|
||||
try:
|
||||
pool = conn.storagePoolLookupByName(pool_name)
|
||||
except libvirt.libvirtError:
|
||||
msg = "Pool {0} not found\n".format(pool_name)
|
||||
sys.stderr.write(msg)
|
||||
continue
|
||||
|
||||
# List all domains that are related to given Pool (just to be 100% sure, but
|
||||
# this shouldn't add any new items to the vm_names set actually).
|
||||
for domain in conn.listAllDomains():
|
||||
name = domain.name()
|
||||
if name.startswith(pool_id):
|
||||
vm_names.add(name)
|
||||
# List all the volumes in the volume pool that seem to be related to
|
||||
# the given Pool name
|
||||
for volume in pool.listVolumes():
|
||||
if volume.startswith(pool_id):
|
||||
for suffix in known_suffixes:
|
||||
volume = re.sub(suffix, "", volume)
|
||||
vm_names.add(volume)
|
||||
|
||||
# List all domains that are related to given Pool (just to be 100% sure, but
|
||||
# this shouldn't add any new items to the vm_names set actually).
|
||||
for domain in conn.listAllDomains():
|
||||
name = domain.name()
|
||||
if name.startswith(pool_id):
|
||||
vm_names.add(name)
|
||||
|
||||
# Print them out, so upper level tooling can work with the list. See:
|
||||
# roles/copr/backend/files/provision/libvirt-list
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue