change indentation from tabs to spaces and couple other minor suggestions by shfmt
This commit is contained in:
1697
xo-install.sh
1697
xo-install.sh
File diff suppressed because it is too large
Load Diff
341
xo-vm-import.sh
341
xo-vm-import.sh
@@ -10,223 +10,220 @@
|
|||||||
IMAGE_URL="https://xo-image.yawn.fi/downloads/image.xva.gz"
|
IMAGE_URL="https://xo-image.yawn.fi/downloads/image.xva.gz"
|
||||||
|
|
||||||
function OSCheck {
|
function OSCheck {
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [[ -z $(command -v xe 2>/dev/null) ]]; then
|
if [[ -z $(command -v xe 2>/dev/null) ]]; then
|
||||||
echo "this scripts needs xe command. make sure you're on xenserver/xcp-ng host"
|
echo "this scripts needs xe command. make sure you're on xenserver/xcp-ng host"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Welcome. This script will import a preinstalled Debian 10 VM image which has Xen Orchestra installed using https://github.com/ronivay/XenOrchestraInstallerUpdater"
|
|
||||||
echo "You need at least 2vCPU/4GB/10GB disk free resources to import VM"
|
|
||||||
echo
|
|
||||||
echo "Please report any issues to this github project"
|
|
||||||
echo
|
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Welcome. This script will import a preinstalled Debian 10 VM image which has Xen Orchestra installed using https://github.com/ronivay/XenOrchestraInstallerUpdater"
|
||||||
|
echo "You need at least 2vCPU/4GB/10GB disk free resources to import VM"
|
||||||
|
echo
|
||||||
|
echo "Please report any issues to this github project"
|
||||||
|
echo
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function NetworkChoose {
|
function NetworkChoose {
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
# get network name/uuid of all available networks configured in the pool
|
# get network name/uuid of all available networks configured in the pool
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
IFS=$'\n' read -r -d '' -a networks <<< "$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
|
IFS=$'\n' read -r -d '' -a networks <<<"$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Which network should the VM use?"
|
echo "Which network should the VM use?"
|
||||||
echo
|
echo
|
||||||
local PS3="Pick a number. CTRL+C to exit: "
|
local PS3="Pick a number. CTRL+C to exit: "
|
||||||
select network in "${networks[@]}"
|
select network in "${networks[@]}"; do
|
||||||
do
|
# get only the network uuid from array which we need later on when adding vif
|
||||||
# get only the network uuid from array which we need later on when adding vif
|
read -r -a network_split <<<"$network"
|
||||||
read -r -a network_split <<< "$network"
|
networkuuid=${network_split[0]}
|
||||||
networkuuid=${network_split[0]}
|
|
||||||
|
|
||||||
# print a menu where to choose network from
|
# print a menu where to choose network from
|
||||||
case $network in
|
case $network in
|
||||||
*)
|
*)
|
||||||
# save network uuid for later
|
# save network uuid for later
|
||||||
vifuuid="$networkuuid"
|
vifuuid="$networkuuid"
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function StorageChoose {
|
function StorageChoose {
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
# get storage name/uuid of all available storages with content-type=user which should match all usable storage repositories
|
# get storage name/uuid of all available storages with content-type=user which should match all usable storage repositories
|
||||||
# shellcheck disable=SC1117
|
# shellcheck disable=SC1117
|
||||||
IFS=$'\n' read -r -d '' -a storages <<< "$(xe sr-list content-type=user | grep "uuid\|name-description" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
|
IFS=$'\n' read -r -d '' -a storages <<<"$(xe sr-list content-type=user | grep "uuid\|name-description" | cut -d':' -f2 | sed 's/^ //' | paste - -)"
|
||||||
|
|
||||||
# bail out if no storage repositories are found
|
# bail out if no storage repositories are found
|
||||||
if [[ ${#storages[@]} -eq 0 ]]; then
|
if [[ ${#storages[@]} -eq 0 ]]; then
|
||||||
echo "No storage repositories found, can't import VM"
|
echo "No storage repositories found, can't import VM"
|
||||||
echo "Create SR and try again. More information: https://xcp-ng.org/docs/storage.html"
|
echo "Create SR and try again. More information: https://xcp-ng.org/docs/storage.html"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Which storage repository should the VM use?"
|
echo "Which storage repository should the VM use?"
|
||||||
echo "default will attempt to use pool default SR"
|
echo "default will attempt to use pool default SR"
|
||||||
echo
|
echo
|
||||||
local PS3="Pick a number. CTRL+C to exit: "
|
local PS3="Pick a number. CTRL+C to exit: "
|
||||||
select storage in "${storages[@]}" "default"
|
select storage in "${storages[@]}" "default"; do
|
||||||
do
|
# get only the storage repository uuid which we need later on when importing image
|
||||||
# get only the storage repository uuid which we need later on when importing image
|
read -r -a storage_split <<<"$storage"
|
||||||
read -r -a storage_split <<< "$storage"
|
storageuuid=${storage_split[0]}
|
||||||
storageuuid=${storage_split[0]}
|
|
||||||
|
|
||||||
# print a menu where to choose storage from
|
# print a menu where to choose storage from
|
||||||
case $storage in
|
case $storage in
|
||||||
default)
|
default)
|
||||||
# this value is handled during import if set to default
|
# this value is handled during import if set to default
|
||||||
sruuid=default
|
sruuid=default
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
# save storage uuid for later
|
# save storage uuid for later
|
||||||
sruuid=$storageuuid
|
sruuid=$storageuuid
|
||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function NetworkSettings {
|
function NetworkSettings {
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
ipregex="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
|
ipregex="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Set network settings for VM. Leave IP-address as blank to use DHCP"
|
echo "Set network settings for VM. Leave IP-address as blank to use DHCP"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# read ip address from user input. dhcp is default if left empty
|
# read ip address from user input. dhcp is default if left empty
|
||||||
read -r -p "IP address: " ipaddress
|
read -r -p "IP address: " ipaddress
|
||||||
ipaddress=${ipaddress:-dhcp}
|
ipaddress=${ipaddress:-dhcp}
|
||||||
|
|
||||||
# if not using dhcp, we need more information
|
# if not using dhcp, we need more information
|
||||||
if [[ "$ipaddress" != "dhcp" ]]; then
|
if [[ "$ipaddress" != "dhcp" ]]; then
|
||||||
# get network details from user and prompt again if input doesn't match ip address regex
|
# get network details from user and prompt again if input doesn't match ip address regex
|
||||||
while ! [[ $ipaddress =~ $ipregex ]]; do
|
while ! [[ $ipaddress =~ $ipregex ]]; do
|
||||||
echo "Check IP address format"
|
echo "Check IP address format"
|
||||||
read -r -p "IP address: " ipaddress
|
read -r -p "IP address: " ipaddress
|
||||||
done
|
done
|
||||||
read -r -p "Netmask [255.255.255.0]: " netmask
|
read -r -p "Netmask [255.255.255.0]: " netmask
|
||||||
netmask=${netmask:-255.255.255.0}
|
netmask=${netmask:-255.255.255.0}
|
||||||
while ! [[ $netmask =~ $ipregex ]]; do
|
while ! [[ $netmask =~ $ipregex ]]; do
|
||||||
echo "Check gateway format"
|
echo "Check gateway format"
|
||||||
read -r -p "Netmask [255.255.255.0]: " netmask
|
read -r -p "Netmask [255.255.255.0]: " netmask
|
||||||
netmask=${netmask:-255.255.255.0}
|
netmask=${netmask:-255.255.255.0}
|
||||||
done
|
done
|
||||||
read -r -p "Gateway: " gateway
|
read -r -p "Gateway: " gateway
|
||||||
while ! [[ $gateway =~ $ipregex ]] && [[ $gateway != "" ]]; do
|
while ! [[ $gateway =~ $ipregex ]] && [[ $gateway != "" ]]; do
|
||||||
echo "Check gateway format"
|
echo "Check gateway format"
|
||||||
read -r -p "Gateway: " gateway
|
read -r -p "Gateway: " gateway
|
||||||
done
|
done
|
||||||
read -r -p "DNS [8.8.8.8]: " dns
|
read -r -p "DNS [8.8.8.8]: " dns
|
||||||
dns=${dns:-8.8.8.8}
|
dns=${dns:-8.8.8.8}
|
||||||
while ! [[ $dns =~ $ipregex ]]; do
|
while ! [[ $dns =~ $ipregex ]]; do
|
||||||
echo "Check dns format"
|
echo "Check dns format"
|
||||||
read -r -p "DNS [8.8.8.8]: " dns
|
read -r -p "DNS [8.8.8.8]: " dns
|
||||||
dns=${dns:-8.8.8.8}
|
dns=${dns:-8.8.8.8}
|
||||||
done
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function VMImport {
|
function VMImport {
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Downloading and importing XVA image..."
|
echo "Downloading and importing XVA image..."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Import image. We pipe through zcat because xe vm-import should transparently decompress gzipped image, but doesn't seem to understand when stream ends when piped through curl/wget whatnot.
|
# Import image. We pipe through zcat because xe vm-import should transparently decompress gzipped image, but doesn't seem to understand when stream ends when piped through curl/wget whatnot.
|
||||||
# if SR was not defined, we leave that parameter out
|
# if SR was not defined, we leave that parameter out
|
||||||
if [[ $sruuid == "default" ]]; then
|
if [[ $sruuid == "default" ]]; then
|
||||||
uuid=$(curl "$IMAGE_URL" | zcat | xe vm-import filename=/dev/stdin)
|
uuid=$(curl "$IMAGE_URL" | zcat | xe vm-import filename=/dev/stdin)
|
||||||
else
|
else
|
||||||
uuid=$(curl "$IMAGE_URL" | zcat | xe vm-import filename=/dev/stdin sr-uuid="$sruuid")
|
uuid=$(curl "$IMAGE_URL" | zcat | xe vm-import filename=/dev/stdin sr-uuid="$sruuid")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# exit if import failed for any reason
|
# exit if import failed for any reason
|
||||||
# shellcheck disable=SC2181
|
# shellcheck disable=SC2181
|
||||||
if [[ $? != "0" ]]; then
|
if [[ $? != "0" ]]; then
|
||||||
echo "Import failed"
|
echo "Import failed"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
echo "Import complete"
|
echo "Import complete"
|
||||||
|
|
||||||
# no network interface included in the image, we need to create one based on network uuid set by user earlier
|
# no network interface included in the image, we need to create one based on network uuid set by user earlier
|
||||||
xe vif-create network-uuid="$vifuuid" vm-uuid="$uuid" device=0 >/dev/null
|
xe vif-create network-uuid="$vifuuid" vm-uuid="$uuid" device=0 >/dev/null
|
||||||
|
|
||||||
# VM startup script reads network details from xenstore and configures interface based on that so set values based on user input earlier
|
# VM startup script reads network details from xenstore and configures interface based on that so set values based on user input earlier
|
||||||
if [[ "$ipaddress" != "dhcp" ]]; then
|
if [[ "$ipaddress" != "dhcp" ]]; then
|
||||||
xe vm-param-set uuid="$uuid" xenstore-data:vm-data/ip="$ipaddress" xenstore-data:vm-data/netmask="$netmask" xenstore-data:vm-data/gateway="$gateway" xenstore-data:vm-data/dns="$dns"
|
xe vm-param-set uuid="$uuid" xenstore-data:vm-data/ip="$ipaddress" xenstore-data:vm-data/netmask="$netmask" xenstore-data:vm-data/gateway="$gateway" xenstore-data:vm-data/dns="$dns"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# remove all other boot options except disk to speed startup
|
# remove all other boot options except disk to speed startup
|
||||||
xe vm-param-remove uuid="$uuid" param-name=HVM-boot-params param-key=order
|
xe vm-param-remove uuid="$uuid" param-name=HVM-boot-params param-key=order
|
||||||
xe vm-param-set uuid="$uuid" HVM-boot-params:"order=c"
|
xe vm-param-set uuid="$uuid" HVM-boot-params:"order=c"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Starting VM..."
|
echo "Starting VM..."
|
||||||
xe vm-start uuid="$uuid"
|
xe vm-start uuid="$uuid"
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
|
|
||||||
# loop max 300 seconds for VM to startup and xen tools to announce ip-address value
|
# loop max 300 seconds for VM to startup and xen tools to announce ip-address value
|
||||||
count=0
|
count=0
|
||||||
limit=10
|
limit=10
|
||||||
ip=$(xe vm-param-get uuid="$uuid" param-name=networks param-key=0/ip 2>/dev/null)
|
ip=$(xe vm-param-get uuid="$uuid" param-name=networks param-key=0/ip 2>/dev/null)
|
||||||
while [[ -z "$ip" ]] && [[ "$count" -lt "$limit" ]]; do
|
while [[ -z "$ip" ]] && [[ "$count" -lt "$limit" ]]; do
|
||||||
echo "Waiting for VM to start and announce it got IP-address"
|
echo "Waiting for VM to start and announce it got IP-address"
|
||||||
sleep 30
|
sleep 30
|
||||||
ip=$(xe vm-param-get uuid="$uuid" param-name=networks param-key=0/ip 2>/dev/null)
|
ip=$(xe vm-param-get uuid="$uuid" param-name=networks param-key=0/ip 2>/dev/null)
|
||||||
(( count++ ))
|
((count++))
|
||||||
done
|
done
|
||||||
|
|
||||||
# network details are needed in xenstore only during first startup so remove them at this point since VM should be running
|
# network details are needed in xenstore only during first startup so remove them at this point since VM should be running
|
||||||
if [[ "$ipaddress" != "dhcp" ]]; then
|
if [[ "$ipaddress" != "dhcp" ]]; then
|
||||||
xe vm-param-remove param-name=xenstore-data param-key=vm-data/ip uuid="$uuid" 2>/dev/null
|
xe vm-param-remove param-name=xenstore-data param-key=vm-data/ip uuid="$uuid" 2>/dev/null
|
||||||
xe vm-param-remove param-name=xenstore-data param-key=vm-data/netmask uuid="$uuid" 2>/dev/null
|
xe vm-param-remove param-name=xenstore-data param-key=vm-data/netmask uuid="$uuid" 2>/dev/null
|
||||||
xe vm-param-remove param-name=xenstore-data param-key=vm-data/gateway uuid="$uuid" 2>/dev/null
|
xe vm-param-remove param-name=xenstore-data param-key=vm-data/gateway uuid="$uuid" 2>/dev/null
|
||||||
xe vm-param-remove param-name=xenstore-data param-key=vm-data/dns uuid="$uuid" 2>/dev/null
|
xe vm-param-remove param-name=xenstore-data param-key=vm-data/dns uuid="$uuid" 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# if we got ip-address value from VM, we print how to access it...
|
# if we got ip-address value from VM, we print how to access it...
|
||||||
if [[ "$ip" != "" ]]; then
|
if [[ "$ip" != "" ]]; then
|
||||||
echo
|
echo
|
||||||
echo "VM Started successfully"
|
echo "VM Started successfully"
|
||||||
echo
|
echo
|
||||||
echo "You can access Xen Orchestra at https://$ip and via SSH at $ip"
|
echo "You can access Xen Orchestra at https://$ip and via SSH at $ip"
|
||||||
echo "Default credentials for UI: admin@admin.net/admin"
|
echo "Default credentials for UI: admin@admin.net/admin"
|
||||||
echo "Default credentials for SSH: xo/xopass"
|
echo "Default credentials for SSH: xo/xopass"
|
||||||
echo
|
echo
|
||||||
echo "Remember to change both passwords before putting VM to use!"
|
echo "Remember to change both passwords before putting VM to use!"
|
||||||
# ... and print the same without ip-address information if ip-address value was missing
|
# ... and print the same without ip-address information if ip-address value was missing
|
||||||
else
|
else
|
||||||
echo
|
echo
|
||||||
echo "VM started but we couldn't fetch it's ip-address from xentools"
|
echo "VM started but we couldn't fetch it's ip-address from xentools"
|
||||||
echo
|
echo
|
||||||
echo "Check VM status/ip-address manually. If VM started correctly, it should have Web UI and SSH accessible at it's ip-address"
|
echo "Check VM status/ip-address manually. If VM started correctly, it should have Web UI and SSH accessible at it's ip-address"
|
||||||
echo "Default credentials for UI: admin@admin.net/admin"
|
echo "Default credentials for UI: admin@admin.net/admin"
|
||||||
echo "Default credentials for SSH: xo/xopass"
|
echo "Default credentials for SSH: xo/xopass"
|
||||||
echo
|
echo
|
||||||
echo "Remember to change both passwords before putting VM to use!"
|
echo "Remember to change both passwords before putting VM to use!"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user