summaryrefslogtreecommitdiffstats
path: root/scripts/post_apex.sh
blob: d38ddd476e78972b6558dba5e0026d062f08c62d (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
##############################################################################
# Copyright (c) 2017 Juraj Linkes (Cisco) and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
#!/bin/bash
SCRIPT_DIR=$(dirname "$0")
. $SCRIPT_DIR/lib.sh
UNDERCLOUD_IP=$(arp -a | grep $(virsh domiflist undercloud | grep default | awk '{print $5}') \
    | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+")
#echo $UNDERCLOUD_IP

# copy rc file to jumphost
echo "Copying overcloud rc to jumphost to $overcloudrc_path"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$UNDERCLOUD_IP:/home/stack/overcloudrc.v3 \
    $overcloudrc_path &> /dev/null

# copy jumphost root key to undercloud vm - needs $UNDERCLOUD_IP
echo "Copying root's public ssh key to undercloud vm"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /root/.ssh/id_rsa.pub \
    root@$UNDERCLOUD_IP:/home/stack/id_rsa_jumphost_root.pub &> /dev/null

# copy key copying script to undercloud vm
echo "Copying ssh setup script to undercloud vm"
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SCRIPT_DIR/copy_keys.sh \
    root@$UNDERCLOUD_IP:/home/stack &> /dev/null

#overcloud_dir="/root/.overcloud"
#node_list_filename="$overcloud_dir/node_list"
#mkdir -p $overcloud_dir
sed -i "/$NODE_PATTERN/d" /etc/hosts
OIFS="$IFS"
IFS=$'\n'
nova_list=$(ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null stack@$UNDERCLOUD_IP \
    ". stackrc && nova list | tail -n+4 | head -n-1 | sed 's/ //g'" 2> /dev/null)
node_list=($nova_list)
IFS="$OIFS"
for node in "${node_list[@]}"
do
    echo
    node_fields=$(echo $node | cut -d "|" -f 3,7)
    node_name=$(echo $node_fields | cut -d "|" -f 1)
    node_ip=$(echo $node_fields | cut -d "=" -f 2)
    echo "Adding $node_name to /etc/hosts"
    echo $node_ip $node_name >> /etc/hosts
    echo "Removing $node_ip from known hosts"
    sed -i "/$node_ip/d" /root/.ssh/known_hosts
    echo "Removing $node_name from known hosts"
    sed -i "/$node_name/d" /root/.ssh/known_hosts
    echo "Setting up ssh keys on $node_name for root"
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null stack@$UNDERCLOUD_IP \
        "/home/stack/copy_keys.sh $node_ip &" &> /dev/null
    echo "Copying overcloudrc to $node_name"
    scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $overcloudrc_path heat-admin@$node_ip:. &> /dev/null
    ssh -oStrictHostKeyChecking=no heat-admin@$node_ip 'sudo cp /home/heat-admin/overcloudrc /root' &> /dev/null
    echo "Cloning fds repo on $node_name to $overcloud_fds_repo_loc"
    ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $node_name \
        'git clone https://gerrit.opnfv.org/gerrit/p/fds.git $overcloud_fds_repo_loc' &> /dev/null
    if [[ $(ssh -oStrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$node_ip \
        'grep -c ". /root/overcloudrc" /root/.bashrc' 2> /dev/null) -eq 0 ]]
    then
        echo "Setting up . /root/overcloudrc in .bashrc on $node_name"
        ssh -oStrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$node_ip \
        'echo ". /root/overcloudrc" >> /root/.bashrc' &> /dev/null
    fi
done
. $overcloudrc_path
echo
openstack flavor list | grep nfv > /dev/null
if [[ ! $? -eq 0 ]]
then
    echo "Configuring flavor nfv"
    openstack flavor create nfv --ram 768 --property hw:mem_page_size=large
else
    echo "Flavor nfv is already configured"
fi

echo
openstack image list | grep cirros-0.3.4 > /dev/null
if [[ ! $? -eq 0 ]]
then
    echo "Configuring image cirros-0.3.4"
    image_loc=/root/cirros-0.3.4-x86_64-disk.img
    if [[ ! -f $image_loc ]]
    then
        echo "Downloading cirros image to $image_loc"
        wget https://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img -O $image_loc
    fi
    openstack image create --disk-format qcow2 --container-format bare --public --property hw_mem_page_size=large \
        --file $image_loc cirros-0.3.4
else
    echo "Image cirros-0.3.4 is already configured"
fi

echo
echo "Post-apex script is done."