From b2f6e953831aba9ab7cc4b8673c237c3bb434100 Mon Sep 17 00:00:00 2001 From: Oleg Vasilev Date: Wed, 30 Nov 2022 22:01:08 +0600 Subject: [PATCH] cloner: clone serial files Before this, on clone the serial file would remain the same for the cloned domain. This doesn't make much sense as the output would be an intermix of two unrelated output sequences. Here we apply the the same filename changing algorithm, as with disk files. Signed-off-by: Oleg Vasilev --- virtinst/cloner.py | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/virtinst/cloner.py b/virtinst/cloner.py index 9334513c5..556bfdbbd 100644 --- a/virtinst/cloner.py +++ b/virtinst/cloner.py @@ -9,6 +9,7 @@ import re import os +from itertools import chain import libvirt @@ -20,6 +21,7 @@ from .devices import DeviceInterface from .devices import DeviceDisk from .logger import log from .devices import DeviceChannel +from .devices import DeviceSerial def _replace_vm(conn, name): @@ -70,9 +72,9 @@ def _generate_clone_name(conn, basename): sep="", start_num=start_num, force_num=force_num) -def _generate_clone_disk_path(conn, origname, newname, origpath): +def _generate_clone_path(origname, newname, origpath, cb_exists): """ - Generate desired cloned disk path name, derived from the + Generate desired cloned path for auxiliary files, derived from the original path, original VM name, and proposed new VM name """ if origpath is None: @@ -99,9 +101,7 @@ def _generate_clone_disk_path(conn, origname, newname, origpath): clonebase = newname clonebase = os.path.join(dirname, clonebase) - def cb(p): - return DeviceDisk.path_definitely_exists(conn, p) - return generatename.generate_name(clonebase, cb, suffix=suffix) + return generatename.generate_name(clonebase, cb_exists, suffix=suffix) def _lookup_vm(conn, name): @@ -287,7 +287,9 @@ class Cloner(object): @staticmethod def generate_clone_disk_path(conn, origname, newname, origpath): - return _generate_clone_disk_path(conn, origname, newname, origpath) + def cb_exists(p): + return DeviceDisk.path_definitely_exists(conn, p) + return _generate_clone_path(origname, newname, origpath, cb_exists) @staticmethod def build_clone_disk(orig_disk, clonepath, allow_create, sparse): @@ -455,6 +457,21 @@ class Cloner(object): # Functional methods # ###################### + def _prepare_serial_files(self): + for serial in chain(self._new_guest.devices.console, + self._new_guest.devices.serial): + if serial.type != DeviceSerial.TYPE_FILE: + continue + + def cb_exists(path): + # Ignore the check for now + return False + + serial.source.path = _generate_clone_path(self.src_name, + self.new_guest.name, + serial.source.path, + cb_exists=cb_exists) + def _prepare_nvram(self): if not self._nvram_diskinfo: return @@ -534,6 +551,7 @@ class Cloner(object): xmldisk.set_source_path(new_disk.get_source_path()) self._prepare_nvram() + self._prepare_serial_files() # Save altered clone xml diff = xmlutil.diff(self._src_guest.get_xml(),