61e65c79294c8544e81fc6007082b480e3bf3897
[releng.git] / jjb / doctor / doctor-env-presetup.sh
1 #!/usr/bin/env bash
2 set -o errexit
3 set -o pipefail
4
5 # set vars from env if not provided by user as options
6 installer_key_file=${installer_key_file:-$HOME/installer_key_file}
7 opnfv_installer=${opnfv_installer:-$HOME/opnfv-installer.sh}
8
9 # Fetch INSTALLER_IP for APEX deployments
10 if [[ ${INSTALLER_TYPE} == 'apex' ]]; then
11
12     echo "Gathering IP information for Apex installer VM"
13     ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
14     if sudo virsh list | grep undercloud; then
15         echo "Installer VM detected"
16         undercloud_mac=$(sudo virsh domiflist undercloud | grep default | \
17                   grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
18         export INSTALLER_IP=$(/usr/sbin/arp -e | grep ${undercloud_mac} | awk {'print $1'})
19         echo "Installer ip is ${INSTALLER_IP}"
20     else
21         echo "No available installer VM exists and no credentials provided...exiting"
22         exit 1
23     fi
24
25     sudo cp /root/.ssh/id_rsa ${installer_key_file}
26     sudo chown `whoami`:`whoami` ${installer_key_file}
27
28 elif [[ ${INSTALLER_TYPE} == 'daisy' ]]; then
29     echo "Gathering IP information for Daisy installer VM"
30     if sudo virsh list | grep daisy; then
31         echo "Installer VM detected"
32
33         bridge_name=$(sudo virsh domiflist daisy | grep vnet | awk '{print $3}')
34         echo "Bridge is $bridge_name"
35
36         installer_mac=$(sudo virsh domiflist daisy | grep vnet | \
37                       grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
38         export INSTALLER_IP=$(/usr/sbin/arp -e -i $bridge_name | grep ${installer_mac} | head -n 1 | awk {'print $1'})
39
40         echo "Installer ip is ${INSTALLER_IP}"
41     else
42         echo "No available installer VM exists...exiting"
43         exit 1
44     fi
45 fi
46
47
48 # Checking if destination path is valid
49 if [ -d $opnfv_installer ]; then
50     error "Please provide the full destination path for the installer ip file including the filename"
51 else
52     # Check if we can create the file (e.g. path is correct)
53     touch $opnfv_installer || error "Cannot create the file specified. Check that the path is correct and run the script again."
54 fi
55
56
57 # Write the installer info to the file
58 echo export INSTALLER_TYPE=${INSTALLER_TYPE} > $opnfv_installer
59 echo export INSTALLER_IP=${INSTALLER_IP} >> $opnfv_installer
60 if [ -e ${installer_key_file} ]; then
61     echo export SSH_KEY=${installer_key_file} >> $opnfv_installer
62 fi