public inbox for kdevops@lists.linux.dev
 help / color / mirror / Atom feed
From: Scott Mayhew <smayhew@redhat.com>
To: kdevops@lists.linux.dev
Subject: [PATCH] guestfs: Don't force the bringup to abort if a domain already exists
Date: Tue,  2 Jan 2024 17:25:05 -0500	[thread overview]
Message-ID: <20240102222505.34645-1-smayhew@redhat.com> (raw)

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).

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 kconfigs/Kconfig.bringup   |  7 +++++++
 scripts/bringup_guestfs.sh | 11 +++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/kconfigs/Kconfig.bringup b/kconfigs/Kconfig.bringup
index 95991cc5..8e096736 100644
--- a/kconfigs/Kconfig.bringup
+++ b/kconfigs/Kconfig.bringup
@@ -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
diff --git a/scripts/bringup_guestfs.sh b/scripts/bringup_guestfs.sh
index e51a5b47..406a9d5e 100755
--- a/scripts/bringup_guestfs.sh
+++ b/scripts/bringup_guestfs.sh
@@ -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"
-- 
2.41.0


             reply	other threads:[~2024-01-02 22:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 22:25 Scott Mayhew [this message]
2024-01-03 12:09 ` [PATCH] guestfs: Don't force the bringup to abort if a domain already exists Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240102222505.34645-1-smayhew@redhat.com \
    --to=smayhew@redhat.com \
    --cc=kdevops@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox