copr: allow pool ID to be specified via --pool or env variable
This commit is contained in:
parent
45d0034a8f
commit
4c4652a74a
1 changed files with 10 additions and 4 deletions
|
@ -6,6 +6,7 @@ defined/running, or (b) have some resource (e.g. storage) still available in the
|
||||||
LibVirt hypervisor.
|
LibVirt hypervisor.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import libvirt
|
import libvirt
|
||||||
|
@ -15,14 +16,19 @@ from helpers import get_hv_identification_from_pool_id
|
||||||
def _get_parser():
|
def _get_parser():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("--connection", required=False)
|
parser.add_argument("--connection", required=False)
|
||||||
parser.add_argument("--pool", required=True)
|
parser.add_argument("--pool", required=False)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def _main():
|
def _main():
|
||||||
args = _get_parser().parse_args()
|
args = _get_parser().parse_args()
|
||||||
|
|
||||||
|
pool_id = args.pool or os.getenv("RESALLOC_POOL_ID")
|
||||||
|
if not pool_id:
|
||||||
|
print("Specify pool ID by --pool or $RESALLOC_POOL_ID")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
connection = args.connection if args.connection else \
|
connection = args.connection if args.connection else \
|
||||||
get_hv_identification_from_pool_id(args.pool)[1]
|
get_hv_identification_from_pool_id(pool_id)[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = libvirt.openReadOnly(connection)
|
conn = libvirt.openReadOnly(connection)
|
||||||
|
@ -37,14 +43,14 @@ def _main():
|
||||||
# Pool name
|
# Pool name
|
||||||
pool = conn.storagePoolLookupByName("images")
|
pool = conn.storagePoolLookupByName("images")
|
||||||
for volume in pool.listVolumes():
|
for volume in pool.listVolumes():
|
||||||
if volume.startswith(args.pool):
|
if volume.startswith(pool_id):
|
||||||
vm_names.add(volume.rsplit("_", 1)[0])
|
vm_names.add(volume.rsplit("_", 1)[0])
|
||||||
|
|
||||||
# List all domains that are related to given Pool (just to be 100% sure, but
|
# 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).
|
# this shouldn't add any new items to the vm_names set actually).
|
||||||
for domain in conn.listAllDomains():
|
for domain in conn.listAllDomains():
|
||||||
name = domain.name()
|
name = domain.name()
|
||||||
if name.startswith(args.pool):
|
if name.startswith(pool_id):
|
||||||
vm_names.add(name)
|
vm_names.add(name)
|
||||||
|
|
||||||
# Print them out, so upper level tooling can work with the list. See:
|
# Print them out, so upper level tooling can work with the list. See:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue