Blame SOURCES/0028-scripts-Add-simple-script-for-automating-VDDK-disk-c.patch

6661d0
From f8d649063edb9744c98aca17c6c82e5fce0a4be7 Mon Sep 17 00:00:00 2001
e7ca0c
From: "Richard W.M. Jones" <rjones@redhat.com>
e7ca0c
Date: Tue, 30 Nov 2021 17:56:02 +0000
e7ca0c
Subject: [PATCH] scripts: Add simple script for automating VDDK disk
e7ca0c
 connections
e7ca0c
e7ca0c
It's tedious to work out how to do this by hand every time.  Include a
e7ca0c
developer script to make connecting to a guest disk easy.
e7ca0c
e7ca0c
(cherry picked from commit 44ee90ee01677032a14d5b71118b7af0651db3d5)
e7ca0c
---
e7ca0c
 .gitignore              |  1 +
e7ca0c
 Makefile.am             |  2 +-
e7ca0c
 configure.ac            |  2 +
e7ca0c
 scripts/vddk-open.sh.in | 89 +++++++++++++++++++++++++++++++++++++++++
e7ca0c
 4 files changed, 93 insertions(+), 1 deletion(-)
e7ca0c
 create mode 100755 scripts/vddk-open.sh.in
e7ca0c
e7ca0c
diff --git a/.gitignore b/.gitignore
e7ca0c
index 847b72dd..6565600f 100644
e7ca0c
--- a/.gitignore
e7ca0c
+++ b/.gitignore
e7ca0c
@@ -89,6 +89,7 @@ plugins/*/*.3
e7ca0c
 /plugins/S3/nbdkit-S3-plugin
e7ca0c
 /plugins/tmpdisk/default-command.c
e7ca0c
 /podwrapper.pl
e7ca0c
+/scripts/vddk-open.sh
e7ca0c
 /server/libnbdkit.a
e7ca0c
 /server/local/nbdkit.pc
e7ca0c
 /server/nbdkit
e7ca0c
diff --git a/Makefile.am b/Makefile.am
e7ca0c
index 49f5d91c..6df5eba0 100644
e7ca0c
--- a/Makefile.am
e7ca0c
+++ b/Makefile.am
e7ca0c
@@ -46,7 +46,7 @@ EXTRA_DIST = \
e7ca0c
 	SECURITY \
e7ca0c
 	$(NULL)
e7ca0c
 
e7ca0c
-CLEANFILES += html/*.html
e7ca0c
+CLEANFILES += html/*.html scripts/*~
e7ca0c
 
e7ca0c
 if !ENABLE_LIBFUZZER
e7ca0c
 # NB: This is not the real nbdkit binary.  It's a wrapper that allows
e7ca0c
diff --git a/configure.ac b/configure.ac
6661d0
index 263714f0..60e7cce2 100644
e7ca0c
--- a/configure.ac
e7ca0c
+++ b/configure.ac
6661d0
@@ -1249,6 +1249,8 @@ dnl Produce output files.
e7ca0c
 AC_CONFIG_HEADERS([config.h])
e7ca0c
 AC_CONFIG_FILES([podwrapper.pl],
e7ca0c
                 [chmod +x,-w podwrapper.pl])
e7ca0c
+AC_CONFIG_FILES([scripts/vddk-open.sh],
e7ca0c
+                [chmod +x,-w scripts/vddk-open.sh])
e7ca0c
 AC_CONFIG_FILES([common/protocol/generate-protostrings.sh],
e7ca0c
                 [chmod +x,-w common/protocol/generate-protostrings.sh])
e7ca0c
 AC_CONFIG_FILES([Makefile
e7ca0c
diff --git a/scripts/vddk-open.sh.in b/scripts/vddk-open.sh.in
e7ca0c
new file mode 100755
e7ca0c
index 00000000..218bc93c
e7ca0c
--- /dev/null
e7ca0c
+++ b/scripts/vddk-open.sh.in
e7ca0c
@@ -0,0 +1,89 @@
e7ca0c
+#!/bin/bash -
e7ca0c
+# @configure_input@
e7ca0c
+# Copyright (C) 2013-2021 Red Hat Inc.
e7ca0c
+#
e7ca0c
+# Redistribution and use in source and binary forms, with or without
e7ca0c
+# modification, are permitted provided that the following conditions are
e7ca0c
+# met:
e7ca0c
+#
e7ca0c
+# * Redistributions of source code must retain the above copyright
e7ca0c
+# notice, this list of conditions and the following disclaimer.
e7ca0c
+#
e7ca0c
+# * Redistributions in binary form must reproduce the above copyright
e7ca0c
+# notice, this list of conditions and the following disclaimer in the
e7ca0c
+# documentation and/or other materials provided with the distribution.
e7ca0c
+#
e7ca0c
+# * Neither the name of Red Hat nor the names of its contributors may be
e7ca0c
+# used to endorse or promote products derived from this software without
e7ca0c
+# specific prior written permission.
e7ca0c
+#
e7ca0c
+# THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
e7ca0c
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
e7ca0c
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
e7ca0c
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
e7ca0c
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
e7ca0c
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
e7ca0c
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
e7ca0c
+# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
e7ca0c
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e7ca0c
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
e7ca0c
+# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
e7ca0c
+# SUCH DAMAGE.
e7ca0c
+
e7ca0c
+# Open an nbdkit-vddk-plugin connection to the first disk of a guest
e7ca0c
+# on a VMware ESXi server.  This script automates the tedious bits of
e7ca0c
+# getting the disk name, moref, etc.  However please read the
e7ca0c
+# nbdkit-vddk-plugin documentation as well.
e7ca0c
+#
e7ca0c
+# Usage:
e7ca0c
+#   scripts/vddk-open.sh SERVER GUEST -r -f -v libdir=/path/to/vmware-vix-disklib-distrib [...]
e7ca0c
+#
e7ca0c
+# where SERVER is the hostname or IP address of the ESXi server and
e7ca0c
+# GUEST is the name of the guest.
e7ca0c
+#
e7ca0c
+# These two required parameters are followed by any extra nbdkit
e7ca0c
+# parameters you want to use, such as VDDK libdir, flags, filters etc.
e7ca0c
+#
e7ca0c
+# Note that the script runs ./nbdkit (ie. the wrapper in the top build
e7ca0c
+# directory).
e7ca0c
+
e7ca0c
+nbdkit="@abs_top_builddir@/nbdkit"
e7ca0c
+
e7ca0c
+server="$1"
e7ca0c
+guest="$2"
e7ca0c
+shift 2
e7ca0c
+
e7ca0c
+# Get the libvirt XML, filename and moref.
e7ca0c
+echo -n "root password? "
e7ca0c
+xml="$( virsh -c "esx://root@$server/?no_verify=1" dumpxml "$guest" )"
e7ca0c
+echo
e7ca0c
+
e7ca0c
+file="$( echo "$xml" | grep '
e7ca0c
+         sed -e "s/.*'\(.*\)'.*/\1/" )"
e7ca0c
+moref="$( echo "$xml" | grep '
e7ca0c
+          sed -e 's,.*>\(.*\)<.*,\1,' )"
e7ca0c
+
e7ca0c
+#echo file="$file"
e7ca0c
+#echo moref="$moref"
e7ca0c
+
e7ca0c
+# Get the thumbprint.
e7ca0c
+thumbprint="$( openssl s_client -connect "$server:443" </dev/null 2>/dev/null |
e7ca0c
+               openssl x509 -in /dev/stdin -fingerprint -sha1 -noout 2>/dev/null |
e7ca0c
+               grep '^sha1 Fingerprint=' |
e7ca0c
+               sed 's/.*Fingerprint=\([A-F0-9:]\+\)/\1/' )"
e7ca0c
+
e7ca0c
+#echo thumbprint="$thumbprint"
e7ca0c
+
e7ca0c
+# Construct the nbdkit command line.
e7ca0c
+declare -a args
e7ca0c
+
e7ca0c
+args[${#args[@]}]="$nbdkit"
e7ca0c
+args[${#args[@]}]="vddk"
e7ca0c
+args[${#args[@]}]="file=$file"
e7ca0c
+args[${#args[@]}]="vm=moref=$moref"
e7ca0c
+args[${#args[@]}]="server=$server"
e7ca0c
+args[${#args[@]}]="thumbprint=$thumbprint"
e7ca0c
+args[${#args[@]}]="user=root"
e7ca0c
+
e7ca0c
+echo "${args[@]}" "$@"
e7ca0c
+"${args[@]}" "$@"
e7ca0c
-- 
e7ca0c
2.31.1
e7ca0c