Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -x |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 3 | |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 4 | # This script assumes that it is being run on the ctl node of the OpenStack |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 5 | # profile on CloudLab. |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 6 | |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 7 | XOS="http://ctl:9999/" |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 8 | AUTH="padmin@vicci.org:letmein" |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 9 | CORD=0 |
| 10 | IMAGE="xos" |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 11 | |
Andy Bavier | 8954c2e | 2015-09-01 14:19:11 -0400 | [diff] [blame] | 12 | # Create public key if none present |
Andy Bavier | f422f2c | 2015-09-01 18:02:28 -0400 | [diff] [blame] | 13 | [ -e ~/.ssh/id_rsa ] || cat /dev/zero | ssh-keygen -q -N "" |
Andy Bavier | 8954c2e | 2015-09-01 14:19:11 -0400 | [diff] [blame] | 14 | |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 15 | # Install Docker |
Andy Bavier | b79acf7 | 2015-09-01 17:57:52 -0400 | [diff] [blame] | 16 | which docker > /dev/null || wget -qO- https://get.docker.com/ | sh |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 17 | sudo usermod -aG docker $(whoami) |
| 18 | |
Andy Bavier | e0828bc | 2015-09-28 10:28:17 -0400 | [diff] [blame] | 19 | sudo apt-get -y install httpie |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 20 | |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 21 | if [ "$CORD" -ne 0 ] |
| 22 | then |
Andy Bavier | f422f2c | 2015-09-01 18:02:28 -0400 | [diff] [blame] | 23 | cp ~/.ssh/id_rsa.pub xos/observers/vcpe/vcpe_public_key |
| 24 | cp ~/.ssh/id_rsa xos/observers/vcpe/vcpe_private_key |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 25 | fi |
| 26 | |
Andy Bavier | 1b8fd47 | 2015-08-06 10:33:14 -0400 | [diff] [blame] | 27 | sudo docker build -t xos . |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 28 | |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 29 | if [ "$CORD" -ne 0 ] |
| 30 | then |
| 31 | sudo docker build -t cord -f Dockerfile.cord . |
| 32 | IMAGE="cord" |
| 33 | fi |
| 34 | |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 35 | # OpenStack is using port 8000... |
| 36 | MYIP=$( hostname -i ) |
Andy Bavier | adc065d | 2015-09-01 17:43:03 -0400 | [diff] [blame] | 37 | sudo docker run -d --add-host="ctl:$MYIP" -p 9999:8000 $IMAGE |
Andy Bavier | 628710c | 2015-08-05 15:41:39 -0400 | [diff] [blame] | 38 | |
| 39 | echo "Waiting for XOS to come up" |
| 40 | until http $XOS &> /dev/null |
| 41 | do |
| 42 | sleep 1 |
| 43 | done |
| 44 | |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 45 | # Copy public key |
| 46 | # BUG: Shouldn't have to set the 'enacted' field... |
Andy Bavier | f422f2c | 2015-09-01 18:02:28 -0400 | [diff] [blame] | 47 | PUBKEY=$( cat ~/.ssh/id_rsa.pub ) |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 48 | http --auth $AUTH PATCH $XOS/xos/users/1/ public_key="$PUBKEY" enacted=$( date "+%Y-%m-%dT%T") |
| 49 | |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 50 | # Set up controller |
Andy Bavier | ddc2f55 | 2015-09-28 11:44:36 -0400 | [diff] [blame] | 51 | sudo cp /root/setup/admin-openrc.sh /tmp |
| 52 | sudo chmod a+r /tmp/admin-openrc.sh |
| 53 | #sudo sed -i 's/:5000/:35357/' /tmp/admin-openrc.sh |
| 54 | source /tmp/admin-openrc.sh |
Andy Bavier | e0828bc | 2015-09-28 10:28:17 -0400 | [diff] [blame] | 55 | http --auth $AUTH POST $XOS/xos/controllers/ name=CloudLab deployment=$XOS/xos/deployments/1/ backend_type=OpenStack version=Juno auth_url=$OS_AUTH_URL admin_user=$OS_USERNAME admin_tenant=$OS_TENANT_NAME admin_password=$OS_PASSWORD domain=Default |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 56 | |
| 57 | # Add controller to site |
| 58 | http --auth $AUTH PATCH $XOS/xos/sitedeployments/1/ controller=$XOS/xos/controllers/1/ |
| 59 | |
| 60 | # Add image |
| 61 | http --auth $AUTH POST $XOS/xos/images/ name=trusty-server-multi-nic disk_format=QCOW2 container_format=BARE |
| 62 | |
| 63 | # Activate image |
| 64 | http --auth $AUTH POST $XOS/xos/imagedeploymentses/ deployment=$XOS/xos/deployments/1/ image=$XOS/xos/images/1/ |
| 65 | |
| 66 | # Add node |
Andy Bavier | adff3dc | 2015-08-07 12:28:49 -0400 | [diff] [blame] | 67 | NODES=$( sudo bash -c "source /root/setup/admin-openrc.sh ; nova hypervisor-list" |grep cloudlab|awk '{print $4}' ) |
| 68 | for NODE in $NODES |
| 69 | do |
| 70 | http --auth $AUTH POST $XOS/xos/nodes/ name=$NODE site_deployment=$XOS/xos/sitedeployments/1/ |
| 71 | done |
Andy Bavier | d54e0f5 | 2015-08-04 17:25:17 -0400 | [diff] [blame] | 72 | |
| 73 | # Modify networktemplate/2 |
| 74 | # BUG: Shouldn't have to set the controller_kind field, it's invalid in the initial fixture |
Andy Bavier | 753f482 | 2015-08-06 10:34:12 -0400 | [diff] [blame] | 75 | FLATNET=$( sudo bash -c "source /root/setup/admin-openrc.sh ; neutron net-list" |grep flat|awk '{print $4}' ) |
Andy Bavier | 1b8fd47 | 2015-08-06 10:33:14 -0400 | [diff] [blame] | 76 | http --auth $AUTH PATCH $XOS/xos/networktemplates/2/ shared_network_name=$FLATNET controller_kind="" |
Andy Bavier | c5302fc | 2015-09-03 11:21:22 -0400 | [diff] [blame] | 77 | |
| 78 | if [ "$CORD" -ne 0 ] |
| 79 | then |
Andy Bavier | 9a1719c | 2015-09-15 15:18:53 -0400 | [diff] [blame] | 80 | DOCKER=$( sudo docker ps|grep $IMAGE|awk '{print $NF}' ) |
| 81 | sudo docker exec $DOCKER bash -c "cd /opt/xos/tosca; python run.py padmin@vicci.org samples/cord-cloudlab.yaml" |
Andy Bavier | c5302fc | 2015-09-03 11:21:22 -0400 | [diff] [blame] | 82 | fi |