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