Updated vm-mount to handle multiple IP addresses for one VM.

in-use
Emily Frost 7 years ago
parent c3081bb106
commit 6e3d143f09
No known key found for this signature in database
GPG Key ID: FD1FA524668FB1FA

@ -18,6 +18,7 @@ if [ "$1" = "-u" ]; then
fusermount -u "${mountpoint}"
fi
# TODO: Probably don't shut it down by default.
if virsh list | grep -q " ${vm_name} "; then
echo "Stopping ${vm_name}"
virsh destroy "${vm_name}"
@ -43,23 +44,37 @@ else
fi
echo "Waiting for ${vm_name} to connect to the network..."
vm_ip_address=""
vm_ip_addresses=""
# TODO: Exit if this failes or times out.
# TODO: This needs a proper timeout.
while [ "${vm_ip_address}" = "" ]; do
vm_ip_address="$(virsh net-dhcp-leases "${NETWORK_NAME}" | awk "${awk_script}")"
while [ "${vm_ip_addresses}" = "" ]; do
vm_ip_addresses="$(virsh net-dhcp-leases "${NETWORK_NAME}" | awk "${awk_script}")"
done
# TODO: Exit if this fails.
echo "$vm_ip_addresses"
# TODO: Make sure this directory isn't already a mountpoint.
# TODO: Make sure this directory isn't made if the vm fails to start or connect.
mkdir -p "${mountpoint}"
mkdir -p "${mountpoint}" || \
{ echo "Failed to create mountpoint ${mountpoint}"; exit 1; }
# TODO: Exit if this failes or times out.
# TODO: This needs a proper timeout.
echo "Attempting to mount over ssh."
until sshfs "${vm_ip_address}:${REMOTE_DIRECTORY}" "${mountpoint}"; do
echo "Could not connect via SSH, retrying."
mounted='false'
until [ $mounted = 'true' ]; do
for ip_address in $vm_ip_addresses; do
echo "Trying at ${ip_address}."
if sshfs "${ip_address}:${REMOTE_DIRECTORY}" "${mountpoint}"; then
echo "Mounted at ${mountpoint}."
exit 0
else
echo "Could not connect to SSH server on ${ip_address}."
fi
done
sleep 3
done
fi

Loading…
Cancel
Save