Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Denis Egorenko | 0d045ae | 2019-06-04 18:23:11 +0400 | [diff] [blame] | 3 | set -e |
| 4 | |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 5 | functionsFile="$(pwd)/functions.sh" |
| 6 | |
| 7 | if [[ ! -f ${functionsFile} ]]; then |
| 8 | echo "ERROR: Can not find 'functions' libfile (${functionsFile}), check your mcp/mcp-common-scripts repo." |
| 9 | exit 1 |
| 10 | else |
| 11 | source ${functionsFile} |
| 12 | fi |
| 13 | |
| 14 | if [[ -z ${SLAVE_VM_NAME} ]]; then |
| 15 | echo "ERROR: \$SLAVE_VM_NAME not set!" |
| 16 | exit 1 |
| 17 | fi |
| 18 | if [[ -z ${SLAVE_VM_SOURCE_DISK} ]] || [[ ! -f ${SLAVE_VM_SOURCE_DISK} ]]; then |
| 19 | echo "ERROR: \$SLAVE_VM_SOURCE_DISK not set, or file does not exist!" |
| 20 | exit 1 |
| 21 | fi |
| 22 | if [[ -z ${VM_CONFIG_DISK} ]] || [[ ! -f ${VM_CONFIG_DISK} ]]; then |
| 23 | echo "ERROR: \$VM_CONFIG_DISK not set, or file does not exist!" |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 27 | prereq_check "slave" |
| 28 | |
| 29 | qemu-img resize ${SLAVE_VM_SOURCE_DISK} 80G |
| 30 | #### Make sure that disk saved to system path which is available for libvirt-qemu:kvm |
| 31 | export SLAVE_VM_SOURCE_DISK=$(place_file_under_libvirt_owned_dir ${SLAVE_VM_SOURCE_DISK} ${NON_DEFAULT_LIBVIRT_DIR}) |
| 32 | |
| 33 | ### Create simple ISO file for a slave vm |
| 34 | networkDataFileBaseName='network_data.json' |
| 35 | networkDataFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "${networkDataFileBaseName}") |
| 36 | contextFilePath=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "context_data.yml") |
| 37 | allocationDataFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "allocation_data.yml") |
| 38 | saltMasterIp=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${allocationDataFile} | grep -w 'infra_config_deploy_address' | cut -f 2 -d ':' | tr -d ' ') |
| 39 | clusterDomain=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${contextFilePath} | grep -w 'cluster_domain:' | cut -f 2 -d ':' | tr -d ' ') |
| 40 | aioIp=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${allocationDataFile} | grep -w 'aio_node_deploy_address:' | cut -f 2 -d ':' | tr -d ' ') |
| 41 | aioHostname=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${allocationDataFile} | grep -w 'aio_node_hostname:' | cut -f 2 -d ':' | tr -d ' ') |
| 42 | aioFailSafeUserKey=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${contextFilePath} | grep -w 'cfg_failsafe_ssh_public_key:' | cut -f 2 -d ':' | sed 's/ //') |
| 43 | aioFailSafeUser=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${contextFilePath} | grep -w 'cfg_failsafe_user:' | cut -f 2 -d ':' | tr -d ' ') |
| 44 | networkDataForSlave=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${networkDataFile} | sed -e "s/${saltMasterIp}/${aioIp}/g") |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 45 | |
| 46 | configDriveDir="$(dirname $0)/../config-drive" |
| 47 | pushd "${configDriveDir}" |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 48 | echo -e ${networkDataForSlave} > ${networkDataFileBaseName} |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 49 | cat <<EOF > ./user_data |
| 50 | #cloud-config |
| 51 | output : { all : '| tee -a /var/log/cloud-init-output.log' } |
| 52 | growpart: |
| 53 | mode: auto |
| 54 | devices: |
| 55 | - '/' |
| 56 | - '/dev/vda3' |
| 57 | ignore_growroot_disabled: false |
| 58 | write_files: |
| 59 | - content: | |
| 60 | root: |
| 61 | size: '70%VG' |
| 62 | var_log: |
| 63 | size: '10%VG' |
| 64 | var_log_audit: |
| 65 | size: '500M' |
| 66 | var_tmp: |
| 67 | size: '3000M' |
| 68 | tmp: |
| 69 | size: '500M' |
| 70 | owner: root:root |
| 71 | path: /usr/share/growlvm/image-layout.yml |
| 72 | slave_boot: |
| 73 | - &slave_boot | |
| 74 | #!/bin/bash |
| 75 | |
| 76 | # Redirect all outputs |
| 77 | exec > >(tee -i /tmp/cloud-init-bootstrap.log) 2>&1 |
| 78 | set -xe |
| 79 | |
| 80 | echo "Configuring Salt minion ..." |
| 81 | [ ! -d /etc/salt/minion.d ] && mkdir -p /etc/salt/minion.d |
| 82 | echo -e "id: ${aioHostname}.${clusterDomain}\nmaster: ${saltMasterIp}" > /etc/salt/minion.d/minion.conf |
| 83 | cat >> /etc/salt/minion.d/minion.conf << EOF |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 84 | log_level: info |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 85 | max_event_size: 100000000 |
| 86 | acceptance_wait_time_max: 60 |
| 87 | acceptance_wait_time: 10 |
| 88 | random_reauth_delay: 270 |
| 89 | recon_default: 1000 |
| 90 | recon_max: 60000 |
| 91 | recon_randomize: True |
| 92 | auth_timeout: 60 |
| 93 | EOF |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 94 | |
| 95 | systemctl restart salt-minion |
| 96 | sleep 90 |
| 97 | cat /var/log/salt/minion |
| 98 | sync |
| 99 | |
| 100 | |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 101 | runcmd: |
| 102 | - 'if lvs vg0; then pvresize /dev/vda3; fi' |
| 103 | - 'if lvs vg0; then /usr/bin/growlvm.py --image-layout-file /usr/share/growlvm/image-layout.yml; fi' |
| 104 | - [bash, -cex, *slave_boot] |
| 105 | EOF |
| 106 | |
Denis Egorenko | f6432c8 | 2019-04-26 19:19:04 +0400 | [diff] [blame] | 107 | isoArgs="--name ${aioHostname} --hostname ${aioHostname}.${clusterDomain} --user-data $(pwd)/user_data --network-data $(pwd)/${networkDataFileBaseName} --quiet --clean-up" |
| 108 | if [[ -n "${aioFailSafeUser}" ]] && [[ -n "${aioFailSafeUserKey}" ]]; then |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 109 | echo "${aioFailSafeUserKey}" > "failSafeKey.pub" |
| 110 | isoArgs="${isoArgs} --cloud-user-name ${aioFailSafeUser} --ssh-keys failSafeKey.pub" |
Denis Egorenko | f6432c8 | 2019-04-26 19:19:04 +0400 | [diff] [blame] | 111 | fi |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 112 | python ./create_config_drive.py ${isoArgs} |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 113 | #### Make sure that iso file is saved to system path which is available for libvirt-qemu:kvm |
| 114 | export SLAVE_VM_CONFIG_DISK=$(place_file_under_libvirt_owned_dir ${aioHostname}.${clusterDomain}-config.iso ${NON_DEFAULT_LIBVIRT_DIR}) |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 115 | popd |
| 116 | |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 117 | render_config "${SLAVE_VM_NAME}" "${SLAVE_VM_MEM_KB}" "${SLAVE_VM_CPUS}" "${SLAVE_VM_SOURCE_DISK}" "${SLAVE_VM_CONFIG_DISK}" |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 118 | |
| 119 | virsh define $(pwd)/${SLAVE_VM_NAME}-vm.xml |
| 120 | virsh autostart ${SLAVE_VM_NAME} |
Denis Egorenko | 0d045ae | 2019-06-04 18:23:11 +0400 | [diff] [blame] | 121 | |
| 122 | openstackAIOFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "setup_aio.yml") |
| 123 | openstackScheme=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${openstackAIOFile} | grep -w 'cluster_public_protocol' | cut -f 2 -d ':' | tr -d ' ') |
| 124 | openstackAddress=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${allocationDataFile} | grep -w 'aio_node_address' | cut -f 2 -d ':' | tr -d ' ') |
| 125 | secretsFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "infra/secrets.yml") |
| 126 | openstackPassword=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${secretsFile} | grep -w 'keystone_admin_password_generated' | cut -f 2 -d ':' | tr -d ' ') |
| 127 | echo "Once OpenStack deploy job is finished successfully OpenStack UI will be available on: ${openstackScheme}://${openstackAddress}:8078" |
| 128 | echo "Login creds are: admin / ${openstackPassword}" |