1 compass_vm_dir=$WORK_DIR/vm/compass
2 rsa_file=$compass_vm_dir/boot.rsa
3 ssh_args="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $rsa_file"
4 function tear_down_compass() {
5 sudo virsh destroy compass > /dev/null 2>&1
6 sudo virsh undefine compass > /dev/null 2>&1
8 sudo umount $compass_vm_dir/old > /dev/null 2>&1
9 sudo umount $compass_vm_dir/new > /dev/null 2>&1
11 sudo rm -rf $compass_vm_dir
13 log_info "tear_down_compass success!!!"
16 function install_compass_core() {
17 local inventory_file=$compass_vm_dir/inventory.file
18 log_info "install_compass_core enter"
19 sed -i "s/mgmt_next_ip:.*/mgmt_next_ip: ${COMPASS_SERVER}/g" $WORK_DIR/installer/compass-install/install/group_vars/all
20 echo "compass_nodocker ansible_ssh_host=$MGMT_IP ansible_ssh_port=22" > $inventory_file
21 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
24 log_info "install_compass_core exit"
25 if [[ $exit_status != 0 ]];then
31 log_info "wait_compass_ok enter"
33 until timeout 1s ssh $ssh_args root@$MGMT_IP "exit" 2>/dev/null
35 log_progress "os install time used: $((retry*100/$1))%"
38 if [[ $retry -ge $1 ]];then
39 log_error "os install time out"
45 log_warn "os install time used: 100%"
46 log_info "wait_compass_ok exit"
49 function launch_compass() {
50 local old_mnt=$compass_vm_dir/old
51 local new_mnt=$compass_vm_dir/new
52 local old_iso=$WORK_DIR/iso/centos.iso
53 local new_iso=$compass_vm_dir/centos.iso
55 log_info "launch_compass enter"
59 mkdir -p $compass_vm_dir $old_mnt
60 sudo mount -o loop $old_iso $old_mnt
61 cd $old_mnt;find .|cpio -pd $new_mnt;cd -
66 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
68 sudo ssh-keygen -f $new_mnt/bootstrap/boot.rsa -t rsa -N ''
69 cp $new_mnt/bootstrap/boot.rsa $rsa_file
71 rm -rf $new_mnt/.rr_moved $new_mnt/rr_moved
72 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
74 rm -rf $old_mnt $new_mnt
76 qemu-img create -f qcow2 $compass_vm_dir/disk.img 100G
79 sed -e "s/REPLACE_MEM/$COMPASS_VIRT_MEM/g" \
80 -e "s/REPLACE_CPU/$COMPASS_VIRT_CPUS/g" \
81 -e "s#REPLACE_IMAGE#$compass_vm_dir/disk.img#g" \
82 -e "s#REPLACE_ISO#$compass_vm_dir/centos.iso#g" \
83 -e "s/REPLACE_NET_MGMT/mgmt/g" \
84 -e "s/REPLACE_BRIDGE_INSTALL/br_install/g" \
85 $COMPASS_DIR/deploy/template/vm/compass.xml \
86 > $WORK_DIR/vm/compass/libvirt.xml
88 sudo virsh define $compass_vm_dir/libvirt.xml
89 sudo virsh start compass
92 log_error "install os timeout"
96 if ! install_compass_core;then
97 log_error "install compass core failed"
102 log_info "launch_compass exit"