From f9a4b883b1dc07efc799725cd3d1378e9e1ec1ea Mon Sep 17 00:00:00 2001 From: ronivay Date: Thu, 17 Sep 2020 12:38:02 +0300 Subject: [PATCH] introduce an appliance option --- README.md | 23 ++++++- xo-appliance.sh | 165 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+), 1 deletion(-) create mode 100755 xo-appliance.sh diff --git a/README.md b/README.md index 25d3015..c17f09c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # In a nutshell -This repo consist of script to install and update [Xen Orchestra](https://xen-orchestra.com/#!/) for CentOS 8/Ubuntu 18/Debian 10 +This repo consist of script to install and update [Xen Orchestra](https://xen-orchestra.com/#!/) for CentOS 8/Ubuntu 18/Debian 10. If you find it difficult to create a VM on your fresh Xenserver/XCP-ng installation, take a look at the appliance method from the end of this README. Installation is done using latest xo-server and xo-web sources by default. With this method Xen-Orchestra has all features unlocked which are normally available only with monthly fee. @@ -124,3 +124,24 @@ Debian/Ubuntu: - cifs-utils - gnupg (debian 10) ``` + +# Appliance + +If you need to import an appliance directly to your host, you may use xo-appliance.sh script for this. It'll download a prebuilt image which has Xen Orchestra and XenOrchestraInstallerUpdater installed. + +Run on your Xenserver/XCP-ng host as root: + +``` +curl https://raw.githubusercontent.com/ronivay/XenOrchestraInstallerUpdater/master/xo-appliance.sh | bash +``` + +Default username for UI is admin@admin.net with password admin + +SSH is accessible with username xo with password xopass + +Remember to change both password before putting the VM to actual use. + +Xen Orchestra is installed to /opt/xo, it uses self-signed certificates from /opt/ssl which you can replace if you wish. Installation script is at /opt/XenOrchestraInstallerUpdater which you can use to update existing installation in the future. + +This image is updated weekly. Latest build date and MD5 checksum can be checked from https://xo-appliance.yawn.fi/downloads/image.txt + diff --git a/xo-appliance.sh b/xo-appliance.sh new file mode 100755 index 0000000..bbe17de --- /dev/null +++ b/xo-appliance.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +IMAGE_URL="https://xo-appliance.yawn.fi/downloads/image.xva" + +function OSCheck { + set -e + + if [[ -z $(which xe 2>/dev/null) ]]; then + echo "this scripts needs xe command. make sure you're on xenserver/xcp-ng host" + exit 1 + fi + + echo + echo "Welcome. This script will import a working Xen Orchestra appliance built 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 { + + set +e + + IFS=$'\n' read -r -d '' -a networks <<< "$(xe network-list | grep "uuid\|name-label" | cut -d':' -f2 | sed 's/^ //' | paste - -)" + + + echo "Which network should the VM use?" + echo + local PS3="Pick a number. CTRL+C to exit: " + select network in "${networks[@]}" + do + read -a network_split <<< "$network" + networkuuid=${network_split[0]} + networkname=${network_split[@]:1} + + case $network in + *) + vifuuid="$networkuuid" + break + ;; + esac + done + +} + +function NetworkSettings { + + set -e + + ipregex="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$" + + echo + echo "Set network settings for VM. Leave IP-address as blank to use DHCP" + echo + + read -p "IP address: " ipaddress + ipaddress=${ipaddress:-dhcp} + + if [[ "$ipaddress" != "dhcp" ]]; then + if ! [[ $ipaddress =~ $ipregex ]]; then + echo "Check ip-address format" + exit 1 + fi + read -p "Netmask [255.255.255.0]: " netmask + netmask=${netmask:-255.255.255.0} + if ! [[ $netmask =~ $ipregex ]]; then + echo "Check netmask format" + exit 1 + fi + read -p "Gateway: " gateway + if [[ $gateway != "" ]]; then + if ! [[ $gateway =~ $ipregex ]]; then + echo "Check gateway format" + exit 1 + fi + fi + read -p "DNS [8.8.8.8]: " dns + dns=${dns:-8.8.8.8} + if ! [[ $dns =~ $ipregex ]]; then + echo "Check dns format" + exit 1 + fi + + fi + +} + +function VMImport { + + set -e + + echo + echo "Downloading and importing XVA image..." + echo + + uuid=$(curl "$IMAGE_URL" | xe vm-import filename=/dev/stdin 2>/dev/null) + + if [[ $? != "0" ]]; then + echo "Import failed" + exit 1 + fi + echo + echo "Import complete" + + xe vif-create network-uuid=$vifuuid vm-uuid=$uuid device=0 >/dev/null + + 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 + fi + + 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" + + echo + echo "Starting VM..." + xe vm-start uuid=$uuid + + set +e + + count=0 + limit=10 + ip=$(xe vm-param-get uuid=$uuid param-name=networks param-key=0/ip 2>/dev/null) + while [[ -z "$ip" ]] && [[ "$count" -lt "$limit" ]]; do + echo "Waiting for VM to start and announce it got IP-address" + sleep 30 + ip=$(xe vm-param-get uuid=$uuid param-name=networks param-key=0/ip 2>/dev/null) + (( count++ )) + done + + 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/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/dns uuid=$uuid 2>/dev/null + fi + + if [[ $ip != "" ]]; then + echo + echo "VM Started successfully" + echo + echo "You can access Xen Orchestra at https://$ip and via SSH at $ip" + echo "Default credentials for UI: admin@admin/admin" + echo "Default credentials for SSH: xo/xopass" + echo + echo "Remember to change both passwords before putting VM to use!" + else + echo + echo "VM started but we couldn't fetch it's ip-address from xentools" + 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 "Default credentials for UI: admin@admin/admin" + echo "Default credentials for SSH: xo/xopass" + echo + echo "Remember to change both passwords before putting VM to use!" + fi + +} + +OSCheck +NetworkChoose +NetworkSettings +VMImport