Untitled
unknown
sh
2 years ago
1.7 kB
6
Indexable
#!/bin/bash
#
# XenServer - change NFS server IP address...
#
# WARNING! This script works on "NFS Virtual disk storage" SRs only!!!
# Based on https://techblog.jeppson.org/2017/01/change-nfs-sr-address-xenserver/
# our parameters
SR_NAME_LABEL="NAS-Borg NFS4 XenProd"
NFS_SERVER=10.0.10.11
NFS_PATH=/mnt/BorgReplicationPool/XenRepProd
NFS_VERSION=4.1
#end of parameters
set -e
host_uuid=$(xe host-list hostname=`hostname` --minimal)
echo "host-uuid='$host_uuid' for hostname='`hostname`'"
[ -n "$host_uuid" ] || {
echo "Unable to get host-uuid for hostname='`hostname`'"
exit 1
}
sr_uuid=$(xe sr-list name-label="$SR_NAME_LABEL" --minimal)
[ -n "$sr_uuid" ] || {
echo "Unable to get sr-uuid for sr-name-label=\"$SR_NAME_LABEL\""
exit 1
}
echo "sr-uuid=$sr_uuid"
sr_type=$(xe sr-list uuid=$sr_uuid params=type --minimal)
[ nfs = "$sr_type" ] || {
echo "SR '$SR_NAME_LABEL' type '$sr_type' != 'nfs'"
exit 1
}
pbd_uuid=$(xe pbd-list host-uuid=$host_uuid sr-name-label="$SR_NAME_LABEL" \
--minimal)
[ -n "$pbd_uuid" ] || {
echo "Unable to get pbd-uuid for \
host-uuid=$host_uuid sr-name-label=\"$SR_NAME_LABEL\""
exit 1
}
echo "pbd-uuid=$pbd_uuid"
set -x
xe pbd-unplug uuid=$pbd_uuid
xe pbd-destroy uuid=$pbd_uuid
set +x
new_pbd_file=`mktemp`
set -x
xe pbd-create host-uuid=$host_uuid sr-uuid=$sr_uuid \
device-config:server=$NFS_SERVER \
device-config:serverpath=$NFS_PATH \
device-config:type=nfs \
device-config:nfsversion=$NFS_VERSION > $new_pbd_file
set +x
[ -s "$new_pbd_file" ] || {
echo "Unable to get new_pbd_id"
exit 1
}
new_pbd_id=$(cat "$new_pbd_file")
set -x
xe pbd-plug uuid=$new_pbd_id
set +x
echo "Done"
exit 0
Editor is loading...