summaryrefslogtreecommitdiffstats
path: root/jjb/doctor/doctor-env-presetup.sh
blob: 61e65c79294c8544e81fc6007082b480e3bf3897 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
set -o errexit
set -o pipefail

# set vars from env if not provided by user as options
installer_key_file=${installer_key_file:-$HOME/installer_key_file}
opnfv_installer=${opnfv_installer:-$HOME/opnfv-installer.sh}

# Fetch INSTALLER_IP for APEX deployments
if [[ ${INSTALLER_TYPE} == 'apex' ]]; then

    echo "Gathering IP information for Apex installer VM"
    ssh_options="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
    if sudo virsh list | grep undercloud; then
        echo "Installer VM detected"
        undercloud_mac=$(sudo virsh domiflist undercloud | grep default | \
                  grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
        export INSTALLER_IP=$(/usr/sbin/arp -e | grep ${undercloud_mac} | awk {'print $1'})
        echo "Installer ip is ${INSTALLER_IP}"
    else
        echo "No available installer VM exists and no credentials provided...exiting"
        exit 1
    fi

    sudo cp /root/.ssh/id_rsa ${installer_key_file}
    sudo chown `whoami`:`whoami` ${installer_key_file}

elif [[ ${INSTALLER_TYPE} == 'daisy' ]]; then
    echo "Gathering IP information for Daisy installer VM"
    if sudo virsh list | grep daisy; then
        echo "Installer VM detected"

        bridge_name=$(sudo virsh domiflist daisy | grep vnet | awk '{print $3}')
        echo "Bridge is $bridge_name"

        installer_mac=$(sudo virsh domiflist daisy | grep vnet | \
                      grep -Eo "[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+")
        export INSTALLER_IP=$(/usr/sbin/arp -e -i $bridge_name | grep ${installer_mac} | head -n 1 | awk {'print $1'})

        echo "Installer ip is ${INSTALLER_IP}"
    else
        echo "No available installer VM exists...exiting"
        exit 1
    fi
fi


# Checking if destination path is valid
if [ -d $opnfv_installer ]; then
    error "Please provide the full destination path for the installer ip file including the filename"
else
    # Check if we can create the file (e.g. path is correct)
    touch $opnfv_installer || error "Cannot create the file specified. Check that the path is correct and run the script again."
fi


# Write the installer info to the file
echo export INSTALLER_TYPE=${INSTALLER_TYPE} > $opnfv_installer
echo export INSTALLER_IP=${INSTALLER_IP} >> $opnfv_installer
if [ -e ${installer_key_file} ]; then
    echo export SSH_KEY=${installer_key_file} >> $opnfv_installer
fi