Commit 62951cfb authored by David Johnson's avatar David Johnson

Autocreate Capnet networks, and user/service tenant projects.

This script, setup-capnet-basic.sh, can be run as many times as you
want... it checks to see if everything it creates already exists.

We create 4 user/service project/user tandems by default.

The idea is that each "user" project is where the project user allocates
nodes, and its master wfa looks up another service wfa at the broker,
and gives node caps to the service wfa.

The projects and users are generically named for now... we still don't
run any wfas by default.
parent 9ef9388c
Pipeline #1231 skipped
#!/bin/sh
##
## This script sets up Capnet networks, multiple tenants, drags in a
## hadoop image, wfagents for a hadoop demo, etc. All Capnet networks
## are "shared" by default, meaning that any tenant can plug into them.
## Obviously, the tenants still have to exchange caps to have their
## nodes or wfagents talk.
##
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
CAPNET_AUTO_ALLPAIRS_WFA="0"
# Grab our libs
. "$DIRNAME/../../setup-lib.sh"
if [ "$HOSTNAME" != "$CONTROLLER" ]; then
exit 0;
fi
if [ -f $SETTINGS ]; then
. $SETTINGS
fi
. $OURDIR/admin-openrc.sh
#
# openstack CLI commands seem flakey sometimes on Kilo and Liberty.
# Don't know if it's WSGI, mysql dropping connections, an NTP
# thing... but until it gets solved more permanently, have to retry :(.
#
__openstack() {
__err=1
__debug=
__times=0
while [ $__times -lt 16 -a ! $__err -eq 0 ]; do
openstack $__debug "$@"
__err=$?
if [ $__err -eq 0 ]; then
break
fi
__debug=" --debug "
__times=`expr $__times + 1`
if [ $__times -gt 1 ]; then
echo "ERROR: openstack command failed: sleeping and trying again!"
sleep 8
fi
done
}
for lan in ${DATAOTHERLANS} ; do
. $OURDIR/info.${lan}
name="$lan"
echo "*** Creating Capnet data network ${lan} and subnet ..."
nmdataip=`cat $OURDIR/data-hosts.${lan} | grep ${NETWORKMANAGER} | sed -n -e 's/^\([0-9]*.[0-9]*.[0-9]*.[0-9]*\).*$/\1/p'`
allocation_pool=`cat $OURDIR/data-allocation-pool.${lan}`
cidr=`cat $OURDIR/data-cidr.${lan}`
# Make sure to set the right gateway IP (to our router)
routeripaddr=`cat $OURDIR/router-ipaddr.$lan`
neutron net-show ${name}-net
if [ ! $? -eq 0 ]; then
neutron net-create ${name}-net --shared \
--provider:physical_network ${lan} --provider:network_type capnet
fi
neutron subnet-show ${name}-subnet
if [ ! $? -eq 0 ]; then
neutron subnet-create ${name}-net --name ${name}-subnet \
--allocation-pool ${allocation_pool} --gateway $routeripaddr $cidr
fi
subnetid=`neutron subnet-show ${name}-subnet | awk '/ id / {print $4}'`
neutron router-show ${name}-router
if [ ! $? -eq 0 ]; then
neutron router-create ${name}-router
fi
# See if it has a port; if so, don't add
neutron router-port-list ${name}-router | grep -q subnet_id
if [ ! $? -eq 0 ]; then
neutron router-interface-add ${name}-router ${name}-subnet
fi
#if [ $PUBLICCOUNT -ge 3 ] ; then
# neutron router-gateway-set ${name}-router ext-net
#fi
# Fix up the dhcp agent port IP addr. We can't set this in the
# creation command, so do a port update!
#ports=`neutron port-list | grep $subnetid | awk '{print $2}'`
#for port in $ports ; do
# owner=`neutron port-show $port | awk '/ device_owner / {print $4}'`
#if [ "x$owner" = "xnetwork:router_interface" -a -f $OURDIR/router-ipaddr.$lan ]; then
# newipaddr=`cat $OURDIR/router-ipaddr.$lan`
# neutron port-update $port --fixed-ip subnet_id=$subnetid,ip_address=$newipaddr
#fi
# if [ "x$owner" = "xnetwork:dhcp" -a -f $OURDIR/dhcp-agent-ipaddr.$lan ]; then
# newipaddr=`cat $OURDIR/dhcp-agent-ipaddr.$lan`
# neutron port-update $port --fixed-ip subnet_id=$subnetid,ip_address=$newipaddr
# fi
#done
# Don't create a workflow agent -- probably in the future create a
# default secgroup one, or something.
if [ $CAPNET_AUTO_ALLPAIRS_WFA = "1" ]; then
neutron capnet-wfagent-create --name wfa0 \
--master --wfapp_path=/usr/bin/capnet-wfagent-allpairs ${name}-net
fi
done
##
## Create some tenants, and service tenants, and users in them (using the
## admin password).
##
if [ "x${ADMIN_PASS}" = "x" ]; then
# Create the admin user -- temporarily use the random one for
# ${ADMIN_API}; we change it right away below manually via sql
APSWD="${ADMIN_API_PASS}"
else
APSWD="${ADMIN_PASS}"
fi
DOMARG=""
#if [ $OSVERSION -gt $OSKILO ]; then
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
DOMARG="--domain default"
fi
i=0
while [ $i -lt 4 ]; do
# Create the resource/compute tenant/user
__openstack project list | grep " tenant-$i "
if [ ! $? -eq 0 ]; then
__openstack project create $DOMARG \
--description "tenant-$i Project" tenant-$i
fi
__openstack user list | grep " tenant-$i-user "
if [ ! $? -eq 0 ]; then
__openstack user create $DOMARG --password "${APSWD}" \
--email "${SWAPPER_EMAIL}" tenant-$i-user
#__openstack role add --project admin --user admin admin
__openstack role add --project tenant-$i --user tenant-$i-user user
fi
# Create the service tenant/user
__openstack project list | grep " service-$i "
if [ ! $? -eq 0 ]; then
__openstack project create $DOMARG \
--description "service-$i Project" service-$i
fi
__openstack user list | grep " service-$i-user "
if [ ! $? -eq 0 ]; then
__openstack user create $DOMARG --password "${APSWD}" \
--email "${SWAPPER_EMAIL}" service-$i-user
#__openstack role add --project admin --user admin admin
__openstack role add --project service-$i --user service-$i-user user
fi
i=`expr $i + 1`
done
......@@ -28,30 +28,6 @@ if [ -f $SETTINGS ]; then
. $SETTINGS
fi
#
# openstack CLI commands seem flakey sometimes on Kilo and Liberty.
# Don't know if it's WSGI, mysql dropping connections, an NTP
# thing... but until it gets solved more permanently, have to retry :(.
#
__openstack() {
__err=1
__debug=
__times=0
while [ $__times -lt 16 -a ! $__err -eq 0 ]; do
openstack $__debug "$@"
__err=$?
if [ $__err -eq 0 ]; then
break
fi
__debug=" --debug "
__times=`expr $__times + 1`
if [ $__times -gt 1 ]; then
echo "ERROR: openstack command failed: sleeping and trying again!"
sleep 8
fi
done
}
maybe_install_packages pssh
PSSH='/usr/bin/parallel-ssh -t 0 -O StrictHostKeyChecking=no '
......@@ -96,9 +72,7 @@ $PSSH $CPHOSTS -o capnet-logs/stdout -e capnet-logs/stderr $DIRNAME/setup-capnet
##
## Finally, we create initial networks!
##
#. $OURDIR/admin-openrc.sh
$DIRNAME/setup-capnet-basic.sh
echo "Done with Capnet Setup!"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment