setup-driver.sh 3.53 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/sh

set -x

DIRNAME=`dirname $0`

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "$DIRNAME/setup-lib.sh"
15
logtstart "driver"
16

17 18 19
# Copy our source code into $OURDIR for future use:
echo "*** Copying source code into $OURDIR/bin ..."
mkdir -p $OURDIR/bin
David Johnson's avatar
David Johnson committed
20
rsync -avz $DIRNAME/ $OURDIR/bin/
21

22 23
echo "*** Setting up root ssh pubkey access across all nodes..."

24 25 26
# All nodes need to publish public keys, and acquire others'
$DIRNAME/setup-root-ssh.sh 1> $OURDIR/setup-root-ssh.log 2>&1

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
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi

if [ "$HOSTNAME" = "$NETWORKMANAGER" ]; then

    echo "*** Waiting for ssh access to all nodes..."

    for node in $NODES ; do
	[ "$node" = "$NETWORKMANAGER" ] && continue

	SUCCESS=1
	fqdn=`getfqdn $node`
	while [ $SUCCESS -ne 0 ] ; do
	    sleep 1
	    ssh -o ConnectTimeout=1 -o PasswordAuthentication=No -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=No $fqdn /bin/ls > /dev/null
	    SUCCESS=$?
	done
	echo "*** $node is up!"
    done

    #
    # Get our hosts files setup to point to the new management network.
    # (These were created one-time in setup-lib.sh)
    #
52 53 54 55
    cat $OURDIR/mgmt-hosts > /etc/hosts.tmp
    cp -p /etc/hosts $OURDIR/hosts.orig
    cat $OURDIR/hosts.orig >> /etc/hosts.tmp
    mv /etc/hosts.tmp /etc/hosts
56 57 58
    for node in $NODES 
    do
	[ "$node" = "$NETWORKMANAGER" ] && continue
59 60 61
	#if unified ; then
	#    continue
	#fi
62 63 64

	fqdn=`getfqdn $node`
	$SSH $fqdn mkdir -p $OURDIR
65 66 67 68
	#scp -p -o StrictHostKeyChecking=no \
	    #$SETTINGS $OURDIR/mgmt-hosts $OURDIR/mgmt-netmask \
	    #$OURDIR/data-hosts $OURDIR/data-netmask \
	    #$fqdn:$OURDIR
69
	scp -p -o StrictHostKeyChecking=no \
70 71 72 73
	    $OURDIR/mgmt-hosts $fqdn:$OURDIR
	# For now, just insert the new hosts in front of the existing ones.
	# setup-{ovs,linuxbridge}-node.sh may do differently.
	$SSH $fqdn "cp -p /etc/hosts $OURDIR/hosts.orig ; cat $OURDIR/mgmt-hosts > /etc/hosts.tmp ; cat $OURDIR/hosts.orig >> /etc/hosts.tmp ; mv /etc/hosts.tmp /etc/hosts"
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    done

    echo "*** Setting up the Management Network"

    if [ -z "${MGMTLAN}" ]; then
	echo "*** Building a VPN-based Management Network"

	$DIRNAME/setup-vpn.sh 1> $OURDIR/setup-vpn.log 2>&1

        # Give the VPN a chance to settle down
	PINGED=0
	while [ $PINGED -eq 0 ]; do
	    sleep 2
	    ping -c 1 $CONTROLLER
	    if [ $? -eq 0 ]; then
		PINGED=1
	    fi
	done
    else
	echo "*** Using $MGMTLAN as the Management Network"
    fi

96 97
    if [ "${ML2PLUGIN}" = "openvswitch" ]; then
	echo "*** Moving Interfaces into OpenVSwitch Bridges"
98

99 100 101 102 103 104
	$DIRNAME/setup-ovs.sh 1> $OURDIR/setup-ovs.log 2>&1
    else
	echo "*** Setting up Linux Bridge static network configuration"

	$DIRNAME/setup-linuxbridge.sh 1> $OURDIR/setup-linuxbridge.log 2>&1
    fi
105 106 107 108 109 110

    echo "*** Telling controller to set up OpenStack!"

    ssh -o StrictHostKeyChecking=no ${CONTROLLER} "/bin/touch $OURDIR/networkmanager-driver-done"
fi

111 112 113 114 115 116 117 118 119 120 121
if [ "$HOSTNAME" = "$CONTROLLER" ]; then
    #
    # Wait for networkmanager setup to touch a special file indicating that
    # it's finished all the network stuff and we should setup the controller.
    #
    echo "*** Waiting for networkmanager to finish network configuration..."

    while [ ! -f $OURDIR/networkmanager-driver-done ]; do
	sleep 1
    done

122 123
    logtend "driver"

124 125 126 127 128 129
    echo "*** Building an Openstack!"

    exec /bin/sh -c "$DIRNAME/setup-controller.sh 1> $OURDIR/setup-controller.log 2>&1 </dev/null"

    exit 1
elif [ "$HOSTNAME" != "$NETWORKMANAGER" ]; then
130
    logtend "driver"
131 132 133
    exit 0;
fi

134
logtend "driver"
135
exit 0