Denis Egorenko | 0d045ae | 2019-06-04 18:23:11 +0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 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 |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 13 | |
| 14 | if [[ -z ${VM_NAME} ]]; then |
| 15 | echo "ERROR: \$VM_NAME not set!" |
| 16 | exit 1 |
| 17 | fi |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 18 | if [[ -z ${VM_SOURCE_DISK} ]] || [[ ! -f ${VM_SOURCE_DISK} ]]; then |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 19 | echo "ERROR: \$VM_SOURCE_DISK not set, or file does not exist!" |
| 20 | exit 1 |
| 21 | fi |
Denis Egorenko | c265640 | 2019-04-19 18:17:50 +0400 | [diff] [blame] | 22 | if [[ -z ${VM_CONFIG_DISK} ]] || [[ ! -f ${VM_CONFIG_DISK} ]]; then |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 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 |
Denis Egorenko | dcc233d | 2019-03-06 18:09:24 +0400 | [diff] [blame] | 28 | |
Denis Egorenko | abe23c5 | 2019-05-30 16:53:55 +0400 | [diff] [blame] | 29 | #### Make sure that both files are saved to system path which is available for libvirt-qemu:kvm |
| 30 | export VM_SOURCE_DISK=$(place_file_under_libvirt_owned_dir ${VM_SOURCE_DISK} ${NON_DEFAULT_LIBVIRT_DIR}) |
| 31 | export VM_CONFIG_DISK=$(place_file_under_libvirt_owned_dir ${VM_CONFIG_DISK} ${NON_DEFAULT_LIBVIRT_DIR}) |
| 32 | |
| 33 | render_config "${VM_NAME}" "${VM_MEM_KB}" "${VM_CPUS}" "${VM_SOURCE_DISK}" "${VM_CONFIG_DISK}" |
alexz | 1c02cd6 | 2018-04-15 22:18:03 +0200 | [diff] [blame] | 34 | |
| 35 | virsh define $(pwd)/${VM_NAME}-vm.xml |
| 36 | virsh autostart ${VM_NAME} |
Denis Egorenko | 892089e | 2019-07-12 16:01:40 +0400 | [diff] [blame] | 37 | |
| 38 | allocationDataFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep -w "allocation_data.yml") |
| 39 | secretsFile=$(isoinfo -i ${VM_CONFIG_DISK} -J -f | grep "infra/secrets.yml") |
Denis Egorenko | 6cb6052 | 2019-07-17 21:36:52 +0400 | [diff] [blame] | 40 | cfgJenkinsPassword=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${secretsFile} | grep 'jenkins_cfg_admin_password_generated' | cut -f 2 -d ':' | tr -d ' ') |
| 41 | cfgJenkinsAddress=$(isoinfo -i ${VM_CONFIG_DISK} -J -x ${allocationDataFile} | grep 'infra_config_deploy_address' | cut -f 2 -d ':' | tr -d ' ') |
Denis Egorenko | 892089e | 2019-07-12 16:01:40 +0400 | [diff] [blame] | 42 | echo "Once deployed, Jenkins will be available via: http://${cfgJenkinsAddress}:8081 and login creds are: admin / ${cfgJenkinsPassword}" |