copr-builders: better libvirt spawning
- stop ignoring several options - pass command-line arguments into LibvirtSpawner.__init__() - don't generate 20G swap volume by default
This commit is contained in:
parent
01f07b26c1
commit
ac59521f08
1 changed files with 12 additions and 22 deletions
|
@ -93,32 +93,24 @@ class LibvirtSpawner:
|
||||||
# pylint: disable=too-many-instance-attributes
|
# pylint: disable=too-many-instance-attributes
|
||||||
workdir = None
|
workdir = None
|
||||||
connection = None
|
connection = None
|
||||||
vm_name = None
|
|
||||||
root_disk_pool = "images"
|
root_disk_pool = "images"
|
||||||
root_vol_size = "6GB"
|
root_vol_size = "6GB"
|
||||||
startup_script = ""
|
startup_script = ""
|
||||||
config_files = []
|
config_files = []
|
||||||
arch = None
|
arch = None
|
||||||
swap_vol_size = None
|
|
||||||
cpu_count = 2
|
|
||||||
boot_options = []
|
boot_options = []
|
||||||
ipv6 = None
|
ipv6 = None
|
||||||
playbook = "{{ provision_directory }}/libvirt-provision.yml"
|
playbook = "{{ provision_directory }}/libvirt-provision.yml"
|
||||||
|
|
||||||
def __init__(self, resalloc_pool_id, log):
|
def __init__(self, resalloc_pool_id, log, args):
|
||||||
|
self.args = args
|
||||||
|
self.vm_name = args.name
|
||||||
host_id, self.connection, self.arch = get_hv_identification_from_pool_id(
|
host_id, self.connection, self.arch = get_hv_identification_from_pool_id(
|
||||||
resalloc_pool_id)
|
resalloc_pool_id)
|
||||||
|
|
||||||
self.config_files.append(ConfigFile(
|
self.config_files.append(ConfigFile(
|
||||||
"resalloc-vars.sh",
|
"resalloc-vars.sh",
|
||||||
f"POOL_ID={resalloc_pool_id}\n",
|
f"POOL_ID={resalloc_pool_id}\n",
|
||||||
))
|
))
|
||||||
|
|
||||||
# The Power9 machine has not enough storage to host 2CPU/VM. Let's
|
|
||||||
# double the quote on CPU (at least for now).
|
|
||||||
if host_id in [6]:
|
|
||||||
self.cpu_count = 4
|
|
||||||
|
|
||||||
self.workdir = tempfile.mkdtemp()
|
self.workdir = tempfile.mkdtemp()
|
||||||
self.script_path = os.path.dirname(os.path.realpath(__file__))
|
self.script_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
self.log = log
|
self.log = log
|
||||||
|
@ -323,7 +315,7 @@ class LibvirtSpawner:
|
||||||
raise Exception(exception_message)
|
raise Exception(exception_message)
|
||||||
|
|
||||||
|
|
||||||
def boot_machine(self, volumes, vcpus):
|
def boot_machine(self, volumes):
|
||||||
"""
|
"""
|
||||||
Use virt-install to start the VM according to previously given
|
Use virt-install to start the VM according to previously given
|
||||||
configuration.
|
configuration.
|
||||||
|
@ -331,9 +323,9 @@ class LibvirtSpawner:
|
||||||
cmd = [
|
cmd = [
|
||||||
'virt-install',
|
'virt-install',
|
||||||
'--connect', self.connection,
|
'--connect', self.connection,
|
||||||
'--ram', '4096',
|
'--ram', str(self.args.ram_size),
|
||||||
'--os-type', 'generic',
|
'--os-type', 'generic',
|
||||||
'--vcpus', str(vcpus),
|
'--vcpus', str(self.args.cpu_count),
|
||||||
'--vnc',
|
'--vnc',
|
||||||
'--features', 'acpi=off',
|
'--features', 'acpi=off',
|
||||||
'--noautoconsole',
|
'--noautoconsole',
|
||||||
|
@ -413,10 +405,10 @@ class LibvirtSpawner:
|
||||||
|
|
||||||
# swap volume
|
# swap volume
|
||||||
swap_volume = None
|
swap_volume = None
|
||||||
if self.swap_vol_size:
|
if self.args.swap_vol_size:
|
||||||
|
size = str(self.args.swap_vol_size) + "MB"
|
||||||
swap_volume = self.vm_name + "_swap"
|
swap_volume = self.vm_name + "_swap"
|
||||||
self.alloc_disk(swap_volume, self.swap_vol_size, pool=pool,
|
self.alloc_disk(swap_volume, size, pool=pool, allocation="2GB")
|
||||||
allocation="2GB")
|
|
||||||
|
|
||||||
volumes = []
|
volumes = []
|
||||||
volumes += [("{}/{}".format(pool, vol_root), 'disk', 'virtio')]
|
volumes += [("{}/{}".format(pool, vol_root), 'disk', 'virtio')]
|
||||||
|
@ -428,7 +420,7 @@ class LibvirtSpawner:
|
||||||
volume = "{}/{}".format(pool, swap_volume)
|
volume = "{}/{}".format(pool, swap_volume)
|
||||||
volumes += [(volume, "disk", "virtio")]
|
volumes += [(volume, "disk", "virtio")]
|
||||||
|
|
||||||
self.boot_machine(volumes, self.cpu_count)
|
self.boot_machine(volumes)
|
||||||
|
|
||||||
self.wait_for_ssh(self.ipv6)
|
self.wait_for_ssh(self.ipv6)
|
||||||
self.execute_spinup_playbook(self.ipv6, self.playbook)
|
self.execute_spinup_playbook(self.ipv6, self.playbook)
|
||||||
|
@ -437,7 +429,7 @@ class LibvirtSpawner:
|
||||||
def get_arg_parser():
|
def get_arg_parser():
|
||||||
""" Get the argparse object """
|
""" Get the argparse object """
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--swap-vol-size', metavar='GB', type=int, default=20)
|
parser.add_argument('--swap-vol-size', metavar='GB', type=int)
|
||||||
parser.add_argument('--root-vol-size', metavar='GB', type=int)
|
parser.add_argument('--root-vol-size', metavar='GB', type=int)
|
||||||
parser.add_argument('--cpu-count', default=2)
|
parser.add_argument('--cpu-count', default=2)
|
||||||
parser.add_argument('--ram-size', metavar='MB', default=4096)
|
parser.add_argument('--ram-size', metavar='MB', default=4096)
|
||||||
|
@ -504,9 +496,7 @@ def _main():
|
||||||
args.resalloc_id_in_pool,
|
args.resalloc_id_in_pool,
|
||||||
devel, log)
|
devel, log)
|
||||||
|
|
||||||
spawner = LibvirtSpawner(args.resalloc_pool_id, log)
|
spawner = LibvirtSpawner(args.resalloc_pool_id, log, args)
|
||||||
spawner.vm_name = args.name
|
|
||||||
spawner.swap_vol_size = str(args.swap_vol_size) + "GB"
|
|
||||||
spawner.add_nat_network()
|
spawner.add_nat_network()
|
||||||
spawner.add_bridged_network("Wired connection 2", "eth1", ip6_a, ip6_g)
|
spawner.add_bridged_network("Wired connection 2", "eth1", ip6_a, ip6_g)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue