Parpare ssh_key for MCP in doctor
[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
46 elif [[ ${INSTALLER_TYPE} == 'fuel' ]]; then
47     if [[ ! "${BRANCH}" =~ "danube" ]]; then
48         export SSH_KEY=${SSH_KEY:-/var/lib/opnfv/mcp.rsa}
49         sudo cp ${SSH_KEY} ${installer_key_file}
50         sudo chown `whoami`:`whoami` ${installer_key_file}
51     fi
52 fi
53
54
55 # Checking if destination path is valid
56 if [ -d $opnfv_installer ]; then
57     error "Please provide the full destination path for the installer ip file including the filename"
58 else
59     # Check if we can create the file (e.g. path is correct)
60     touch $opnfv_installer || error "Cannot create the file specified. Check that the path is correct and run the script again."
61 fi
62
63
64 # Write the installer info to the file
65 echo export INSTALLER_TYPE=${INSTALLER_TYPE} > $opnfv_installer
66 echo export INSTALLER_IP=${INSTALLER_IP} >> $opnfv_installer
67 if [ -e ${installer_key_file} ]; then
68     echo export SSH_KEY=${installer_key_file} >> $opnfv_installer
69 fi