From 85a588e382a5eb6fbd8769fbe7ed19e2d73dcb4b Mon Sep 17 00:00:00 2001 From: naichuans Date: Wed, 31 May 2017 06:32:43 +0000 Subject: [PATCH] os-xenapi: remove install dependence with devstack 2: Part two: configure ubuntu DomU VM and introduce install-devstack-xen.sh Move tools/xen from devstack to os-xenapi which will be the center place to hold some XenServer/XenAPI specify source code. This part is used to configure a DomU VM and install devstack on domu VM Change-Id: I20f4663d987266d6ff6d57c5eb3c4447d51f9162 --- .../install-devstack-xen.sh | 224 +++++------ {install => tools/install}/common/functions | 61 +-- .../install}/conf/ubuntupreseed.cfg | 0 {install => tools/install}/conf/xenrc | 25 +- .../install}/create_ubuntu_template.sh | 7 +- tools/install/devstack/install_devstack.sh | 348 ++++++++++++++++++ .../install}/scripts/install-os-vpx.sh | 0 .../scripts/install_ubuntu_template.sh | 2 +- tools/install/scripts/manage-vdi | 97 +++++ {install => tools/install}/scripts/on_exit.sh | 0 .../scripts/persist_domU_interfaces.sh | 107 ++++++ tools/install/scripts/prepare_guest.sh | 122 ++++++ .../install/scripts/prepare_guest_template.sh | 99 +++++ .../install}/scripts/ubuntu_latecommand.sh | 0 .../install}/scripts/uninstall-os-vpx.sh | 0 tools/install_on_xen_host.sh | 201 ++++++++++ 16 files changed, 1097 insertions(+), 196 deletions(-) rename install-devstack-xen.sh => tools/install-devstack-xen.sh (73%) mode change 100644 => 100755 rename {install => tools/install}/common/functions (85%) rename {install => tools/install}/conf/ubuntupreseed.cfg (100%) rename {install => tools/install}/conf/xenrc (84%) rename {install => tools/install}/create_ubuntu_template.sh (96%) create mode 100755 tools/install/devstack/install_devstack.sh rename {install => tools/install}/scripts/install-os-vpx.sh (100%) rename {install => tools/install}/scripts/install_ubuntu_template.sh (98%) create mode 100755 tools/install/scripts/manage-vdi rename {install => tools/install}/scripts/on_exit.sh (100%) create mode 100755 tools/install/scripts/persist_domU_interfaces.sh create mode 100755 tools/install/scripts/prepare_guest.sh create mode 100755 tools/install/scripts/prepare_guest_template.sh rename {install => tools/install}/scripts/ubuntu_latecommand.sh (100%) rename {install => tools/install}/scripts/uninstall-os-vpx.sh (100%) create mode 100755 tools/install_on_xen_host.sh diff --git a/install-devstack-xen.sh b/tools/install-devstack-xen.sh old mode 100644 new mode 100755 similarity index 73% rename from install-devstack-xen.sh rename to tools/install-devstack-xen.sh index c6466e4..6431dac --- a/install-devstack-xen.sh +++ b/tools/install-devstack-xen.sh @@ -37,6 +37,10 @@ optional arguments: before running any tests. The host will not be rebooted after installing the supplemental pack, so new kernels will not be picked up. + -o OS_XENAPI_SRC An URL point to a zip file for os-xenapi, This defaults to the + official os-xenapi repository. + -w WAIT_TILL_LAUNCH Set it to 1 if user want to pending on the installation until + it is done flags: -f Force SR replacement. If your XenServer has an LVM type SR, @@ -61,7 +65,8 @@ exit 1 } # Defaults for optional arguments -DEVSTACK_SRC="https://github.com/openstack-dev/devstack/archive/master.tar.gz" +DEVSTACK_SRC=${DEVSTACK_SRC:-"https://github.com/openstack-dev/devstack"} +OS_XENAPI_SRC=${OS_XENAPI_SRC:-"https://github.com/openstack/os-xenapi/archive/master.zip"} TEST_TYPE="none" FORCE_SR_REPLACEMENT="false" EXIT_AFTER_JEOS_INSTALLATION="" @@ -69,7 +74,9 @@ LOG_FILE_DIRECTORY="" JEOS_URL="" JEOS_FILENAME="" SUPP_PACK_URL="" -SCREEN_LOGDIR="/opt/stack/devstack_logs" +LOGDIR="/opt/stack/devstack_logs" +DEV_STACK_DOMU_NAME=${DEV_STACK_DOMU_NAME:-DevStackOSDomU} +WAIT_TILL_LAUNCH=1 # Get Positional arguments set +u @@ -86,7 +93,7 @@ REMAINING_OPTIONS="$#" # Get optional parameters set +e -while getopts ":t:d:fnl:j:e:s:" flag; do +while getopts ":t:d:fnl:j:e:o:s:w:" flag; do REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) case "$flag" in t) @@ -122,12 +129,29 @@ while getopts ":t:d:fnl:j:e:s:" flag; do SUPP_PACK_URL="$OPTARG" REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) ;; + o) + OS_XENAPI_SRC="$OPTARG" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + w) + WAIT_TILL_LAUNCH="$OPTARG" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; \?) print_usage_and_die "Invalid option -$OPTARG" ;; esac done + set -e +if [ "$TEST_TYPE" != "none" ] && [ $WAIT_TILL_LAUNCH -ne 1 ]; then + echo "WARNING: You can't perform a test even before the insallation done, force set WAIT_TILL_LAUNCH to 1" + WAIT_TILL_LAUNCH=1 +fi + +if [ "$TEST_TYPE" != "none" ] && [ "$EXIT_AFTER_JEOS_INSTALLATION" = "true" ]; then + print_usage_and_die "ERROR: You can't perform a test without a devstack invironment, exit" +fi # Make sure that all options processed if [ "0" != "$REMAINING_OPTIONS" ]; then @@ -152,6 +176,8 @@ XENSERVER_PASS: $XENSERVER_PASS PRIVKEY: $PRIVKEY TEST_TYPE: $TEST_TYPE DEVSTACK_SRC: $DEVSTACK_SRC +OS_XENAPI_SRC: $OS_XENAPI_SRC + FORCE_SR_REPLACEMENT: $FORCE_SR_REPLACEMENT JEOS_URL: ${JEOS_URL:-template will not be imported} @@ -175,6 +201,12 @@ function assert_tool_exists() { fi } +DEFAULT_SR_ID=$(on_xenserver < \ + stack@\$GUEST_IP "tar --ignore-failed-read -czf - ${LOGDIR}/* /opt/stack/tempest/*.xml" > \ /root/artifacts/domU.tgz < /dev/null || true fi tar --ignore-failed-read -czf /root/artifacts/dom0.tgz /var/log/messages* /var/log/xensource* /var/log/SM* || true @@ -284,48 +317,6 @@ else exit 1 fi -echo -n "Verify XenServer has an ext type default SR..." -copy_logs_on_failure on_xenserver << END_OF_SR_OPERATIONS -set -eu - -# Verify the host is suitable for devstack -defaultSR=\$(xe pool-list params=default-SR minimal=true) -currentSrType=\$(xe sr-param-get uuid=\$defaultSR param-name=type) -if [ "\$currentSrType" != "ext" -a "\$currentSrType" != "nfs" -a "\$currentSrType" != "ffs" -a "\$currentSrType" != "file" ]; then - if [ "true" == "$FORCE_SR_REPLACEMENT" ]; then - echo "" - echo "" - echo "Trying to replace the default SR with an EXT SR" - - pbd_uuid=\`xe pbd-list sr-uuid=\$defaultSR minimal=true\` - host_uuid=\`xe pbd-param-get uuid=\$pbd_uuid param-name=host-uuid\` - use_device=\`xe pbd-param-get uuid=\$pbd_uuid param-name=device-config param-key=device\` - - # Destroy the existing SR - xe pbd-unplug uuid=\$pbd_uuid - xe sr-destroy uuid=\$defaultSR - - sr_uuid=\`xe sr-create content-type=user host-uuid=\$host_uuid type=ext device-config:device=\$use_device shared=false name-label="Local storage"\` - pool_uuid=\`xe pool-list minimal=true\` - xe pool-param-set default-SR=\$sr_uuid uuid=\$pool_uuid - xe pool-param-set suspend-image-SR=\$sr_uuid uuid=\$pool_uuid - xe sr-param-add uuid=\$sr_uuid param-name=other-config i18n-key=local-storage - exit 0 - fi - echo "" - echo "" - echo "ERROR: The xenserver host must have an EXT3/NFS/FFS/File SR as the default SR" - echo "Use the -f flag to destroy the current default SR and create a new" - echo "ext type default SR." - echo "" - echo "WARNING: This will destroy your actual default SR !" - echo "" - - exit 1 -fi -END_OF_SR_OPERATIONS -echo "OK" - echo -n "Get the IP address of XenServer..." XENSERVER_IP=$(on_xenserver << GET_XENSERVER_IP xe host-list params=address minimal=true @@ -349,29 +340,13 @@ SUPP_PACK sleep 10m fi -echo -n "Hack ISCSISR.py on XenServer (original saved to /root/ISCSISR.py.orig)..." -on_xenserver << HACK_ISCSI_SR -set -eu - -iscsi_target_file="" -for candidate_file in "/opt/xensource/sm/ISCSISR.py" "/usr/lib64/xcp-sm/ISCSISR.py"; do - if [ -e "\$candidate_file" ]; then - iscsi_target_file=\$candidate_file - fi -done -if [ -n "\$iscsi_target_file" ]; then - if ! [ -e "/root/ISCSISR.py.orig" ]; then - cp \$iscsi_target_file /root/ISCSISR.py.orig - fi - sed -e "s/'phy'/'aio'/g" /root/ISCSISR.py.orig > \$iscsi_target_file -fi -HACK_ISCSI_SR -echo "OK" - if [ -n "$JEOS_URL" ]; then echo "(re-)importing JeOS template" on_xenserver << END_OF_JEOS_IMPORT set -eu + +mkdir -p $TMP_TEMPLATE_DIR + JEOS_TEMPLATE="\$(xe template-list name-label="jeos_template_for_devstack" --minimal)" if [ -n "\$JEOS_TEMPLATE" ]; then @@ -379,12 +354,12 @@ if [ -n "\$JEOS_TEMPLATE" ]; then xe template-uninstall template-uuid="\$JEOS_TEMPLATE" force=true > /dev/null fi -rm -f /root/jeos-for-devstack.xva -echo " downloading $JEOS_URL to /root/jeos-for-devstack.xva" -wget -qO /root/jeos-for-devstack.xva "$JEOS_URL" -echo " importing /root/jeos-for-devstack.xva" -xe vm-import filename=/root/jeos-for-devstack.xva -rm -f /root/jeos-for-devstack.xva +rm -f $TMP_TEMPLATE_DIR/jeos-for-devstack.xva +echo " downloading $JEOS_URL to $TMP_TEMPLATE_DIR/jeos-for-devstack.xva" +wget -qO $TMP_TEMPLATE_DIR/jeos-for-devstack.xva "$JEOS_URL" +echo " importing $TMP_TEMPLATE_DIR/jeos-for-devstack.xva" +xe vm-import filename=$TMP_TEMPLATE_DIR/jeos-for-devstack.xva +rm -rf $TMP_TEMPLATE_DIR echo " verify template imported" JEOS_TEMPLATE="\$(xe template-list name-label="jeos_template_for_devstack" --minimal)" if [ -z "\$JEOS_TEMPLATE" ]; then @@ -396,35 +371,20 @@ END_OF_JEOS_IMPORT echo "OK" fi -if [ -e $DEVSTACK_SRC ]; then -copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS -set -eu +TMPDIR=$(echo "mktemp -d" | on_xenserver) -mkdir -p $TMPDIR/devstack-local -END_OF_XENSERVER_COMMANDS - scp $_SSH_OPTIONS -r $DEVSTACK_SRC/* "root@$XENSERVER:$TMPDIR/devstack-local" -else -copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS -set -exu - -cd $TMPDIR - -wget "$DEVSTACK_SRC" -O _devstack.tgz -tar -xzf _devstack.tgz -cd devstack* -END_OF_XENSERVER_COMMANDS -fi - -# set nounset for $NOVA_CONF set +u - +DOM0_OPT_DIR=$TMPDIR/domU +DOM0_OS_API_UNZIP_DIR="$DOM0_OPT_DIR/os-xenapi" +DOM0_OS_API_DIR="$DOM0_OS_API_UNZIP_DIR/os-xenapi-*" +DOM0_TOOL_DIR="$DOM0_OS_API_DIR/tools" +DOM0_INSTALL_DIR="$DOM0_TOOL_DIR/install" copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS -set -exu - -cd $TMPDIR - -cd devstack* - + mkdir $DOM0_OPT_DIR + cd $DOM0_OPT_DIR + wget --no-check-certificate "$OS_XENAPI_SRC" + unzip -o master.zip -d $DOM0_OS_API_UNZIP_DIR + cd $DOM0_INSTALL_DIR cat << LOCALCONF_CONTENT_ENDS_HERE > local.conf # ``local.conf`` is a user-maintained settings file that is sourced from ``stackrc``. # This gives it the ability to override any variables set in ``stackrc``. @@ -448,7 +408,6 @@ SWIFT_HASH="66a3d6b56c1f479c8b4e70ab5c2000f5" # Nice short names, so we could export an XVA VM_BRIDGE_OR_NET_NAME="osvmnet" PUB_BRIDGE_OR_NET_NAME="ospubnet" -XEN_INT_BRIDGE_OR_NET_NAME="osintnet" # Do not use secure delete CINDER_SECURE_DELETE=False @@ -457,15 +416,13 @@ CINDER_SECURE_DELETE=False VIRT_DRIVER=xenserver # OpenStack VM settings -OSDOMU_VDI_GB=30 -OSDOMU_MEM_MB=8192 - TERMINATE_TIMEOUT=90 BUILD_TIMEOUT=600 # DevStack settings -LOGFILE=${SCREEN_LOGDIR}/stack.log -SCREEN_LOGDIR=${SCREEN_LOGDIR} + +LOGDIR=${LOGDIR} +LOGFILE=${LOGDIR}/stack.log UBUNTU_INST_HTTP_HOSTNAME=archive.ubuntu.com UBUNTU_INST_HTTP_DIRECTORY=/ubuntu @@ -487,7 +444,6 @@ ENABLE_TENANT_VLANS=True Q_ML2_TENANT_NETWORK_TYPE=vlan ML2_VLAN_RANGES="physnet1:1100:1200" -PUB_IP=172.24.4.1 SUBNETPOOL_PREFIX_V4=192.168.10.0/24 NETWORK_GATEWAY=192.168.10.1 @@ -500,43 +456,35 @@ PUBLIC_INTERFACE=eth2 [DEFAULT] disk_allocation_ratio = 2.0 -# Neutron ovs bridge mapping -[[post-config|\\\$NEUTRON_CORE_PLUGIN_CONF]] -[ovs] -bridge_mappings = physnet1:br-eth1,public:br-ex - LOCALCONF_CONTENT_ENDS_HERE -# unset nounset for $NOVA_CONF -set -u - -# XenServer doesn't have nproc by default - but it's used by stackrc. -# Fake it up if one doesn't exist -set +e -which nproc > /dev/null 2>&1 -if [ \$? -ne 0 ]; then - cat >> /usr/local/bin/nproc << END_OF_NPROC -#!/bin/bash -cat /proc/cpuinfo | grep -c processor -END_OF_NPROC - chmod +x /usr/local/bin/nproc +# begin installation process +cd $DOM0_TOOL_DIR +if [ $FORCE_SR_REPLACEMENT = 'true' ]; then + ./install_on_xen_host.sh -d $DEVSTACK_SRC -l $LOGDIR -w $WAIT_TILL_LAUNCH -f +else + ./install_on_xen_host.sh -d $DEVSTACK_SRC -l $LOGDIR -w $WAIT_TILL_LAUNCH fi -cd tools/xen -EXIT_AFTER_JEOS_INSTALLATION="$EXIT_AFTER_JEOS_INSTALLATION" ./install_os_domU.sh END_OF_XENSERVER_COMMANDS +on_xenserver << END_OF_RM_TMPDIR + +#delete install dir +rm $TMPDIR -rf +END_OF_RM_TMPDIR + if [ "$TEST_TYPE" == "none" ]; then exit 0 fi # Run tests +DOM0_FUNCTION_DIR="$DOM0_OS_API_DIR/install/common" copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS -set -exu -cd $TMPDIR -cd devstack* -GUEST_IP=\$(. "tools/xen/functions" && find_ip_by_name DevStackOSDomU 0) +set -exu + +GUEST_IP=\$(. $DOM0_FUNCTION_DIR/functions && find_ip_by_name $DEV_STACK_DOMU_NAME 0) ssh -q \ -o Batchmode=yes \ -o StrictHostKeyChecking=no \ diff --git a/install/common/functions b/tools/install/common/functions similarity index 85% rename from install/common/functions rename to tools/install/common/functions index 933062a..42bb35d 100755 --- a/install/common/functions +++ b/tools/install/common/functions @@ -16,52 +16,10 @@ function die_with_error { exit 1 } -function xapi_plugin_location { - for PLUGIN_DIR in "/etc/xapi.d/plugins/" "/usr/lib/xcp/plugins/" "/usr/lib/xapi/plugins" "/usr/lib64/xapi/plugins"; do - if [ -d $PLUGIN_DIR ]; then - echo $PLUGIN_DIR - return 0 - fi - done - return 1 -} - -function create_directory_for_kernels { - if [ -d "/boot/guest" ]; then - echo "INFO: /boot/guest directory already exists, using that" >&2 - else - local local_path - local_path="$(get_local_sr_path)/os-guest-kernels" - mkdir -p $local_path - ln -s $local_path /boot/guest - fi -} - -function create_directory_for_images { - if [ -d "/images" ]; then - echo "INFO: /images directory already exists, using that" >&2 - else - local local_path - local_path="$(get_local_sr_path)/os-images" - mkdir -p $local_path - ln -s $local_path /images - fi -} - function get_local_sr { xe pool-list params=default-SR minimal=true } -function get_local_sr_path { - pbd_path="/var/run/sr-mount/$(get_local_sr)" - pbd_device_config_path=`xe pbd-list sr-uuid=$(get_local_sr) params=device-config | grep " path: "` - if [ -n "$pbd_device_config_path" ]; then - pbd_uuid=`xe pbd-list sr-uuid=$(get_local_sr) minimal=true` - pbd_path=`xe pbd-param-get uuid=$pbd_uuid param-name=device-config param-key=path || echo ""` - fi - echo $pbd_path -} - function find_ip_by_name { local guest_name="$1" local interface="$2" @@ -273,6 +231,25 @@ function set_vm_memory { uuid=$vm } +function set_vm_disk { + local vm_name_label + local vm_disk_size + + vm_name_label="$1" + vm_disk_size="$2" + + local vm_uuid + local vm_vbd + local vm_vdi + + vm_uuid=$(xe vm-list name-label=$vm_name_label --minimal) + vm_vbd=$(xe vbd-list vm-uuid=$vm_uuid device=xvda --minimal) + vm_vdi=$(xe vdi-list vbd-uuids=$vm_vbd --minimal) + + xe vdi-resize uuid=$vm_vdi disk-size=$((vm_disk_size * 1024 * 1024 * 1024)) +} + + function max_vcpus { local vm_name_label diff --git a/install/conf/ubuntupreseed.cfg b/tools/install/conf/ubuntupreseed.cfg similarity index 100% rename from install/conf/ubuntupreseed.cfg rename to tools/install/conf/ubuntupreseed.cfg diff --git a/install/conf/xenrc b/tools/install/conf/xenrc similarity index 84% rename from install/conf/xenrc rename to tools/install/conf/xenrc index c2085b3..efb1ec8 100644 --- a/install/conf/xenrc +++ b/tools/install/conf/xenrc @@ -6,21 +6,13 @@ # # Name of this guest -GUEST_NAME=${GUEST_NAME:-CleanUbuntuVM} +GUEST_NAME=${GUEST_NAME:-UbuntuVM} # Template cleanup CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false} TNAME="jeos_template_for_ubuntu" SNAME_TEMPLATE="jeos_snapshot_for_ubuntu" -# Devstack now contains many components. 4GB ram is not enough to prevent -# swapping and memory fragmentation - the latter of which can cause failures -# such as blkfront failing to plug a VBD and lead to random test fails. -# -# Set to 6GB so an 8GB XenServer VM can have a 1GB Dom0 and leave 1GB for VMs -OSDOMU_MEM_MB=6144 -OSDOMU_VDI_GB=8 - # Size of image VDI_MB=${VDI_MB:-5000} @@ -29,11 +21,11 @@ VDI_MB=${VDI_MB:-5000} # such as blkfront failing to plug a VBD and lead to random test fails. # # Set to 6GB so an 8GB XenServer VM can have a 1GB Dom0 and leave 1GB for VMs -CLEAN_VM_MEM_MB=6144 -CLEAN_VM_VDI_GB=8 +VM_MEM_MB=${VM_MEM_MB:-6144} +VM_VDI_GB=${VM_VDI_GB:-30} # VM Password -GUEST_PASSWORD=${GUEST_PASSWORD:-secret} +GUEST_PASSWORD=${GUEST_PASSWORD:-admin} # Extracted variables for OpenStack VM network device numbers. # Make sure they form a continuous sequence starting from 0 @@ -105,10 +97,17 @@ DOMZERO_USER=domzero # Get the management network from the XS installation VM_BRIDGE_OR_NET_NAME="OpenStack VM Network" PUB_BRIDGE_OR_NET_NAME="OpenStack Public Network" -XEN_INT_BRIDGE_OR_NET_NAME="OpenStack VM Integration Network" # Extracted variables for OpenStack VM network device numbers. # Make sure they form a continuous sequence starting from 0 MGT_DEV_NR=0 VM_DEV_NR=1 PUB_DEV_NR=2 + +# VM Network +VM_IP=${VM_IP:-10.255.255.255} +VM_NETMASK=${VM_NETMASK:-255.255.255.0} + +# Public network +PUB_IP=${PUB_IP:-172.24.4.1} +PUB_NETMASK=${PUB_NETMASK:-255.255.255.0} diff --git a/install/create_ubuntu_template.sh b/tools/install/create_ubuntu_template.sh similarity index 96% rename from install/create_ubuntu_template.sh rename to tools/install/create_ubuntu_template.sh index 7ed6b37..5efcb0f 100755 --- a/install/create_ubuntu_template.sh +++ b/tools/install/create_ubuntu_template.sh @@ -192,10 +192,13 @@ else echo "the template has already exist" fi template_uuid=$(xe_min template-list name-label="$TNAME") -echo "$template_uuid" exist_val=$(xe template-param-get uuid=$template_uuid param-name=PV-args) -echo "$exist_val" if [ -n "$exist_val" ]; then xe template-param-set uuid=$template_uuid PV-args="" fi +set +x +echo "################################################################################" +echo "" +echo "Template create done!" +echo "################################################################################" diff --git a/tools/install/devstack/install_devstack.sh b/tools/install/devstack/install_devstack.sh new file mode 100755 index 0000000..78e3771 --- /dev/null +++ b/tools/install/devstack/install_devstack.sh @@ -0,0 +1,348 @@ +#!/bin/bash + +# This script is run by install_on_xen_host.sh +# +# It modifies the ubuntu image created by install_on_xen_host.sh +# and previously moodified by prepare_guest_template.sh +# +# This script is responsible for: +# - creates a DomU VM +# - creating run.sh, to run the code on DomU boot +# +# by install_on_xen_host.sh + +# Exit on errors +set -o errexit +# Echo commands +set -o xtrace + +# This directory +THIS_DIR=$(cd $(dirname "$0") && pwd) +TOP_DIR="$THIS_DIR/../" +SCRIPT_DIR="$TOP_DIR/scripts" +COMM_DIR="$TOP_DIR/common" +CONF_DIR="$TOP_DIR/conf" + +# Include onexit commands +. $SCRIPT_DIR/on_exit.sh + +# xapi functions +. $COMM_DIR/functions + +# Source params +source $CONF_DIR/xenrc + +# Defaults for optional arguments +DEVSTACK_SRC=${DEVSTACK_SRC:-"https://github.com/openstack-dev/devstack"} +LOGDIR="/opt/stack/devstack_logs" + +# Number of options passed to this script +REMAINING_OPTIONS="$#" +# Get optional parameters +set +e +while getopts ":d:l:" flag; do + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + case "$flag" in + d) + DEVSTACK_SRC="$DEVSTACK_SRC" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + l) + LOGDIR="$LOGDIR" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + \?) + print_usage_and_die "Invalid option -$OPTARG" + ;; + esac +done +set -e + +# Make sure that all options processed +if [ "0" != "$REMAINING_OPTIONS" ]; then + print_usage_and_die "ERROR: some arguments were not recognised!" +fi + +# +# Prepare VM for DevStack +# + +# +# Configure Networking +# + +MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true` +MGT_BRIDGE_OR_NET_NAME=`xe network-list uuid=$MGT_NETWORK params=bridge minimal=true` + +setup_network "$VM_BRIDGE_OR_NET_NAME" +setup_network "$MGT_BRIDGE_OR_NET_NAME" +setup_network "$PUB_BRIDGE_OR_NET_NAME" + +if parameter_is_specified "FLAT_NETWORK_BRIDGE"; then + if [ "$(bridge_for "$VM_BRIDGE_OR_NET_NAME")" != "$(bridge_for "$FLAT_NETWORK_BRIDGE")" ]; then + cat >&2 << EOF +ERROR: FLAT_NETWORK_BRIDGE is specified in localrc file, and either no network +found on XenServer by searching for networks by that value as name-label or +bridge name or the network found does not match the network specified by +VM_BRIDGE_OR_NET_NAME. Please check your localrc file. +EOF + exit 1 + fi +fi + +if ! xenapi_is_listening_on "$MGT_BRIDGE_OR_NET_NAME"; then + cat >&2 << EOF +ERROR: XenAPI does not have an assigned IP address on the management network. +please review your XenServer network configuration / localrc file. +EOF + exit 1 +fi + +HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME") + +# Also, enable ip forwarding in rc.local, since the above trick isn't working +if ! grep -q "echo 1 >/proc/sys/net/ipv4/ip_forward" /etc/rc.local; then + echo "echo 1 >/proc/sys/net/ipv4/ip_forward" >> /etc/rc.local +fi +# Enable ip forwarding at runtime as well +echo 1 > /proc/sys/net/ipv4/ip_forward + +HOST_IP=$(xenapi_ip_on "$MGT_BRIDGE_OR_NET_NAME") + +#install the previous ubuntu VM + +vm_exist=$(xe vm-list name-label="$DEV_STACK_DOMU_NAME" --minimal) +if [ "$vm_exist" != "" ] +then + echo "Uninstall the previous VM" + xe vm-uninstall vm="$DEV_STACK_DOMU_NAME" force=true +fi + +echo "Install a new ubuntu VM according to previous template" + +vm_uuid=$(xe vm-install template="$TNAME" new-name-label="$DEV_STACK_DOMU_NAME") + +xe vm-param-set other-config:os-vpx=true uuid="$vm_uuid" + +# Install XenServer tools, and other such things +$SCRIPT_DIR/prepare_guest_template.sh "$DEV_STACK_DOMU_NAME" + +# Set virtual machine parameters +set_vm_memory "$DEV_STACK_DOMU_NAME" "$VM_MEM_MB" + +# Max out VCPU count for better performance +max_vcpus "$DEV_STACK_DOMU_NAME" + +# Wipe out all network cards +destroy_all_vifs_of "$DEV_STACK_DOMU_NAME" + +# Add only one interface to prepare the guest template +add_interface "$DEV_STACK_DOMU_NAME" "$MGT_BRIDGE_OR_NET_NAME" "0" + +# start the VM to run the prepare steps +xe vm-start vm="$DEV_STACK_DOMU_NAME" + +# Wait for prep script to finish and shutdown system +wait_for_VM_to_halt "$DEV_STACK_DOMU_NAME" + +## Setup network cards +# Wipe out all +destroy_all_vifs_of "$DEV_STACK_DOMU_NAME" +# Tenant network +add_interface "$DEV_STACK_DOMU_NAME" "$VM_BRIDGE_OR_NET_NAME" "$VM_DEV_NR" +# Management network +add_interface "$DEV_STACK_DOMU_NAME" "$MGT_BRIDGE_OR_NET_NAME" "$MGT_DEV_NR" +# Public network +add_interface "$DEV_STACK_DOMU_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR" + +# +# persistant the VM's interfaces +# +$SCRIPT_DIR/persist_domU_interfaces.sh "$DEV_STACK_DOMU_NAME" + + +FLAT_NETWORK_BRIDGE="${FLAT_NETWORK_BRIDGE:-$(bridge_for "$VM_BRIDGE_OR_NET_NAME")}" +append_kernel_cmdline "$DEV_STACK_DOMU_NAME" "flat_network_bridge=${FLAT_NETWORK_BRIDGE}" + +# Add a separate xvdb, if it was requested +if [[ "0" != "$XEN_XVDB_SIZE_GB" ]]; then + vm=$(xe vm-list name-label="$DEV_STACK_DOMU_NAME" --minimal) + + # Add a new disk + localsr=$(get_local_sr) + extra_vdi=$(xe vdi-create \ + name-label=xvdb-added-by-devstack \ + virtual-size="${XEN_XVDB_SIZE_GB}GiB" \ + sr-uuid=$localsr type=user) + xe vbd-create vm-uuid=$vm vdi-uuid=$extra_vdi device=1 +fi + +# +# Run DevStack VM +# +xe vm-start vm="$DEV_STACK_DOMU_NAME" + +# Get hold of the Management IP of OpenStack VM +OS_VM_MANAGEMENT_ADDRESS=$MGT_IP +if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then + OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $DEV_STACK_DOMU_NAME $MGT_DEV_NR) +fi + +# Create an ssh-keypair, and set it up for dom0 user +rm -f /root/dom0key /root/dom0key.pub +ssh-keygen -f /root/dom0key -P "" -C "dom0" +DOMID=$(get_domid "$DEV_STACK_DOMU_NAME") + +xenstore-write /local/domain/$DOMID/authorized_keys/$DOMZERO_USER "$(cat /root/dom0key.pub)" +xenstore-chmod -u /local/domain/$DOMID/authorized_keys/$DOMZERO_USER r$DOMID + +function run_on_appliance { + ssh \ + -i /root/dom0key \ + -o UserKnownHostsFile=/dev/null \ + -o StrictHostKeyChecking=no \ + -o BatchMode=yes \ + "$DOMZERO_USER@$OS_VM_MANAGEMENT_ADDRESS" "$@" +} + +# Wait until we can log in to the appliance +while ! run_on_appliance true; do + sleep 1 +done + +# Remove authenticated_keys updater cronjob +echo "" | run_on_appliance crontab - + +# Generate a passwordless ssh key for domzero user +echo "ssh-keygen -f /home/$DOMZERO_USER/.ssh/id_rsa -C $DOMZERO_USER@appliance -N \"\" -q" | run_on_appliance + +# Authenticate that user to dom0 +run_on_appliance cat /home/$DOMZERO_USER/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys + +set +x +echo "################################################################################" +echo "" +echo "VM configuration done!" +echo "################################################################################" + + +xe vm-shutdown vm="$DEV_STACK_DOMU_NAME" +wait_for_VM_to_halt "$DEV_STACK_DOMU_NAME" +# +# Mount the VDI +# +echo "check vdi mapping" +STAGING_DIR=$($SCRIPT_DIR/manage-vdi open $DEV_STACK_DOMU_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*") +add_on_exit "$SCRIPT_DIR/manage-vdi close $DEV_STACK_DOMU_NAME 0 1" +# Make sure we have a stage +if [ ! -d $STAGING_DIR/etc ]; then + echo "ERROR:ct properly set up!" + exit 1 +fi + +if [ ! -d "$STAGING_DIR/opt/stack" ]; then + echo "ERROR: scet" + exit -1 +fi + +rm -f $STAGING_DIR/opt/stack/local.conf +XENSERVER_IP=$(xe host-list params=address minimal=true) + +# Create an systemd task for devstack +cat >$STAGING_DIR/etc/systemd/system/devstack.service << EOF +[Unit] +Description=Install OpenStack by DevStack + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStartPre=/bin/rm -f /opt/stack/runsh.succeeded +ExecStart=/bin/su -c "/opt/stack/run.sh" stack +StandardOutput=tty +StandardError=tty + +[Install] +WantedBy=multi-user.target + +EOF + +if [ $? -ne 0 ]; then +echo "fatal error, install service failed." +exit 1 +fi + +# enable this service +rm -f $STAGING_DIR/etc/systemd/system/multi-user.target.wants/devstack.service +ln -s /etc/systemd/system/devstack.service $STAGING_DIR/etc/systemd/system/multi-user.target.wants/devstack.service + +# Gracefully cp only if source file/dir exists +function cp_it { + if [ -e $1 ] || [ -d $1 ]; then + cp -pRL $1 $2 + fi +} + +# Copy over your ssh keys and env if desired +cp_it ~/.ssh $STAGING_DIR/opt/stack/.ssh +cp_it ~/.ssh/id_rsa.pub $STAGING_DIR/opt/stack/.ssh/authorized_keys +cp_it ~/.gitconfig $STAGING_DIR/opt/stack/.gitconfig +cp_it ~/.vimrc $STAGING_DIR/opt/stack/.vimrc +cp_it ~/.bashrc $STAGING_DIR/opt/stack/.bashrc + + +# Configure run.sh +DOMU_STACK_DIR=/opt/stack +DOMU_DEV_STACK_DIR=$DOMU_STACK_DIR/devstack +cat <$STAGING_DIR/opt/stack/run.sh +#!/bin/bash +set -eux +( + flock -n 9 || exit 1 + + sudo chown -R stack $DOMU_STACK_DIR + + cd $DOMU_STACK_DIR + + [ -e /opt/stack/runsh.succeeded ] && rm /opt/stack/runsh.succeeded + echo \$\$ >> /opt/stack/run_sh.pid + + if [ ! -d $DOMU_DEV_STACK_DIR ]; then + git clone $DEVSTACK_SRC $DOMU_DEV_STACK_DIR + fi + + cp $DOMU_STACK_DIR/local.conf $DOMU_DEV_STACK_DIR/ + + cd $DOMU_DEV_STACK_DIR + ./unstack.sh || true + ./stack.sh + + # Got to the end - success + touch /opt/stack/runsh.succeeded + + # Update /etc/issue + ( + echo "OpenStack VM - Installed by DevStack" + IPADDR=$(ip -4 address show eth0 | sed -n 's/.*inet \([0-9\.]\+\).*/\1/p') + echo " Management IP: $IPADDR" + echo -n " Devstack run: " + if [ -e /opt/stack/runsh.succeeded ]; then + echo "SUCCEEDED" + else + echo "FAILED" + fi + echo "" + ) > /opt/stack/issue + sudo cp /opt/stack/issue /etc/issue + + rm /opt/stack/run_sh.pid +) 9> /opt/stack/.runsh_lock +EOF + +chmod 755 $STAGING_DIR/opt/stack/run.sh +if [ ! -f $TOP_DIR/local.conf ]; then + echo "ERROR: You should prepare a local.conf and put it under $TOP_DIR" + exit 1 +fi + +cp_it $TOP_DIR/local.conf $STAGING_DIR/opt/stack/local.conf +cp_it $THIS_DIR/run.sh $STAGING_DIR/opt/stack/run.sh diff --git a/install/scripts/install-os-vpx.sh b/tools/install/scripts/install-os-vpx.sh similarity index 100% rename from install/scripts/install-os-vpx.sh rename to tools/install/scripts/install-os-vpx.sh diff --git a/install/scripts/install_ubuntu_template.sh b/tools/install/scripts/install_ubuntu_template.sh similarity index 98% rename from install/scripts/install_ubuntu_template.sh rename to tools/install/scripts/install_ubuntu_template.sh index 17bd6ba..1521eba 100755 --- a/install/scripts/install_ubuntu_template.sh +++ b/tools/install/scripts/install_ubuntu_template.sh @@ -46,7 +46,7 @@ fi # Clone built-in template to create new template new_uuid=$(xe vm-clone uuid=$builtin_uuid \ new-name-label="$UBUNTU_INST_TEMPLATE_NAME") -disk_size=$(($CLEAN_VM_VDI_GB * 1024 * 1024 * 1024)) +disk_size=$(($VM_VDI_GB * 1024 * 1024 * 1024)) # Some of these settings can be found in example preseed files # however these need to be answered before the netinstall diff --git a/tools/install/scripts/manage-vdi b/tools/install/scripts/manage-vdi new file mode 100755 index 0000000..f3112bb --- /dev/null +++ b/tools/install/scripts/manage-vdi @@ -0,0 +1,97 @@ +#!/bin/bash + +set -eux + +action="$1" +vm="$2" +device="${3-0}" +part="${4-}" + +function xe_min() { + local cmd="$1" + shift + xe "$cmd" --minimal "$@" +} + +function run_udev_settle() { + which_udev=$(which udevsettle) || true + if [ -n "$which_udev" ]; then + udevsettle + else + udevadm settle + fi +} + +vm_uuid=$(xe_min vm-list name-label="$vm") +vdi_uuid=$(xe_min vbd-list params=vdi-uuid vm-uuid="$vm_uuid" \ + userdevice="$device") + + +dom0_uuid=$(xe_min vm-list is-control-domain=true) + +function get_mount_device() { + vbd_uuid=$1 + + dev=$(xe_min vbd-list params=device uuid="$vbd_uuid") + if [[ "$dev" =~ "sm/" || "$dev" =~ "blktap-2/" ]]; then + DEBIAN_FRONTEND=noninteractive \ + apt-get --option "Dpkg::Options::=--force-confold" --assume-yes \ + install kpartx &> /dev/null || true + mapping=$(kpartx -av "/dev/$dev" | sed -ne 's,^add map \([a-z0-9\-]*\).*$,\1,p' | sed -ne "s,^\(.*${part}\)\$,\1,p") + if [ -z "$mapping" ]; then + echo "Failed to find mapping" + exit -1 + fi + + local device="/dev/mapper/${mapping}" + for (( i = 0; i < 5; i++ )) ; do + if [ -b $device ] ; then + echo $device + return + fi + sleep 1 + done + echo "ERROR: timed out waiting for dev-mapper" + exit 1 + else + echo "/dev/$dev$part" + fi +} + +function clean_dev_mappings() { + dev=$(xe_min vbd-list params=device uuid="$vbd_uuid") + if [[ "$dev" =~ "sm/" || "$dev" =~ "blktap-2/" ]]; then + kpartx -dv "/dev/$dev" + fi +} + +function open_vdi() { + vbd_uuid=$(xe vbd-create vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid" \ + device=autodetect) + mp=$(mktemp -d) + xe vbd-plug uuid="$vbd_uuid" + + run_udev_settle + + mount_device=$(get_mount_device "$vbd_uuid") + mount "$mount_device" "$mp" + echo "Your vdi is mounted at $mp" +} + +function close_vdi() { + vbd_uuid=$(xe_min vbd-list vm-uuid="$dom0_uuid" vdi-uuid="$vdi_uuid") + mount_device=$(get_mount_device "$vbd_uuid") + run_udev_settle + umount "$mount_device" + + clean_dev_mappings + + xe vbd-unplug uuid=$vbd_uuid + xe vbd-destroy uuid=$vbd_uuid +} + +if [ "$action" == "open" ]; then + open_vdi +elif [ "$action" == "close" ]; then + close_vdi +fi diff --git a/install/scripts/on_exit.sh b/tools/install/scripts/on_exit.sh similarity index 100% rename from install/scripts/on_exit.sh rename to tools/install/scripts/on_exit.sh diff --git a/tools/install/scripts/persist_domU_interfaces.sh b/tools/install/scripts/persist_domU_interfaces.sh new file mode 100755 index 0000000..a3ff18d --- /dev/null +++ b/tools/install/scripts/persist_domU_interfaces.sh @@ -0,0 +1,107 @@ +#!/bin/bash + +# This script is run by config_devstack_domu_vm.sh +# +# It modifies the ubuntu image created by config_devstack_domu_vm.sh +# and previously moodified by prepare_guest_template.sh +# +# This script is responsible for: +# - pushing in the DevStack code +# It does this by mounting the disk image of the VM. +# +# The resultant image is then templated and started +# by config_devstack_domu_vm.sh + +# Exit on errors +set -o errexit +# Echo commands +set -o xtrace + +# This directory +THIS_DIR=$(cd $(dirname "$0") && pwd) +TOP_DIR="$THIS_DIR/../" +SCRIPT_DIR="$TOP_DIR/scripts" +COMM_DIR="$TOP_DIR/common" +CONF_DIR="$TOP_DIR/conf" + +# Include onexit commands +. $SCRIPT_DIR/on_exit.sh + +# xapi functions +. $COMM_DIR/functions + +# Source params +source $CONF_DIR/xenrc + +# +# Parameters +# +GUEST_NAME="$1" + +function _print_interface_config { + local device_nr + local ip_address + local netmask + + device_nr="$1" + ip_address="$2" + netmask="$3" + + local device + + device="eth${device_nr}" + + echo "auto $device" + if [ "$ip_address" = "dhcp" ]; then + echo "iface $device inet dhcp" + else + echo "iface $device inet static" + echo " address $ip_address" + echo " netmask $netmask" + fi + + # Turn off tx checksumming for better performance + echo " post-up ethtool -K $device tx off" +} + +function print_interfaces_config { + echo "auto lo" + echo "iface lo inet loopback" + + _print_interface_config $PUB_DEV_NR $PUB_IP $PUB_NETMASK + _print_interface_config $VM_DEV_NR $VM_IP $VM_NETMASK + _print_interface_config $MGT_DEV_NR $MGT_IP $MGT_NETMASK +} + +# +# Mount the VDI +# +STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*") +add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1" + +# Make sure we have a stage +if [ ! -d $STAGING_DIR/etc ]; then + echo "Stage is not properly set up!" + exit 1 +fi + +# Only support DHCP for now - don't support how different versions of Ubuntu handle resolv.conf +if [ "$MGT_IP" != "dhcp" ] && [ "$PUB_IP" != "dhcp" ]; then + echo "Configuration without DHCP not supported" + exit 1 +fi + +# Configure the hostname +echo $GUEST_NAME > $STAGING_DIR/etc/hostname + +# Hostname must resolve for rabbit +HOSTS_FILE_IP=$PUB_IP +if [ $MGT_IP != "dhcp" ]; then + HOSTS_FILE_IP=$MGT_IP +fi +cat <$STAGING_DIR/etc/hosts +127.0.0.1 localhost localhost.localdomain +EOF + +# Configure the network +print_interfaces_config > $STAGING_DIR/etc/network/interfaces diff --git a/tools/install/scripts/prepare_guest.sh b/tools/install/scripts/prepare_guest.sh new file mode 100755 index 0000000..664aef5 --- /dev/null +++ b/tools/install/scripts/prepare_guest.sh @@ -0,0 +1,122 @@ +#!/bin/bash + +# This script is run on an Ubuntu VM. +# This script is inserted into the VM by prepare_guest_template.sh +# and is run when that VM boots. +# It customizes a fresh Ubuntu install, so it is ready +# to run stack.sh +# +# creating the user called "stack", +# and shuts down the VM to signal the script has completed + +set -o errexit +set -o nounset +set -o xtrace + +# Configurable nuggets +GUEST_PASSWORD="$1" +STACK_USER="$2" +DOMZERO_USER="$3" + + +function setup_domzero_user { + local username + + username="$1" + + local key_updater_script + local sudoers_file + key_updater_script="/home/$username/update_authorized_keys.sh" + sudoers_file="/etc/sudoers.d/allow_$username" + + # Create user + adduser --disabled-password --quiet "$username" --gecos "$username" + + # Give passwordless sudo + cat > $sudoers_file << EOF + $username ALL = NOPASSWD: ALL +EOF + chmod 0440 $sudoers_file + + # A script to populate this user's authenticated_keys from xenstore + cat > $key_updater_script << EOF +#!/bin/bash +set -eux + +DOMID=\$(sudo xenstore-read domid) +sudo xenstore-exists /local/domain/\$DOMID/authorized_keys/$username +sudo xenstore-read /local/domain/\$DOMID/authorized_keys/$username > /home/$username/xenstore_value +cat /home/$username/xenstore_value > /home/$username/.ssh/authorized_keys +EOF + + # Give the key updater to the user + chown $username:$username $key_updater_script + chmod 0700 $key_updater_script + + # Setup the .ssh folder + mkdir -p /home/$username/.ssh + chown $username:$username /home/$username/.ssh + chmod 0700 /home/$username/.ssh + touch /home/$username/.ssh/authorized_keys + chown $username:$username /home/$username/.ssh/authorized_keys + chmod 0600 /home/$username/.ssh/authorized_keys + + # Setup the key updater as a cron job + crontab -u $username - << EOF +* * * * * $key_updater_script +EOF + +} + +# Make a small cracklib dictionary, so that passwd still works, but we don't +# have the big dictionary. +mkdir -p /usr/share/cracklib +echo a | cracklib-packer + +# Make /etc/shadow, and set the root password +pwconv +echo "root:$GUEST_PASSWORD" | chpasswd + +# Put the VPX into UTC. +rm -f /etc/localtime + +# Add stack user +groupadd libvirtd +useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd +echo $STACK_USER:$GUEST_PASSWORD | chpasswd +echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers + +setup_domzero_user "$DOMZERO_USER" + +# Add an udev rule, so that new block devices could be written by stack user +cat > /etc/udev/rules.d/50-openstack-blockdev.rules << EOF +KERNEL=="xvd[b-z]", GROUP="$STACK_USER", MODE="0660" +EOF + +# Give ownership of /opt/stack to stack user +chown -R $STACK_USER /opt/stack + +function setup_vimrc { + if [ ! -e $1 ]; then + # Simple but usable vimrc + cat > $1 <$STAGING_DIR/etc/rc.local +#!/bin/sh -e +bash /opt/stack/prepare_guest.sh \\ + "$GUEST_PASSWORD" "$STACK_USER" "$DOMZERO_USER" \\ + > /opt/stack/prepare_guest.log 2>&1 +EOF +echo "$STAGING_DIR/etc/apt/sources.list" +# Update ubuntu repositories +cat > $STAGING_DIR/etc/apt/sources.list << EOF +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} main restricted +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} main restricted +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates main restricted +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates main restricted +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} universe +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} universe +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates universe +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates universe +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} multiverse +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE} multiverse +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates multiverse +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-updates multiverse +deb http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-backports main restricted universe multiverse +deb-src http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY} ${UBUNTU_INST_RELEASE}-backports main restricted universe multiverse + +deb http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security main restricted +deb-src http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security main restricted +deb http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security universe +deb-src http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security universe +deb http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security multiverse +deb-src http://security.ubuntu.com/ubuntu ${UBUNTU_INST_RELEASE}-security multiverse +EOF + +rm -f $STAGING_DIR/etc/apt/apt.conf +if [ -n "$UBUNTU_INST_HTTP_PROXY" ]; then + cat > $STAGING_DIR/etc/apt/apt.conf << EOF +Acquire::http::Proxy "$UBUNTU_INST_HTTP_PROXY"; +EOF +fi diff --git a/install/scripts/ubuntu_latecommand.sh b/tools/install/scripts/ubuntu_latecommand.sh similarity index 100% rename from install/scripts/ubuntu_latecommand.sh rename to tools/install/scripts/ubuntu_latecommand.sh diff --git a/install/scripts/uninstall-os-vpx.sh b/tools/install/scripts/uninstall-os-vpx.sh similarity index 100% rename from install/scripts/uninstall-os-vpx.sh rename to tools/install/scripts/uninstall-os-vpx.sh diff --git a/tools/install_on_xen_host.sh b/tools/install_on_xen_host.sh new file mode 100755 index 0000000..00d4790 --- /dev/null +++ b/tools/install_on_xen_host.sh @@ -0,0 +1,201 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o xtrace + +export LC_ALL=C + +# This directory +THIS_DIR=$(cd $(dirname "$0") && pwd) +INSTALL_DIR="$THIS_DIR/install" + +COMM_DIR="$INSTALL_DIR/common" +CONF_DIR="$INSTALL_DIR/conf" +DEV_STACK_DIR="$INSTALL_DIR/devstack" + +. $COMM_DIR/functions +# Source params +source $CONF_DIR/xenrc + +function print_usage_and_die +{ +cat >&2 << EOF +usage: $0 + +A simple script to use devstack to setup an OpenStack. This script should be +executed on a xenserver host. + +optional arguments: + -d DEVSTACK_SRC An URL pointing to a tar.gz snapshot of devstack. This + defaults to the official devstack repository. Can also be a local + file location. + -l LOG_FILE_DIRECTORY The directory in which to store the devstack logs on failure. + -w WAIT_TILL_LAUNCH Set it to 1 if user want to pending on the installation until + it is done + +flags: + -f Force SR replacement. If your XenServer has an LVM type SR, + it will be destroyed and replaced with an ext SR. + WARNING: This will destroy your actual default SR ! + +An example run: + + # Install devstack + $0 mypassword + +$@ +EOF +exit 1 +} + +# Defaults for optional arguments +DEVSTACK_SRC=${DEVSTACK_SRC:-"https://github.com/openstack-dev/devstack"} +LOGDIR="/opt/stack/devstack_logs" +WAIT_TILL_LAUNCH=1 +FORCE_SR_REPLACEMENT="false" + +# Number of options passed to this script +REMAINING_OPTIONS="$#" + +# Get optional parameters +set +e +while getopts ":d:fl:w:" flag; do + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + case "$flag" in + d) + DEVSTACK_SRC="$OPTARG" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + f) + FORCE_SR_REPLACEMENT="true" + ;; + l) + LOGDIR="$OPTARG" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + w) + WAIT_TILL_LAUNCH="$OPTARG" + REMAINING_OPTIONS=$(expr "$REMAINING_OPTIONS" - 1) + ;; + \?) + print_usage_and_die "Invalid option -$OPTARG" + exit 1 + ;; + esac +done +set -e + +# Make sure that all options processed +if [ "0" != "$REMAINING_OPTIONS" ]; then + print_usage_and_die "ERROR: some arguments were not recognised!" +fi + +## +# begin install devstack process +## + +# Verify the host is suitable for devstack +echo -n "Verify XenServer has an ext type default SR..." +defaultSR=$(xe pool-list params=default-SR minimal=true) +currentSrType=$(xe sr-param-get uuid=$defaultSR param-name=type) +if [ "$currentSrType" != "ext" -a "$currentSrType" != "nfs" -a "$currentSrType" != "ffs" -a "$currentSrType" != "file" ]; then + if [ "true" == "$FORCE_SR_REPLACEMENT" ]; then + echo "" + echo "" + echo "Trying to replace the default SR with an EXT SR" + + pbd_uuid=`xe pbd-list sr-uuid=$defaultSR minimal=true` + host_uuid=`xe pbd-param-get uuid=$pbd_uuid param-name=host-uuid` + use_device=`xe pbd-param-get uuid=$pbd_uuid param-name=device-config param-key=device` + + # Destroy the existing SR + xe pbd-unplug uuid=$pbd_uuid + xe sr-destroy uuid=$defaultSR + + sr_uuid=`xe sr-create content-type=user host-uuid=$host_uuid type=ext device-config:device=$use_device shared=false name-label="Local storage"` + pool_uuid=`xe pool-list minimal=true` + xe pool-param-set default-SR=$sr_uuid uuid=$pool_uuid + xe pool-param-set suspend-image-SR=$sr_uuid uuid=$pool_uuid + xe sr-param-add uuid=$sr_uuid param-name=other-config i18n-key=local-storage + exit 0 + fi + echo "" + echo "" + echo "ERROR: The xenserver host must have an EXT3/NFS/FFS/File SR as the default SR" + echo "Use the -f flag to destroy the current default SR and create a new" + echo "ext type default SR." + echo "" + echo "WARNING: This will destroy your actual default SR !" + echo "" + + exit 1 +fi + +# create template if needed +$INSTALL_DIR/create_ubuntu_template.sh +if [ -n "${EXIT_AFTER_JEOS_INSTALLATION:-}" ]; then + echo "User requested to quit after JEOS installation" + exit 0 +fi + +# install DevStack on the VM +$DEV_STACK_DIR/install_devstack.sh -d $DEVSTACK_SRC -l $LOGDIR + +#start openstack domU VM +xe vm-start vm="$DEV_STACK_DOMU_NAME" + +# If we have copied our ssh credentials, use ssh to monitor while the installation runs +function ssh_no_check { + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@" +} + +# Get hold of the Management IP of OpenStack VM +OS_VM_MANAGEMENT_ADDRESS=$MGT_IP +if [ $OS_VM_MANAGEMENT_ADDRESS == "dhcp" ]; then + OS_VM_MANAGEMENT_ADDRESS=$(find_ip_by_name $DEV_STACK_DOMU_NAME $MGT_DEV_NR) +fi + +if [ "$WAIT_TILL_LAUNCH" = "1" ] && [ -e ~/.ssh/id_rsa.pub ]; then + set +x + echo "VM Launched - Waiting for run.sh" + while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e /opt/stack/run_sh.pid"; do + echo "VM Launched - Waiting for run.sh" + sleep 10 + done + echo -n "devstack service is running, waiting for stack.sh to start logging..." + + pid=`ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "cat /opt/stack/run_sh.pid"` + if [ -n "$LOGDIR" ]; then + while ! ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "test -e ${LOGDIR}/stack.log"; do + echo -n "..." + sleep 10 + done + + ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "tail --pid $pid -n +1 -f ${LOGDIR}/stack.log" + else + echo -n "LOGDIR not set; just waiting for process $pid to finish" + ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS "wait $pid" + fi + # Fail if devstack did not succeed + ssh_no_check -q stack@$OS_VM_MANAGEMENT_ADDRESS 'test -e /opt/stack/runsh.succeeded' + echo "################################################################################" + echo "" + echo "All Finished!" + echo "You can visit the OpenStack Dashboard" + echo "at http://$OS_VM_MANAGEMENT_ADDRESS, and contact other services at the usual ports." +else + set +x + echo "################################################################################" + echo "" + echo "All Finished!" + echo "Now, you can monitor the progress of the stack.sh installation by " + echo "looking at the console of your domU / checking the log files." + echo "" + echo "ssh into your domU now: 'ssh stack@$OS_VM_MANAGEMENT_ADDRESS' using your password" + echo "and then do: 'sudo systemctl status devstack' to check if devstack is still running." + echo "Check that /opt/stack/runsh.succeeded exists" + echo "" + echo "When devstack completes, you can visit the OpenStack Dashboard" + echo "at http://$OS_VM_MANAGEMENT_ADDRESS, and contact other services at the usual ports." +fi