summaryrefslogtreecommitdiffstats
path: root/compass
diff options
context:
space:
mode:
authorTim Rozet <trozet@redhat.com>2015-07-28 15:39:49 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2015-07-28 15:39:49 +0000
commit1a9d2532a3cf8bf01fbe829d38bc8988d43aca44 (patch)
tree102270b235cc201fd22ac3ffa57f017f9c228a0c /compass
parent151d0c11410d69d68d6985a275faf0d68958bc9a (diff)
parent99c363dbd827c430cf2bed2cd27c66be4642bae2 (diff)
Merge "speed up the installation of compass"
Diffstat (limited to 'compass')
-rwxr-xr-xcompass/ci/build.sh26
-rwxr-xr-xcompass/ci/deploy.sh14
-rwxr-xr-xcompass/ci/launch.sh65
-rwxr-xr-xcompass/ci/log.sh22
-rw-r--r--compass/deploy/compass_vm.sh103
-rw-r--r--compass/deploy/conf/baremetal.conf20
-rw-r--r--compass/deploy/conf/base.conf25
-rw-r--r--compass/deploy/conf/five.conf2
-rw-r--r--compass/deploy/deploy_host.sh40
-rw-r--r--compass/deploy/host_baremetal.sh9
-rw-r--r--compass/deploy/host_vm.sh59
-rwxr-xr-xcompass/deploy/network.sh70
-rw-r--r--compass/deploy/prepare.sh66
-rw-r--r--compass/deploy/template/network/bridge.xml5
-rw-r--r--compass/deploy/template/network/nat.xml10
-rw-r--r--compass/deploy/template/vm/compass.xml64
-rw-r--r--compass/deploy/template/vm/host.xml67
17 files changed, 612 insertions, 55 deletions
diff --git a/compass/ci/build.sh b/compass/ci/build.sh
index 4e5b87b..2b7fd9a 100755
--- a/compass/ci/build.sh
+++ b/compass/ci/build.sh
@@ -84,7 +84,7 @@ EOF
# BEGIN of variables to customize
#
BUILD_BASE=$(readlink -e ../build/)
-RESULT_DIR="${BUILD_BASE}/release"
+export RESULT_DIR="${BUILD_BASE}/release"
BUILD_SPEC="${BUILD_BASE}/config.mk"
CACHE_DIR="cache"
LOCAL_CACHE_ARCH_NAME="compass-cache"
@@ -112,11 +112,11 @@ DEBUG=0
INTEGRATION_TEST=0
FULL_INTEGRATION_TEST=0
INTERACTIVE=0
-BUILD_CACHE_URI=
+export BUILD_CACHE_URI=
BUILD_SPEC=
BUILD_DIR=
BUILD_LOG=
-BUILD_VERSION=
+export BUILD_VERSION=
MAKE_ARGS=
#
# END of script assigned variables
@@ -133,6 +133,8 @@ source ${INCLUDE_DIR}/build.sh.debug
############################################################################
# BEGIN of main
#
+build_prepare
+
while getopts "s:c:v:f:l:r:RtTh" OPTION
do
case $OPTION in
@@ -376,15 +378,15 @@ mkdir -p ${BUILD_DIR}
cp ${BUILD_BASE}/.versions ${BUILD_DIR}
cp ${RESULT_DIR}/*.iso* ${BUILD_DIR}
-if [ $POPULATE_CACHE -eq 1 ]; then
- if [ ! -z ${BUILD_CACHE_URI} ]; then
- echo "Building cache ..."
- tar --dereference -C ${BUILD_BASE} -caf ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${CACHE_DIR}
- echo "Uploading cache ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}"
- ${REMOTE_ACCESS_METHD} -T ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz
- rm ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz
- fi
-fi
+#if [ $POPULATE_CACHE -eq 1 ]; then
+# if [ ! -z ${BUILD_CACHE_URI} ]; then
+# echo "Building cache ..."
+# tar --dereference -C ${BUILD_BASE} -caf ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${CACHE_DIR}
+# echo "Uploading cache ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}"
+# ${REMOTE_ACCESS_METHD} -T ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz ${BUILD_CACHE_URI}/${REMOTE_CACHE_ARCH_NAME}.tgz
+# rm ${BUILD_BASE}/${LOCAL_CACHE_ARCH_NAME}.tgz
+# fi
+#fi
echo "Success!!!"
exit 0
#
diff --git a/compass/ci/deploy.sh b/compass/ci/deploy.sh
index fe754aa..197bf63 100755
--- a/compass/ci/deploy.sh
+++ b/compass/ci/deploy.sh
@@ -1,5 +1,9 @@
-SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-CONF_NAME=$1
-source ${SCRIPT_DIR}/../deploy/prepare.sh || exit $?
-source ${SCRIPT_DIR}/../deploy/setup-env.sh || exit $?
-source ${SCRIPT_DIR}/../deploy/deploy-vm.sh || exit $?
+#set -x
+COMPASS_DIR=`cd ${BASH_SOURCE[0]%/*}/../;pwd`
+export COMPASS_DIR
+
+apt-get install screen
+screen -ls |grep deploy|awk -F. '{print $1}'|xargs kill -9
+screen -wipe
+#screen -dmSL deploy bash $COMPASS_DIR/ci/launch.sh $*
+$COMPASS_DIR/ci/launch.sh $*
diff --git a/compass/ci/launch.sh b/compass/ci/launch.sh
new file mode 100755
index 0000000..316b06f
--- /dev/null
+++ b/compass/ci/launch.sh
@@ -0,0 +1,65 @@
+#set -x
+WORK_DIR=$COMPASS_DIR/ci/work
+
+if [[ $# -ge 1 ]];then
+ CONF_NAME=$1
+else
+ CONF_NAME=cluster
+fi
+
+source ${COMPASS_DIR}/ci/log.sh
+source ${COMPASS_DIR}/deploy/conf/${CONF_NAME}.conf
+source ${COMPASS_DIR}/deploy/prepare.sh
+source ${COMPASS_DIR}/deploy/network.sh
+
+if [[ ! -z $VIRT_NUMBER ]];then
+ source ${COMPASS_DIR}/deploy/host_vm.sh
+else
+ source ${COMPASS_DIR}/deploy/host_baremetal.sh
+fi
+
+source ${COMPASS_DIR}/deploy/compass_vm.sh
+source ${COMPASS_DIR}/deploy/deploy_host.sh
+
+######################### main process
+
+if ! prepare_env;then
+ echo "prepare_env failed"
+ exit 1
+fi
+
+log_info "########## get host mac begin #############"
+machines=`get_host_macs`
+if [[ -z $machines ]];then
+ log_error "get_host_macs failed"
+ exit 1
+fi
+
+log_info "deploy host macs: $machines"
+export machines
+
+log_info "########## set up network begin #############"
+if ! create_nets;then
+ log_error "create_nets failed"
+ exit 1
+fi
+
+if ! launch_compass;then
+ log_error "launch_compass failed"
+ exit 1
+fi
+if [[ ! -z $VIRT_NUMBER ]];then
+ if ! launch_host_vms;then
+ log_error "launch_host_vms failed"
+ exit 1
+ fi
+fi
+if ! deploy_host;then
+ #tear_down_machines
+ #tear_down_compass
+ exit 1
+else
+ #tear_down_machines
+ #tear_down_compass
+ exit 0
+fi
diff --git a/compass/ci/log.sh b/compass/ci/log.sh
new file mode 100755
index 0000000..f54fdca
--- /dev/null
+++ b/compass/ci/log.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+reset=`tput sgr0`
+red=`tput setaf 1`
+green=`tput setaf 2`
+yellow=`tput setaf 3`
+
+function log_info() {
+ echo -e "${green}$*${reset}"
+}
+
+function log_warn() {
+ echo -e "${yellow}$*${reset}"
+}
+
+function log_error() {
+ echo -e "${red}$*${reset}"
+}
+
+function log_progress() {
+ echo -en "${yellow}$*\r${reset}"
+}
+
diff --git a/compass/deploy/compass_vm.sh b/compass/deploy/compass_vm.sh
new file mode 100644
index 0000000..0764917
--- /dev/null
+++ b/compass/deploy/compass_vm.sh
@@ -0,0 +1,103 @@
+compass_vm_dir=$WORK_DIR/vm/compass
+rsa_file=$compass_vm_dir/boot.rsa
+ssh_args="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $rsa_file"
+function tear_down_compass() {
+ sudo virsh destroy compass > /dev/null 2>&1
+ sudo virsh undefine compass > /dev/null 2>&1
+
+ sudo umount $compass_vm_dir/old > /dev/null 2>&1
+ sudo umount $compass_vm_dir/new > /dev/null 2>&1
+
+ sudo rm -rf $compass_vm_dir
+
+ log_info "tear_down_compass success!!!"
+}
+
+function install_compass_core() {
+ local inventory_file=$compass_vm_dir/inventory.file
+ log_info "install_compass_core enter"
+ sed -i "s/mgmt_next_ip:.*/mgmt_next_ip: ${COMPASS_SERVER}/g" $WORK_DIR/installer/compass-install/install/group_vars/all
+ echo "compass_nodocker ansible_ssh_host=$MGMT_IP ansible_ssh_port=22" > $inventory_file
+ PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ANSIBLE_HOST_KEY_CHECKING=false ANSIBLE_SSH_ARGS='-o UserKnownHostsFile=/dev/null -o ControlMaster=auto -o ControlPersist=60s' ansible-playbook -e pipeline=true --private-key=$rsa_file --user=root --connection=ssh --inventory-file=$inventory_file $WORK_DIR/installer/compass-install/install/compass_nodocker.yml
+ exit_status=$?
+ rm $inventory_file
+ log_info "install_compass_core exit"
+ if [[ $exit_status != 0 ]];then
+ /bin/false
+ fi
+}
+
+function wait_ok() {
+ log_info "wait_compass_ok enter"
+ retry=0
+ until timeout 1s ssh $ssh_args root@$MGMT_IP "exit" 2>/dev/null
+ do
+ log_progress "os install time used: $((retry*100/$1))%"
+ sleep 1
+ let retry+=1
+ if [[ $retry -ge $1 ]];then
+ log_error "os install time out"
+ tear_down_compass
+ exit 1
+ fi
+ done
+
+ log_warn "os install time used: 100%"
+ log_info "wait_compass_ok exit"
+}
+
+function launch_compass() {
+ local old_mnt=$compass_vm_dir/old
+ local new_mnt=$compass_vm_dir/new
+ local old_iso=$WORK_DIR/iso/centos.iso
+ local new_iso=$compass_vm_dir/centos.iso
+
+ log_info "launch_compass enter"
+ tear_down_compass
+
+ set -e
+ mkdir -p $compass_vm_dir $old_mnt
+ sudo mount -o loop $old_iso $old_mnt
+ cd $old_mnt;find .|cpio -pd $new_mnt;cd -
+
+ sudo umount $old_mnt
+
+ chmod 755 -R $new_mnt
+ sed -i -e "s/REPLACE_MGMT_IP/$MGMT_IP/g" -e "s/REPLACE_MGMT_NETMASK/$MGMT_MASK/g" -e "s/REPLACE_INSTALL_IP/$COMPASS_SERVER/g" -e "s/REPLACE_INSTALL_NETMASK/$INSTALL_MASK/g" -e "s/REPLACE_GW/$MGMT_GW/g" $new_mnt/isolinux/isolinux.cfg
+
+ sudo ssh-keygen -f $new_mnt/bootstrap/boot.rsa -t rsa -N ''
+ cp $new_mnt/bootstrap/boot.rsa $rsa_file
+
+ rm -rf $new_mnt/.rr_moved $new_mnt/rr_moved
+ sudo mkisofs -quiet -r -J -R -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -hide-rr-moved -x "lost+found:" -o $new_iso $new_mnt
+
+ rm -rf $old_mnt $new_mnt
+
+ qemu-img create -f qcow2 $compass_vm_dir/disk.img 100G
+
+ # create vm xml
+ sed -e "s/REPLACE_MEM/$COMPASS_VIRT_MEM/g" \
+ -e "s/REPLACE_CPU/$COMPASS_VIRT_CPUS/g" \
+ -e "s#REPLACE_IMAGE#$compass_vm_dir/disk.img#g" \
+ -e "s#REPLACE_ISO#$compass_vm_dir/centos.iso#g" \
+ -e "s/REPLACE_NET_MGMT/mgmt/g" \
+ -e "s/REPLACE_BRIDGE_INSTALL/br_install/g" \
+ $COMPASS_DIR/deploy/template/vm/compass.xml \
+ > $WORK_DIR/vm/compass/libvirt.xml
+
+ sudo virsh define $compass_vm_dir/libvirt.xml
+ sudo virsh start compass
+
+ if ! wait_ok 300;then
+ log_error "install os timeout"
+ exit 1
+ fi
+
+ if ! install_compass_core;then
+ log_error "install compass core failed"
+ exit 1
+ fi
+
+ set +e
+ log_info "launch_compass exit"
+}
diff --git a/compass/deploy/conf/baremetal.conf b/compass/deploy/conf/baremetal.conf
new file mode 100644
index 0000000..317d561
--- /dev/null
+++ b/compass/deploy/conf/baremetal.conf
@@ -0,0 +1,20 @@
+export VIRT_CPUS=4
+export HOST_MACS="'64:3e:8c:4c:6d:a3' '64:3e:8c:4c:6d:37' '64:3e:8c:4c:6c:d7' '64:3e:8c:4c:6b:7b' '64:3e:8c:4c:68:2b'"
+export VIRT_MEM=16384
+export VIRT_DISK=30G
+export 'ADAPTER_OS_PATTERN=(?i)ubuntu-14\.04.*'
+#export 'ADAPTER_OS_PATTERN=(?i)centos-6\.5.*'
+export ADAPTER_NAME="openstack_juno"
+export ADAPTER_TARGET_SYSTEM_PATTERN="^openstack$"
+export ADAPTER_FLAVOR_PATTERN="HA-ansible-multinodes"
+export HOSTNAMES="host1,host2,host3,host4,host5"
+export HOST_ROLES="host1=controller,ha;host2=controller,ha;host3=controller,ha;host4=compute;host5=compute"
+export DEFAULT_ROLES=""
+export SWITCH_IPS="172.29.1.166"
+export SWITCH_CREDENTIAL="version=2c,community=public"
+export DEPLOYMENT_TIMEOUT="150"
+export POLL_SWITCHES_FLAG="nopoll_switches"
+export DASHBOARD_URL=""
+export REGTEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source ${REGTEST_DIR}/base.conf
+export VIP="10.1.0.222"
diff --git a/compass/deploy/conf/base.conf b/compass/deploy/conf/base.conf
index bb9d66c..d8e8d51 100644
--- a/compass/deploy/conf/base.conf
+++ b/compass/deploy/conf/base.conf
@@ -1,12 +1,28 @@
-export COMPASS_SERVER=10.1.0.12
-export COMPASS_SERVER_URL="http://10.1.0.12/api"
+export ISO_URL=http://192.168.123.11:9999/xh/work/build/work/compass.iso
+export INSTALL_IP=${INSTALL_IP:-10.1.0.12}
+export INSTALL_MASK=${INSTALL_MASK:-255.255.255.0}
+export INSTALL_GW=${INSTALL_GW:-10.1.0.1}
+export INSTALL_IP_START=${INSTALL_IP_START:-10.1.0.1}
+export INSTALL_IP_END=${INSTALL_IP_END:-10.1.0.254}
+export MGMT_IP=${MGMT_IP:-192.168.200.2}
+export MGMT_MASK=${MAGMT_MASK:-255.255.252.0}
+export MGMT_GW=${MAGMT_GW:-192.168.200.1}
+export MGMT_IP_START=${MGMT_IP_START:-192.168.200.3}
+export MGMT_IP_END=${MGMT_IP_END:-192.168.200.254}
+export OM_NIC=${OM_NIC:-eth3}
+export OM_IP=${OM_IP:-192.168.123.11/22}
+export OM_GW=${OM_GW:-192.168.120.1}
+export COMPASS_VIRT_CPUS=4
+export COMPASS_VIRT_MEM=4096
+export COMPASS_SERVER=$INSTALL_IP
+export COMPASS_SERVER_URL="http://$COMPASS_SERVER/api"
export COMPASS_USER_EMAIL="admin@huawei.com"
export COMPASS_USER_PASSWORD="admin"
export CLUSTER_NAME="opnfv2"
export LANGUAGE="EN"
export TIMEZONE="America/Los_Angeles"
-export NTP_SERVER="10.1.0.12"
-export NAMESERVERS="10.1.0.12"
+export NTP_SERVER="$COMPASS_SERVER"
+export NAMESERVERS="$COMPASS_SERVER"
export DOMAIN="ods.com"
export PARTITIONS="/home=5%,/tmp=5%,/var=20%"
export SUBNETS="10.1.0.0/24,172.16.2.0/24,172.16.3.0/24,172.16.4.0/24"
@@ -19,6 +35,7 @@ export TENANT_INTERFACE=${TENANT_INTERFACE:-eth1}
export STORAGE_INTERFACE=${STORAGE_INTERFACE:-eth3}
export PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-eth2}
+
function next_ip {
ip_addr=$1
ip_base="$(echo $ip_addr | cut -d. -f'1 2 3')"
diff --git a/compass/deploy/conf/five.conf b/compass/deploy/conf/five.conf
index 32981aa..f32411b 100644
--- a/compass/deploy/conf/five.conf
+++ b/compass/deploy/conf/five.conf
@@ -12,7 +12,7 @@ export HOST_ROLES="host1=controller,network;host2=compute,storage;host3=compute,
export DEFAULT_ROLES=""
export SWITCH_IPS="1.1.1.1"
export SWITCH_CREDENTIAL="version=2c,community=public"
-export DEPLOYMENT_TIMEOUT="90"
+export DEPLOYMENT_TIMEOUT="150"
export POLL_SWITCHES_FLAG="nopoll_switches"
export DASHBOARD_URL=""
export REGTEST_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
diff --git a/compass/deploy/deploy_host.sh b/compass/deploy/deploy_host.sh
new file mode 100644
index 0000000..d08a821
--- /dev/null
+++ b/compass/deploy/deploy_host.sh
@@ -0,0 +1,40 @@
+function deploy_host(){
+ cd $WORK_DIR/installer/compass-core
+ source $WORK_DIR/venv/bin/activate
+ if pip --help | grep -q trusted; then
+ pip install -i http://pypi.douban.com/simple -e . --trusted-host pypi.douban.com
+ else
+ pip install -i http://pypi.douban.com/simple -e .
+ fi
+
+ sudo mkdir -p /var/log/compass
+ sudo chown -R 777 /var/log/compass
+
+ sudo mkdir -p /etc/compass
+ sudo cp -rf conf/setting /etc/compass/.
+
+ cp bin/switch_virtualenv.py.template bin/switch_virtualenv.py
+ sed -i "s|\$PythonHome|$VIRTUAL_ENV|g" bin/switch_virtualenv.py
+ ssh $ssh_args root@${COMPASS_SERVER} mkdir -p /opt/compass/bin/ansible_callbacks
+ scp $ssh_args -r ${COMPASS_DIR}/deploy/status_callback.py root@${COMPASS_SERVER}:/opt/compass/bin/ansible_callbacks/status_callback.py
+
+ (sleep 15;reboot_hosts ) &
+ bin/client.py --logfile= --loglevel=debug --logdir= --compass_server="${COMPASS_SERVER_URL}" \
+ --compass_user_email="${COMPASS_USER_EMAIL}" --compass_user_password="${COMPASS_USER_PASSWORD}" \
+ --cluster_name="${CLUSTER_NAME}" --language="${LANGUAGE}" --timezone="${TIMEZONE}" \
+ --hostnames="${HOSTNAMES}" --partitions="${PARTITIONS}" --subnets="${SUBNETS}" \
+ --adapter_os_pattern="${ADAPTER_OS_PATTERN}" --adapter_name="${ADAPTER_NAME}" \
+ --adapter_target_system_pattern="${ADAPTER_TARGET_SYSTEM_PATTERN}" \
+ --adapter_flavor_pattern="${ADAPTER_FLAVOR_PATTERN}" \
+ --http_proxy="${PROXY}" --https_proxy="${PROXY}" --no_proxy="${IGNORE_PROXY}" \
+ --ntp_server="${NTP_SERVER}" --dns_servers="${NAMESERVERS}" --domain="${DOMAIN}" \
+ --search_path="${SEARCH_PATH}" --default_gateway="${GATEWAY}" \
+ --server_credential="${SERVER_CREDENTIAL}" --local_repo_url="${LOCAL_REPO_URL}" \
+ --os_config_json_file="${OS_CONFIG_FILENAME}" --service_credentials="${SERVICE_CREDENTIALS}" \
+ --console_credentials="${CONSOLE_CREDENTIALS}" --host_networks="${HOST_NETWORKS}" \
+ --network_mapping="${NETWORK_MAPPING}" --package_config_json_file="${PACKAGE_CONFIG_FILENAME}" \
+ --host_roles="${HOST_ROLES}" --default_roles="${DEFAULT_ROLES}" --switch_ips="${SWITCH_IPS}" \
+ --machines=${machines//\'} --switch_credential="${SWITCH_CREDENTIAL}" \
+ --deployment_timeout="${DEPLOYMENT_TIMEOUT}" --${POLL_SWITCHES_FLAG} --dashboard_url="${DASHBOARD_URL}" \
+ --cluster_vip="${VIP}"
+}
diff --git a/compass/deploy/host_baremetal.sh b/compass/deploy/host_baremetal.sh
new file mode 100644
index 0000000..26238e0
--- /dev/null
+++ b/compass/deploy/host_baremetal.sh
@@ -0,0 +1,9 @@
+function get_host_macs() {
+ local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all
+ local machines=`echo $HOST_MACS|sed 's/ /,/g'`
+
+ echo "test: true" >> $config_file
+ echo "pxe_boot_macs: [${machines}]" >> $config_file
+
+ echo $machines
+}
diff --git a/compass/deploy/host_vm.sh b/compass/deploy/host_vm.sh
new file mode 100644
index 0000000..cf9a757
--- /dev/null
+++ b/compass/deploy/host_vm.sh
@@ -0,0 +1,59 @@
+host_vm_dir=$WORK_DIR/vm
+function tear_down_machines() {
+ for i in host{0..4}
+ do
+ sudo virsh destroy $i 1>/dev/null 2>/dev/null
+ sudo virsh undefine $i 1>/dev/null 2>/dev/null
+ rm -rf $host_vm_dir/host$i
+ done
+}
+
+function reboot_hosts() {
+ log_warn "reboot_hosts do nothing"
+}
+
+function launch_host_vms() {
+ tear_down_machines
+ #function_bod
+ mac_array=`echo $machines|sed 's/,/ /g'`
+ log_info "bringing up pxe boot vms"
+ i=0
+ for mac in $mac_array; do
+ log_info "creating vm disk for instance host${i}"
+ vm_dir=$host_vm_dir/host$i
+ mkdir -p $vm_dir
+ sudo qemu-img create -f raw $vm_dir/disk.img ${VIRT_DISK}
+ # create vm xml
+ sed -e "s/REPLACE_MEM/$VIRT_MEM/g" \
+ -e "s/REPLACE_CPU/$VIRT_CPUS/g" \
+ -e "s/REPLACE_NAME/host$i/g" \
+ -e "s#REPLACE_IMAGE#$vm_dir/disk.img#g" \
+ -e "s/REPLACE_BOOT_MAC/$mac/g" \
+ -e "s/REPLACE_BRIDGE_MGMT/br_install/g" \
+ -e "s/REPLACE_BRIDGE_TENANT/br_install/g" \
+ -e "s/REPLACE_BRIDGE_PUBLIC/br_install/g" \
+ -e "s/REPLACE_BRIDGE_STORAGE/br_install/g" \
+ $COMPASS_DIR/deploy/template/vm/host.xml\
+ > $vm_dir/libvirt.xml
+
+ sudo virsh define $vm_dir/libvirt.xml
+ sudo virsh start host$i
+ let i=i+1
+ done
+}
+
+function get_host_macs() {
+ local config_file=$WORK_DIR/installer/compass-install/install/group_vars/all
+ local mac_generator=${COMPASS_DIR}/deploy/mac_generator.sh
+ local machines=
+
+ chmod +x $mac_generator
+ mac_array=`$mac_generator $VIRT_NUMBER`
+ machines=`echo $mac_array|sed 's/ /,/g'`
+
+ echo "test: true" >> $config_file
+ echo "pxe_boot_macs: [${machines}]" >> $config_file
+
+ echo $machines
+}
+
diff --git a/compass/deploy/network.sh b/compass/deploy/network.sh
new file mode 100755
index 0000000..c60607e
--- /dev/null
+++ b/compass/deploy/network.sh
@@ -0,0 +1,70 @@
+function destroy_nets() {
+ sudo virsh net-destroy mgmt > /dev/null 2>&1
+ sudo virsh net-undefine mgmt > /dev/null 2>&1
+
+ sudo virsh net-destroy install > /dev/null 2>&1
+ sudo virsh net-undefine install > /dev/null 2>&1
+ rm -rf $COMPASS_DIR/deploy/work/network/*.xml
+}
+
+function setup_om_bridge() {
+ local device=$1
+ local gw=$2
+ ip link set br_install down
+ ip addr flush $device
+ brctl delbr br_install
+
+ brctl addbr br_install
+ brctl addif br_install $device
+ ip link set br_install up
+
+ shift;shift
+ for ip in $*;do
+ ip addr add $ip dev br_install
+ done
+
+ route add default gw $gw
+}
+
+function setup_om_nat() {
+ # create install network
+ sed -e "s/REPLACE_BRIDGE/br_install/g" \
+ -e "s/REPLACE_NAME/install/g" \
+ -e "s/REPLACE_GATEWAY/$INSTALL_GW/g" \
+ -e "s/REPLACE_MASK/$INSTALL_MASK/g" \
+ -e "s/REPLACE_START/$INSTALL_IP_START/g" \
+ -e "s/REPLACE_END/$INSTALL_IP_END/g" \
+ $COMPASS_DIR/deploy/template/network/nat.xml \
+ > $WORK_DIR/network/install.xml
+
+ sudo virsh net-define $WORK_DIR/network/install.xml
+ sudo virsh net-start install
+}
+
+function create_nets() {
+ destroy_nets
+
+ # create mgmt network
+ sed -e "s/REPLACE_BRIDGE/br_mgmt/g" \
+ -e "s/REPLACE_NAME/mgmt/g" \
+ -e "s/REPLACE_GATEWAY/$MGMT_GW/g" \
+ -e "s/REPLACE_MASK/$MGMT_MASK/g" \
+ -e "s/REPLACE_START/$MGMT_IP_START/g" \
+ -e "s/REPLACE_END/$MGMT_IP_END/g" \
+ $COMPASS_DIR/deploy/template/network/nat.xml \
+ > $WORK_DIR/network/mgmt.xml
+
+ sudo virsh net-define $WORK_DIR/network/mgmt.xml
+ sudo virsh net-start mgmt
+
+ # create install network
+ if [[ ! -z $VIRT_NUMBER ]];then
+ setup_om_nat
+ else
+ mask=`echo $INSTALL_MASK | awk -F'.' '{print ($1*(2^24)+$2*(2^16)+$3*(2^8)+$4)}'`
+ mask_len=`echo "obase=2;${mask}"|bc|awk -F'0' '{print length($1)}'`
+ setup_om_bridge $OM_NIC $OM_GW $INSTALL_GW/$mask_len $OM_IP
+ fi
+
+}
+
diff --git a/compass/deploy/prepare.sh b/compass/deploy/prepare.sh
index 2086c5d..9ec15f8 100644
--- a/compass/deploy/prepare.sh
+++ b/compass/deploy/prepare.sh
@@ -1,35 +1,35 @@
-sudo apt-get update -y
-sudo apt-get install git python-pip python-dev -y
-vagrant --version
-if [[ $? != 0 ]]; then
- vagrant_pkg_url=https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2_x86_64.deb
- wget ${vagrant_pkg_url}
- sudo dpkg -i $(basename ${vagrant_pkg_url})
-else
- echo "vagrant is already installed"
-fi
-sudo apt-get install libxslt-dev libxml2-dev libvirt-dev build-essential qemu-utils qemu-kvm libvirt-bin virtinst libmysqld-dev -y
-sudo service libvirt-bin restart
+function prepare_env() {
+ export PYTHONPATH=/usr/lib/python2.7/dist-packages:/usr/local/lib/python2.7/dist-packages
+ sudo apt-get update -y
+ sudo apt-get install mkisofs bc
+ sudo apt-get install git python-pip python-dev -y
+ sudo apt-get install libxslt-dev libxml2-dev libvirt-dev build-essential qemu-utils qemu-kvm libvirt-bin virtinst libmysqld-dev -y
+ sudo pip install --upgrade pip
+ sudo pip install --upgrade ansible
+ sudo pip install --upgrade virtualenv
+ sudo service libvirt-bin restart
+
+ # prepare work dir
+ sudo rm -rf $WORK_DIR
+ mkdir -p $WORK_DIR
+ mkdir -p $WORK_DIR/installer
+ mkdir -p $WORK_DIR/vm
+ mkdir -p $WORK_DIR/network
+ mkdir -p $WORK_DIR/iso
+ mkdir -p $WORK_DIR/venv
-for plugin in vagrant-libvirt vagrant-mutate; do
- vagrant plugin list |grep $plugin
- if [[ $? != 0 ]]; then
- vagrant plugin install $plugin --plugin-source https://ruby.taobao.org
- else
- echo "$plugin plugin is already installed"
+ if [[ ! -f centos.iso ]];then
+ wget -O $WORK_DIR/iso/centos.iso $ISO_URL
fi
-done
-sudo pip install --upgrade ansible virtualenv
-#precise_box_vb_url=https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box
-#precise_box_vb_filename=$(basename ${precise_box_vb_url})
-centos65_box_vb_url=https://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.5-x86_64-v20140504.box
-centos65_box_vb_filename=$(basename ${centos65_box_vb_url})
-#wget ${precise_box_vb_url}
-vagrant box list |grep centos65
-if [[ $? != 0 ]]; then
- wget ${centos65_box_vb_url}
- mv ${centos65_box_vb_filename} centos65.box
- vagrant mutate centos65.box libvirt
-else
- echo "centos65 box already exists"
-fi
+
+ # copy compass
+ mkdir -p $WORK_DIR/mnt
+ sudo mount -o loop $WORK_DIR/iso/centos.iso $WORK_DIR/mnt
+ cp -rf $WORK_DIR/mnt/compass/compass-core $WORK_DIR/installer/
+ cp -rf $WORK_DIR/mnt/compass/compass-install $WORK_DIR/installer/
+ sudo umount $WORK_DIR/mnt
+ rm -rf $WORK_DIR/mnt
+
+ chmod 755 $WORK_DIR -R
+ virtualenv $WORK_DIR/venv
+}
diff --git a/compass/deploy/template/network/bridge.xml b/compass/deploy/template/network/bridge.xml
new file mode 100644
index 0000000..6202cf1
--- /dev/null
+++ b/compass/deploy/template/network/bridge.xml
@@ -0,0 +1,5 @@
+<network ipv6='no'>
+ <name>REPLACE_NAME</name>
+ <forward mode='bridge'>
+ </forward>
+</network>
diff --git a/compass/deploy/template/network/nat.xml b/compass/deploy/template/network/nat.xml
new file mode 100644
index 0000000..90ce888
--- /dev/null
+++ b/compass/deploy/template/network/nat.xml
@@ -0,0 +1,10 @@
+<network ipv6='yes'>
+ <name>REPLACE_NAME</name>
+ <forward mode='nat'/>
+ <bridge name='REPLACE_BRIDGE'/>
+ <ip address='REPLACE_GATEWAY' netmask='REPLACE_MASK'>
+ <!--dhcp>
+ <range start='REPLACE_START' end='REPLACE_END'/>
+ </dhcp-->
+ </ip>
+</network>
diff --git a/compass/deploy/template/vm/compass.xml b/compass/deploy/template/vm/compass.xml
new file mode 100644
index 0000000..918a9f2
--- /dev/null
+++ b/compass/deploy/template/vm/compass.xml
@@ -0,0 +1,64 @@
+<domain type='kvm'>
+ <name>compass</name>
+ <memory unit='MiB'>REPLACE_MEM</memory>
+ <currentMemory unit='MiB'>REPLACE_MEM</currentMemory>
+ <vcpu placement='static'>REPLACE_CPU</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
+ <boot dev='hd'/>
+ <boot dev='cdrom'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <cpu mode='host-model'>
+ <model fallback='allow'/>
+ <feature policy='optional' name='vmx'/>
+ <feature policy='optional' name='svm'/>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/kvm-spice</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='qcow2'/>
+ <source file='REPLACE_IMAGE'/>
+ <target dev='vda' bus='ide'/>
+ </disk>
+ <disk type='file' device='cdrom'>
+ <driver name='qemu' type='raw'/>
+ <source file='REPLACE_ISO'/>
+ <target dev='hdc' bus='ide'/>
+ <readonly/>
+ </disk>
+ <controller type='pci' index='0' model='pci-root'/>
+ <interface type='network'>
+ <source network='REPLACE_NET_MGMT'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+ </interface>
+ <interface type='bridge'>
+ <source bridge='REPLACE_BRIDGE_INSTALL'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </interface>
+ <serial type='pty'>
+ <target port='0'/>
+ </serial>
+ <console type='pty'>
+ <target type='serial' port='0'/>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'>
+ <listen type='address' address='0.0.0.0'/>
+ </graphics>
+ <video>
+ <model type='cirrus' vram='9216' heads='1'/>
+ </video>
+ </devices>
+</domain>
diff --git a/compass/deploy/template/vm/host.xml b/compass/deploy/template/vm/host.xml
new file mode 100644
index 0000000..b399e6f
--- /dev/null
+++ b/compass/deploy/template/vm/host.xml
@@ -0,0 +1,67 @@
+<domain type='kvm'>
+ <name>REPLACE_NAME</name>
+ <memory unit='MiB'>REPLACE_MEM</memory>
+ <currentMemory unit='MiB'>REPLACE_MEM</currentMemory>
+ <vcpu placement='static'>REPLACE_CPU</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>
+ <boot dev='hd'/>
+ <boot dev='network'/>
+ <bios useserial='yes' rebootTimeout='0'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/bin/kvm-spice</emulator>
+ <disk type='file' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source file='REPLACE_IMAGE'/>
+ <target dev='vda' bus='virtio'/>
+ </disk>
+ <interface type='bridge'>
+ <mac address=REPLACE_BOOT_MAC/>
+ <source bridge='REPLACE_BRIDGE_MGMT'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+ </interface>
+ <interface type='bridge'>
+ <source bridge='REPLACE_BRIDGE_TENANT'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
+ </interface>
+ <interface type='bridge'>
+ <source bridge='REPLACE_BRIDGE_PUBLIC'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
+ </interface>
+ <interface type='bridge'>
+ <source bridge='REPLACE_BRIDGE_STORAGE'/>
+ <model type='virtio'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+ </interface>
+ <serial type='pty'>
+ <source path='/dev/pts/0'/>
+ </serial>
+ <console type='pty' tty='/dev/pts/0'>
+ <source path='/dev/pts/0'/>
+ <target type='serial' port='0'/>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='5901' autoport='yes' listen='0.0.0.0'>
+ <listen type='address' address='0.0.0.0'/>
+ </graphics>
+ <video>
+ <model type='cirrus' vram='9216' heads='1'/>
+ <alias name='video0'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </video>
+ </devices>
+</domain>