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}" fusermount -u "${mountpoint}"
fi fi
# TODO: Probably don't shut it down by default.
if virsh list | grep -q " ${vm_name} "; then if virsh list | grep -q " ${vm_name} "; then
echo "Stopping ${vm_name}" echo "Stopping ${vm_name}"
virsh destroy "${vm_name}" virsh destroy "${vm_name}"
@ -43,23 +44,37 @@ else
fi fi
echo "Waiting for ${vm_name} to connect to the network..." 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: Exit if this failes or times out.
# TODO: This needs a proper timeout. # TODO: This needs a proper timeout.
while [ "${vm_ip_address}" = "" ]; do while [ "${vm_ip_addresses}" = "" ]; do
vm_ip_address="$(virsh net-dhcp-leases "${NETWORK_NAME}" | awk "${awk_script}")" vm_ip_addresses="$(virsh net-dhcp-leases "${NETWORK_NAME}" | awk "${awk_script}")"
done 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. # 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: Exit if this failes or times out.
# TODO: This needs a proper timeout. # TODO: This needs a proper timeout.
echo "Attempting to mount over ssh." echo "Attempting to mount over ssh."
until sshfs "${vm_ip_address}:${REMOTE_DIRECTORY}" "${mountpoint}"; do mounted='false'
echo "Could not connect via SSH, retrying."
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 sleep 3
done done
fi fi

Loading…
Cancel
Save