copr: make the libvirt-list --connection optional
This commit is contained in:
parent
965039a738
commit
eb1c4410e8
3 changed files with 61 additions and 58 deletions
|
@ -8,20 +8,24 @@ LibVirt hypervisor.
|
|||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import libvirt
|
||||
from helpers import get_hv_identification_from_pool_id
|
||||
|
||||
|
||||
def _get_parser():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--connection", required=True)
|
||||
parser.add_argument("--connection", required=False)
|
||||
parser.add_argument("--pool", required=True)
|
||||
return parser
|
||||
|
||||
def _main():
|
||||
args = _get_parser().parse_args()
|
||||
|
||||
connection = args.connection if args.connection else \
|
||||
get_hv_identification_from_pool_id(args.pool)[1]
|
||||
|
||||
try:
|
||||
conn = libvirt.openReadOnly(args.connection)
|
||||
conn = libvirt.openReadOnly(connection)
|
||||
except libvirt.libvirtError:
|
||||
print('Failed to open connection to the hypervisor')
|
||||
sys.exit(1)
|
||||
|
|
53
roles/copr/backend/templates/provision/helpers.py
Normal file
53
roles/copr/backend/templates/provision/helpers.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
def get_hv_identification_from_pool_id(pool_id):
|
||||
""" Get unique ID of the hypervisor """
|
||||
if pool_id.startswith("copr_hv_x86_64_01"):
|
||||
return (
|
||||
0,
|
||||
"qemu+ssh://copr@vmhost-x86-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_02"):
|
||||
return (
|
||||
1,
|
||||
"qemu+ssh://copr@vmhost-x86-copr02"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_03"):
|
||||
return (
|
||||
2,
|
||||
"qemu+ssh://copr@vmhost-x86-copr03"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_04"):
|
||||
return (
|
||||
3,
|
||||
"qemu+ssh://copr@vmhost-x86-copr04"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_ppc64le_01"):
|
||||
return (
|
||||
4,
|
||||
"qemu+ssh://copr@vmhost-p08-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_ppc64le_02"):
|
||||
return (
|
||||
5,
|
||||
"qemu+ssh://copr@vmhost-p08-copr02"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
|
||||
if pool_id.startswith("copr_p09_01"):
|
||||
return (
|
||||
6,
|
||||
"qemu+ssh://copr@vmhost-p09-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
raise Exception("can't convert pool_id to hv ID")
|
|
@ -16,6 +16,7 @@ import shutil
|
|||
import time
|
||||
import pipes
|
||||
import argparse
|
||||
from helpers import get_hv_identification_from_pool_id
|
||||
|
||||
|
||||
DEFAULT_POOL = 'images'
|
||||
|
@ -25,61 +26,6 @@ VOLUMES = {
|
|||
}
|
||||
|
||||
|
||||
def get_hv_identification_from_pool_id(pool_id):
|
||||
""" Get unique ID of the hypervisor """
|
||||
if pool_id.startswith("copr_hv_x86_64_01"):
|
||||
return (
|
||||
0,
|
||||
"qemu+ssh://copr@vmhost-x86-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_02"):
|
||||
return (
|
||||
1,
|
||||
"qemu+ssh://copr@vmhost-x86-copr02"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_03"):
|
||||
return (
|
||||
2,
|
||||
"qemu+ssh://copr@vmhost-x86-copr03"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_x86_64_04"):
|
||||
return (
|
||||
3,
|
||||
"qemu+ssh://copr@vmhost-x86-copr04"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"x86_64",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_ppc64le_01"):
|
||||
return (
|
||||
4,
|
||||
"qemu+ssh://copr@vmhost-p08-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
if pool_id.startswith("copr_hv_ppc64le_02"):
|
||||
return (
|
||||
5,
|
||||
"qemu+ssh://copr@vmhost-p08-copr02"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
|
||||
if pool_id.startswith("copr_p09_01"):
|
||||
return (
|
||||
6,
|
||||
"qemu+ssh://copr@vmhost-p09-copr01"
|
||||
".rdu-cc.fedoraproject.org/system",
|
||||
"ppc64le",
|
||||
)
|
||||
raise Exception("can't convert pool_id to hv ID")
|
||||
|
||||
|
||||
class ConfigFile:
|
||||
def __init__(self, name, contents):
|
||||
self.name = name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue