diff --git a/tools/install-devstack-xen.sh b/tools/install-devstack-xen.sh index 8cfcdd0..b9d56dd 100755 --- a/tools/install-devstack-xen.sh +++ b/tools/install-devstack-xen.sh @@ -22,9 +22,9 @@ positional arguments: optional arguments: -t TEST_TYPE Type of the tests to run. One of [none, exercise, smoke, full] defaults to none - -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. + -d DEVSTACK_SRC It can be a local directory containing a local repository or + an URL pointing to a remote repository. This defaults to the + official devstack repository. -l LOG_FILE_DIRECTORY The directory in which to store the devstack logs on failure. -j JEOS_URL An URL for an xva containing an exported minimal OS template with the name jeos_template_for_ubuntu, to be used @@ -36,7 +36,8 @@ 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 + -o OS_XENAPI_SRC It can be a local directory containing a local repository or + an URL pointing to a remote repository. 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 @@ -75,7 +76,7 @@ exit 1 # Defaults for optional arguments 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"} +OS_XENAPI_SRC=${OS_XENAPI_SRC:-"https://github.com/openstack/os-xenapi"} TEST_TYPE="none" FORCE_SR_REPLACEMENT="false" EXIT_AFTER_JEOS_INSTALLATION="" @@ -90,6 +91,7 @@ NODE_TYPE="all" NODE_NAME="" CONTROLLER_IP="" DISABLE_JOURNALING="false" +DEFAULT_INSTALL_SRC="$(mktemp -d --suffix=install)" # Get Positional arguments set +u @@ -283,7 +285,10 @@ set -eu mkdir -p $TMP_TEMPLATE_DIR -JEOS_TEMPLATE="\$(xe template-list name-label=$JEOS_TEMP_NAME --minimal)" +JEOS_TEMPLATE="\$(. "$COMM_DIR/functions" && get_template $JEOS_TEMP_NAME $(get_current_host_uuid)) +if [ JEOS_TEMPLATE==*,* ]; then + JEOS_TEMPLATE=${JEOS_TEMPLATE##*,} +fi if [ -z "\$JEOS_TEMPLATE" ]; then echo "FATAL: $JEOS_TEMP_NAME not found" @@ -365,15 +370,6 @@ else exit 1 fi -echo -n "Get the IP address of XenServer..." -XENSERVER_IP=$(on_xenserver << GET_XENSERVER_IP -xe host-list params=address minimal=true -GET_XENSERVER_IP -) -if [ -z "$XENSERVER_IP" ]; then - echo "Failed to detect the IP address of XenServer" - exit 1 -fi echo "OK" if [ -n "$SUPP_PACK_URL" ]; then @@ -395,11 +391,14 @@ set -eu mkdir -p $TMP_TEMPLATE_DIR -JEOS_TEMPLATE="\$(xe template-list name-label=$JEOS_TEMP_NAME --minimal)" +JEOS_TEMPLATE="\$(. "$COMM_DIR/functions" && get_template $JEOS_TEMP_NAME $(get_current_host_uuid)) if [ -n "\$JEOS_TEMPLATE" ]; then echo " $JEOS_TEMP_NAME already exist, uninstalling" - xe template-uninstall template-uuid="\$JEOS_TEMPLATE" force=true > /dev/null + IFS=',' + for i in "\${JEOS_TEMPLATE[@]}"; do + xe template-uninstall template-uuid="\$i" force=true > /dev/null + done fi rm -f $TMP_TEMPLATE_DIR/jeos-for-devstack.xva @@ -409,7 +408,7 @@ 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_TEMP_NAME --minimal)" +JEOS_TEMPLATE="\$(. "$COMM_DIR/functions" && get_template $JEOS_TEMP_NAME $(get_current_host_uuid)) if [ -z "\$JEOS_TEMPLATE" ]; then echo "FATAL: template $JEOS_TEMP_NAME does not exist after import." exit 1 @@ -419,23 +418,52 @@ END_OF_JEOS_IMPORT echo "OK" fi +# Got install repositories. +# If input repository is an URL, for os-xenapi, it is only needed on xenserver, +# so we will download it and move it to xenserver when needed; for devstack, it +# is needed on DomU, so we configure a service on DomU and download it after +# DomU first bootup. +if [ -d $DEVSTACK_SRC ]; then + # Local repository for devstack exist, copy it to default directory for + # unified treatment + cp -rf $DEVSTACK_SRC $DEFAULT_INSTALL_SRC + DEVSTACK_SRC=$DEFAULT_INSTALL_SRC/devstack +fi +if [ ! -d $OS_XENAPI_SRC ]; then + # Local repository for os-xenapi does not exist, OS_XENAPI_SRC must be a git + # URL. Download it to default directory + git clone $OS_XENAPI_SRC $DEFAULT_INSTALL_SRC/os-xenapi +else + # Local repository for os-xenapi exists, copy it to default directory + # unified treatment + cp -rf $OS_XENAPI_SRC $DEFAULT_INSTALL_SRC +fi + TMPDIR=$(echo "mktemp -d" | on_xenserver) 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" +ssh $_SSH_OPTIONS root@$XENSERVER "[ -d $DOM0_OPT_DIR ] && echo ok || mkdir -p $DOM0_OPT_DIR" +tar -zcvf local_res.tar.gz $DEFAULT_INSTALL_SRC +scp $_SSH_OPTIONS local_res.tar.gz root@$XENSERVER:$DOM0_OPT_DIR +rm -f local_res.tar.gz +DOM0_OS_API_DIR=$DOM0_OPT_DIR/os-xenapi +if [ -d $DEVSTACK_SRC ]; then + DEVSTACK_SRC=$DOM0_OPT_DIR/devstack +fi copy_logs_on_failure on_xenserver << END_OF_XENSERVER_COMMANDS - 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 + tar -zxvf local_res.tar.gz + # remove root flag + DEFAULT_INSTALL_SRC=${DEFAULT_INSTALL_SRC#*/} + mv \$DEFAULT_INSTALL_SRC/* ./ + DOM0_TOOL_DIR="$DOM0_OS_API_DIR/tools" + DOM0_INSTALL_DIR="\$DOM0_TOOL_DIR/install" + cd \$DOM0_INSTALL_DIR # override items in xenrc - sed -i "s/DevStackOSDomU/$NODE_NAME/g" $DOM0_INSTALL_DIR/conf/xenrc + sed -i "s/DevStackOSDomU/$NODE_NAME/g" \$DOM0_INSTALL_DIR/conf/xenrc # prepare local.conf cat << LOCALCONF_CONTENT_ENDS_HERE > local.conf @@ -483,8 +511,8 @@ LOGFILE=${LOGDIR}/stack.log VERBOSE=True # XenAPI specific -XENAPI_CONNECTION_URL="http://$XENSERVER_IP" -VNCSERVER_PROXYCLIENT_ADDRESS="$XENSERVER_IP" +XENAPI_CONNECTION_URL="http://$XENSERVER" +VNCSERVER_PROXYCLIENT_ADDRESS="$XENSERVER" # Neutron specific part Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch @@ -521,7 +549,7 @@ disk_allocation_ratio = 2.0 LOCALCONF_CONTENT_ENDS_HERE # begin installation process -cd $DOM0_TOOL_DIR +cd \$DOM0_TOOL_DIR OPTARGS="" if [ $FORCE_SR_REPLACEMENT = 'true' ]; then OPTARGS="$OPTARGS -f" @@ -586,4 +614,6 @@ END_OF_DEVSTACK_COMMANDS END_OF_XENSERVER_COMMANDS +rm -rf $DEFAULT_INSTALL_SRC + copy_logs diff --git a/tools/install/common/functions b/tools/install/common/functions index 42bb35d..85ebf7c 100755 --- a/tools/install/common/functions +++ b/tools/install/common/functions @@ -60,7 +60,8 @@ function _create_new_network { local name_label name_label=$1 - xe network-create name-label="$name_label" + uuid=$(xe network-create name-label="$name_label") + xe network-param-add uuid=$uuid param-name=other-config assume_network_is_shared='true' } function _multiple_networks_with_name { @@ -198,6 +199,16 @@ function have_multiple_hosts { xe host-list --minimal | grep -q "," } +function get_current_host_uuid { + source /etc/xensource-inventory; + echo $INSTALLATION_UUID +} + +function get_current_dom0_uuid { + source /etc/xensource-inventory; + echo $CONTROL_DOMAIN_UUID +} + function attach_network { local bridge_or_net_name @@ -207,7 +218,7 @@ function attach_network { local host net=$(_network_uuid "$bridge_or_net_name") - host=$(xe host-list --minimal) + host=$(get_current_host_uuid) xe network-attach uuid=$net host-uuid=$host } @@ -259,7 +270,8 @@ function max_vcpus { local host local cpu_count - host=$(xe host-list --minimal) + host=$(get_current_host_uuid) + vm=$(_vm_uuid "$vm_name_label") cpu_count=$(xe host-param-get \ @@ -294,6 +306,46 @@ function max_vcpus { xe vm-param-set uuid=$vm VCPUs-at-startup=$cpu_count } +function get_template { + local tmp_name="$1" + local host="$2" + tmp=$(xe template-list name-label="$tmp_name" --minimal) + if [[ $tmp == *","* ]]; then + tmp_group=tmp + tmp=$(xe template-list name-label="$tmp_name" \ + possible-hosts=$host --minimal) + # Current host have no template + if [[ -z $tmp ]]; then + tmp=${tmp_group##*,} + fi + fi + echo $tmp +} + +function clean_template_other_conf { + local tmp_name="$1" + tmp=$(xe template-list name-label="$tmp_name" --minimal) + if [ -n "\$tmp" ]; then + echo " $tmp clean other configure" + IFS=',' + for i in "\${tmp[@]}"; do + xe template-param-clear param-name=other-config uuid=$i > /dev/null + done + fi +} + +function uninstall_template { + local tmp_name="$1" + tmp=$(xe template-list name-label="$tmp_name" --minimal) + if [ -n "\$tmp" ]; then + echo " $tmp already exist, uninstalling" + IFS=',' + for i in "\${tmp[@]}"; do + xe template-uninstall template-uuid="\$i" force=true > /dev/null + done + fi +} + function get_domid { local vm_name_label @@ -307,7 +359,7 @@ function install_conntrack_tools { local xs_ver_major local centos_ver local conntrack_conf - xs_host=$(xe host-list --minimal) + xs_host=$(get_current_host_uuid) xs_ver_major=$(xe host-param-get uuid=$xs_host param-name=software-version param-key=product_version_text_short | cut -d'.' -f 1) if [ $xs_ver_major -gt 6 ]; then # Only support conntrack-tools in Dom0 with XS7.0 and above diff --git a/tools/install/create_ubuntu_template.sh b/tools/install/create_ubuntu_template.sh index 5efcb0f..d07f2ff 100755 --- a/tools/install/create_ubuntu_template.sh +++ b/tools/install/create_ubuntu_template.sh @@ -35,20 +35,21 @@ source $CONF_DIR/xenrc cd $THIS_DIR -# Die if multiple hosts listed +# Check if multiple hosts listed if have_multiple_hosts; then cat >&2 << EOF -ERROR: multiple hosts found. This might mean that the XenServer is a member -of a pool - Exiting. +Info: multiple hosts found. This might mean that the XenServer is a member +of a pool. EOF - exit 1 fi # # Configure Networking # -MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true` +host_uuid=$(get_current_host_uuid) + +MGT_NETWORK=`xe pif-list management=true host-uuid=$host_uuid params=network-uuid minimal=true` HOST_MGT_BRIDGE_OR_NET_NAME=`xe network-list uuid=$MGT_NETWORK params=bridge minimal=true` setup_network "$HOST_MGT_BRIDGE_OR_NET_NAME" @@ -93,7 +94,7 @@ if [ "$DO_SHUTDOWN" = "1" ]; then $SCRIPT_DIR/uninstall-os-vpx.sh $clean_templates_arg # Destroy any instances that were launched - for uuid in `xe vm-list | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do + for uuid in `xe vm-list resident-on=$host_uuid | grep -1 instance | grep uuid | sed "s/.*\: //g"`; do echo "Shutting down nova instance $uuid" xe vm-uninstall uuid=$uuid force=true done @@ -109,8 +110,8 @@ fi # Create Ubuntu VM template # and/or create VM from template # +templateuuid=$(get_template $TNAME $host_uuid) -templateuuid=$(xe template-list name-label="$TNAME") if [ -z "$templateuuid" ]; then # # Install Ubuntu over network @@ -175,7 +176,7 @@ if [ -z "$templateuuid" ]; then set_vm_memory "$GUEST_NAME" "1024" - xe vm-start vm="$GUEST_NAME" + xe vm-start vm="$GUEST_NAME" on=$host_uuid # wait for install to finish wait_for_VM_to_halt "$GUEST_NAME" @@ -191,7 +192,7 @@ if [ -z "$templateuuid" ]; then else echo "the template has already exist" fi -template_uuid=$(xe_min template-list name-label="$TNAME") +template_uuid=$(get_template "$TNAME" $host_uuid) exist_val=$(xe template-param-get uuid=$template_uuid param-name=PV-args) if [ -n "$exist_val" ]; then diff --git a/tools/install/devstack/install_devstack.sh b/tools/install/devstack/install_devstack.sh index d7c5cad..c89f9b6 100755 --- a/tools/install/devstack/install_devstack.sh +++ b/tools/install/devstack/install_devstack.sh @@ -75,7 +75,9 @@ fi # Configure Networking # -MGT_NETWORK=`xe pif-list management=true params=network-uuid minimal=true` +host_uuid=$(get_current_host_uuid) + +MGT_NETWORK=`xe pif-list management=true host-uuid=$host_uuid 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" @@ -144,7 +146,7 @@ destroy_all_vifs_of "$DEV_STACK_DOMU_NAME" 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" +xe vm-start vm="$DEV_STACK_DOMU_NAME" on=$host_uuid # Wait for prep script to finish and shutdown system wait_for_VM_to_halt "$DEV_STACK_DOMU_NAME" @@ -164,7 +166,6 @@ add_interface "$DEV_STACK_DOMU_NAME" "$PUB_BRIDGE_OR_NET_NAME" "$PUB_DEV_NR" # $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}" @@ -205,7 +206,7 @@ fi # # Run DevStack VM # -xe vm-start vm="$DEV_STACK_DOMU_NAME" +xe vm-start vm="$DEV_STACK_DOMU_NAME" on=$host_uuid # Get hold of the Management IP of OpenStack VM OS_VM_MANAGEMENT_ADDRESS=$MGT_IP @@ -271,7 +272,9 @@ if [ ! -d "$STAGING_DIR/opt/stack" ]; then fi rm -f $STAGING_DIR/opt/stack/local.conf -XENSERVER_IP=$(xe host-list params=address minimal=true) +pif=$(xe pif-list management=true host-uuid=$host_uuid --minimal) +XENSERVER_IP=$(xe pif-param-get param-name=IP uuid=$pif) + # Create an systemd task for devstack cat >$STAGING_DIR/etc/systemd/system/devstack.service << EOF @@ -313,6 +316,10 @@ 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 +if [ -d $DEVSTACK_SRC ]; then + # Local repository for devstack exist, copy it to DomU + cp_it $DEVSTACK_SRC $STAGING_DIR/opt/stack/ +fi # Journald default is to not persist logs to disk if /var/log/journal is # not present. Update the configuration to set storage to persistent which @@ -341,6 +348,7 @@ set -eux echo \$\$ >> /opt/stack/run_sh.pid if [ ! -d $DOMU_DEV_STACK_DIR ]; then + echo "Can not find the devstack source code, get it from git." git clone $DEVSTACK_SRC $DOMU_DEV_STACK_DIR fi diff --git a/tools/install/scripts/install_ubuntu_template.sh b/tools/install/scripts/install_ubuntu_template.sh index 1521eba..d78f177 100755 --- a/tools/install/scripts/install_ubuntu_template.sh +++ b/tools/install/scripts/install_ubuntu_template.sh @@ -16,6 +16,10 @@ THIS_DIR=$(cd $(dirname "$0") && pwd) SCRIPT_DIR="$THIS_DIR/../scripts" COMM_DIR="$THIS_DIR/../common" CONF_DIR="$THIS_DIR/../conf" + +# xapi functions +. $COMM_DIR/functions + # For default setings see xenrc source $CONF_DIR/xenrc @@ -23,12 +27,13 @@ source $CONF_DIR/xenrc preseed_url=$1 # Delete template or skip template creation as required -previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \ - params=uuid --minimal) +host=$(get_current_host_uuid) +previous_template=$(get_template "$UBUNTU_INST_TEMPLATE_NAME" $host) + if [ -n "$previous_template" ]; then if $CLEAN_TEMPLATES; then - xe template-param-clear param-name=other-config uuid=$previous_template - xe template-uninstall template-uuid=$previous_template force=true + clean_template_other_conf $previous_template + uninstall_template $previous_template else echo "Template $UBUNTU_INST_TEMPLATE_NAME already present" exit 0 @@ -37,7 +42,7 @@ fi # Get built-in template builtin_name="Debian Squeeze 6.0 (32-bit)" -builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal) +builtin_uuid=$(get_template "$builtin_name" $host) if [[ -z $builtin_uuid ]]; then echo "Can't find the Debian Squeeze 32bit template on your XenServer." exit 1 diff --git a/tools/install/scripts/manage-vdi b/tools/install/scripts/manage-vdi index f3112bb..cfcb15e 100755 --- a/tools/install/scripts/manage-vdi +++ b/tools/install/scripts/manage-vdi @@ -2,6 +2,11 @@ set -eux +THIS_DIR=$(cd $(dirname "$0") && pwd) +COMM_DIR="$THIS_DIR/../common" +# xapi functions +. $COMM_DIR/functions + action="$1" vm="$2" device="${3-0}" @@ -26,8 +31,7 @@ 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) +dom0_uuid=$(get_current_dom0_uuid) function get_mount_device() { vbd_uuid=$1 diff --git a/tools/install/scripts/uninstall-os-vpx.sh b/tools/install/scripts/uninstall-os-vpx.sh index 96dad7e..20fa160 100755 --- a/tools/install/scripts/uninstall-os-vpx.sh +++ b/tools/install/scripts/uninstall-os-vpx.sh @@ -19,6 +19,11 @@ set -ex +THIS_DIR=$(cd $(dirname "$0") && pwd) +COMM_DIR="$THIS_DIR/../common" +# xapi functions +. $COMM_DIR/functions + # By default, don't remove the templates REMOVE_TEMPLATES=${REMOVE_TEMPLATES:-"false"} if [ "$1" = "--remove-templates" ]; then @@ -75,14 +80,15 @@ uninstall_template() xe template-uninstall template-uuid=$vm_uuid force=true >/dev/null } -# remove the VMs and their disks -for u in $(xe_min vm-list other-config:os-vpx=true | sed -e 's/,/ /g'); do +host=$(get_current_host_uuid) +# remove the VMs and their disks on this host +for u in $(xe_min vm-list resident-on=$host other-config:os-vpx=true | sed -e 's/,/ /g'); do uninstall "$u" done # remove the templates if [ "$REMOVE_TEMPLATES" == "true" ]; then - for u in $(xe_min template-list other-config:os-vpx=true | sed -e 's/,/ /g'); do + for u in $(xe_min template-list possible-hosts=$host other-config:os-vpx=true | sed -e 's/,/ /g'); do uninstall_template "$u" done fi diff --git a/tools/install_on_xen_host.sh b/tools/install_on_xen_host.sh index 8f3c9f9..f22b8b5 100755 --- a/tools/install_on_xen_host.sh +++ b/tools/install_on_xen_host.sh @@ -153,7 +153,7 @@ fi $DEV_STACK_DIR/install_devstack.sh -d $DEVSTACK_SRC -l $LOGDIR $OPTARGS #start openstack domU VM -xe vm-start vm="$DEV_STACK_DOMU_NAME" +xe vm-start vm="$DEV_STACK_DOMU_NAME" on=$(get_current_host_uuid) # If we have copied our ssh credentials, use ssh to monitor while the installation runs function ssh_no_check {