forked from infra/ansible
copr-hypervisor: avoid using vol-upload to avoid FD leaks
Per discussion with @pkrempa it seems that it's anyway a good idea to upload this way, as scp is faster (we avoid many io layers). Relates: https://redhat.atlassian.net/browse/RHEL-170773
This commit is contained in:
parent
43a7a9e0fe
commit
8c5923e123
1 changed files with 28 additions and 6 deletions
|
|
@ -17,6 +17,7 @@ import shlex
|
|||
import time
|
||||
import argparse
|
||||
import ipaddress
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from helpers import get_hv_identification_from_pool_id
|
||||
|
||||
|
|
@ -65,13 +66,13 @@ class LibvirtSpawner:
|
|||
self.log.debug("Logging to %s", self.connection)
|
||||
self.cleanup_actions = {}
|
||||
|
||||
def call(self, cmd, *args, **kwargs):
|
||||
def call(self, cmd, *args, call=subprocess.call, **kwargs):
|
||||
"""
|
||||
Run CMD, and log info.
|
||||
"""
|
||||
self.log.debug("cmd: %s", ' '.join([shlex.quote(str(x)) for x in cmd]))
|
||||
start = time.time()
|
||||
status = subprocess.call(cmd, *args, **kwargs)
|
||||
status = call(cmd, *args, **kwargs)
|
||||
self.log.debug(" -> exit_status=%s, time=%ss",
|
||||
status, round(time.time() - start, 3))
|
||||
return status
|
||||
|
|
@ -82,6 +83,13 @@ class LibvirtSpawner:
|
|||
"""
|
||||
return self.call(['virsh', '-c', self.connection] + args, stdout=sys.stderr)
|
||||
|
||||
def virsh_check_output(self, args):
|
||||
"""
|
||||
Call virsh without polluting stdout.
|
||||
"""
|
||||
return self.call(['virsh', '-c', self.connection] + args,
|
||||
call=subprocess.check_output).decode("utf-8")
|
||||
|
||||
def wait_for_ssh(self, host):
|
||||
"""
|
||||
Knowing the IP address of recently started VM, wait for the SSH server
|
||||
|
|
@ -240,10 +248,24 @@ ssh_authorized_keys:
|
|||
return image
|
||||
|
||||
def create_volume_from_iso(self, name, prealloc_size, iso, pool=DEFAULT_POOL):
|
||||
""" Create libvirt volume from ISO file """
|
||||
self.alloc_disk(name, prealloc_size, pool)
|
||||
if self.virsh_silent(['vol-upload', name, iso, '--pool', pool]):
|
||||
raise Exception("can not vol-upload the config disk")
|
||||
"""
|
||||
Create libvirt volume from ISO file
|
||||
"""
|
||||
parsed_url = urlparse(self.connection)
|
||||
remote_host = parsed_url.netloc
|
||||
if not remote_host:
|
||||
raise RuntimeError(f"Could not deduce remote host from connection: {self.connection}")
|
||||
|
||||
# <path>/libvirt-images</path> -> /libvirt-images
|
||||
pool_path = self.virsh_check_output(["-q", "pool-dumpxml", pool, "--xpath", '//target/path'])
|
||||
pool_path = pool_path.strip()[6:-7]
|
||||
target_path = os.path.join(pool_path, name)
|
||||
|
||||
scp_cmd = ['scp', '-p', iso, f"{remote_host}:{target_path}"]
|
||||
if self.call(scp_cmd):
|
||||
raise RuntimeError(f"Failed to upload ISO via SCP to {target_path} on {remote_host}")
|
||||
|
||||
self.virsh_silent(["pool-refresh", pool])
|
||||
|
||||
def create_volume_from_volume(self, name, volume, pool=DEFAULT_POOL, size=None):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue