Skip to contentSkip to conversation

guestfs: Don't force the bringup to abort if a domain already exists

PATCH In review Scott Mayhew 2 participants 2 messages Jan 2, 2024 – Jan 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 guestfs: Don't force the bringup to abort if a domain already exists

The guestfs bringup script checks to see if a domain already exists, and aborts if it does. Vagrant would just bring up the existing domain. Add a config option to do that with guestfs (the default is still to abort, though).

---
 kconfigs/Kconfig.bringup   |  7 +++++++
 scripts/bringup_guestfs.sh | 11 +++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
kconfigs/Kconfig.bringup +7 -0
index 95991cc5..8e096736 100644
@@ -66,6 +66,13 @@ config VIRT_BUILDER_OS_VERSION
          build a root image for the guest. Run "virt-builder -l"
          to get a list of operating systems and versions supported
          by guestfs.
+config GUESTFS_ABORT_DUP
+	bool "Abort bringup if domain already defined"
+	default y
+	help
+	  This option will abort the bringup process if the domain is
+	  already defined. If set to "n", the bringup process try to
+	  start the existing domain instead of aborting.
 endif # GUESTFS
 
 config LIBVIRT
scripts/bringup_guestfs.sh +9 -2
index e51a5b47..406a9d5e 100755
@@ -22,6 +22,7 @@ BASE_IMAGE_DIR="${STORAGEDIR}/base_images"
 BASE_IMAGE="${BASE_IMAGE_DIR}/${OS_VERSION}.raw"
 mkdir -p $STORAGEDIR
 mkdir -p $BASE_IMAGE_DIR
+ABORT_DUP=${CONFIG_GUESTFS_ABORT_DUP}
 
 cmdfile=$(mktemp)
 
@@ -58,8 +59,14 @@ do
 	#
 	virsh domstate $name 1>/dev/null 2>&1
 	if [ $? -eq 0 ]; then
-		echo "Domain $name is already defined. Aborting!"
-		exit 1
+		if [ "$ABORT_DUP" = "y" ]; then
+			echo "Domain $name is already defined. Aborting!"
+			exit 1
+		else
+			echo "Domain $name is already defined."
+			virsh start $name
+			exit 0
+		fi
 	fi
 
 	SSH_KEY_DIR="${GUESTFSDIR}/$name/ssh"
Signature · 1 line
2.41.0
#1 lore raw
Quoted 5 lines · Scott Mayhew

The guestfs bringup script checks to see if a domain already exists, and aborts if it does. Vagrant would just bring up the existing domain. Add a config option to do that with guestfs (the default is still to abort, though).

If the old behavior was to just bring up the domain, then we should probably just follow suit here. Maybe drop the config option and just change this to work like Vagrant does?

Quoted 53 lines
---
 kconfigs/Kconfig.bringup   |  7 +++++++
 scripts/bringup_guestfs.sh | 11 +++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
kconfigs/Kconfig.bringup +7 -0
index 95991cc5..8e096736 100644
@@ -66,6 +66,13 @@ config VIRT_BUILDER_OS_VERSION
          build a root image for the guest. Run "virt-builder -l"
          to get a list of operating systems and versions supported
          by guestfs.
+config GUESTFS_ABORT_DUP
+	bool "Abort bringup if domain already defined"
+	default y
+	help
+	  This option will abort the bringup process if the domain is
+	  already defined. If set to "n", the bringup process try to
+	  start the existing domain instead of aborting.
 endif # GUESTFS
 
 config LIBVIRT
scripts/bringup_guestfs.sh +9 -2
index e51a5b47..406a9d5e 100755
@@ -22,6 +22,7 @@ BASE_IMAGE_DIR="${STORAGEDIR}/base_images"
 BASE_IMAGE="${BASE_IMAGE_DIR}/${OS_VERSION}.raw"
 mkdir -p $STORAGEDIR
 mkdir -p $BASE_IMAGE_DIR
+ABORT_DUP=${CONFIG_GUESTFS_ABORT_DUP}
 
 cmdfile=$(mktemp)
 
@@ -58,8 +59,14 @@ do
 	#
 	virsh domstate $name 1>/dev/null 2>&1
 	if [ $? -eq 0 ]; then
-		echo "Domain $name is already defined. Aborting!"
-		exit 1
+		if [ "$ABORT_DUP" = "y" ]; then
+			echo "Domain $name is already defined. Aborting!"
+			exit 1
+		else
+			echo "Domain $name is already defined."
+			virsh start $name
+			exit 0
+		fi
 	fi
 
 	SSH_KEY_DIR="${GUESTFSDIR}/$name/ssh"
Signature · 1 line
Jeff Layton <[email protected]>