ttm4200 Openstack Setup Guide
ttm4200 Openstack Setup Guide
This document provides information on the admin side of setting up an OpenStack project for use in labs.
Prepare VM Image
Create a VM image, e.g., in VirtualBox and export it. Note that currently, the VM flavors that are available
in the OpenStack cloud have max. 40GB of disk space. Make sure that the size of the virtual disk (not just
the image itself) is below that threshold. Additional aspects to consider:
• Make sure that dhclient runs on startup so that the VM is reachable via SSH. For the Ubuntu-based
image, I went with rc.local:
#!/bin/bash
dhclient
exit 0
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
• Make sure that required services are running (in my case this was docker via sudo systemctl enable
docker).
• Install x2goserver for remote graphical access https://wiki.x2go.org/doku.php/doc:installation:
x2goserver. In case of Ubuntu:
1
sudo add-apt-repository ppa:x2go/stable
sudo apt-get update
sudo apt-get install x2goserver x2goserver-xsession
Project Preparation
Before creating the actual VMs, we’ll need to set up a router and add firewall rules to allow us to ping /
SSH them. This initial setup can be performed via the OpenStack CLI or via the web interface. Guides for
both options are available at https://www.ntnu.no/wiki/display/skyhigh/Initial+setup.
Creating Instances
Navigate to https://skyhigh.iik.ntnu.no/horizon/project/instances/ to create the VMs via the “Launch In-
stace” dialog. Using this, you can directly create as many instances as you need, e.g., equal to the number of
lab groups you have. Under “Source”, you can select your VM image that will be used to create the instance.
Under “Flavor”, you can set the resources per instance.
#!/bin/bash
for i in {1..27}
do
openstack floating ip create ntnu-internal
done
Similarly, assigning floating IPs via the web GUI is cumbersome if doing it in bulk. Again, a simple bash
script can be used to do it via the CLI. In this example, my VM instances were called ttm4200-labvm-$I
and floating-ips.txt was created via
openstack floating ip list | awk -F"|" '{print $3}' > floating-ips.txt.
#!/bin/bash
I=0
while IFS= read -r line; do
let "I++"
echo "openstack server add floating ip ttm4200-labvm-$I $line"
done < floating-ips.txt
2
Setting Custom Credentials per VM
To avoid different groups accessing other VMs in the project by trying random IPs, we set per-instance
passwords using sshpass. Run this script from a PC that can access the OpenStack VMs. pw-ip.txt is a
space-separated list of group-ID, VM IP, desired password, and some other information. The script extracts
this info and updated the VM password (original password for the ttm4200 user was ttm4200). If you’d like
to avoid the password hash showing up in the bash history, you can add export HISTIGNORE='*sudo -S*'
or make that configuration part of your original VM image.
#!/bin/bash
while IFS= read -r line; do
IP=$(echo $line | awk -F’ ’ ’{print $2}’)
PW=$(echo $line | awk -F’ ’ ’{print $3}’)
PWHASHED=$(openssl passwd $PW)
MYCMD="sshpass -p ttm4200 ssh -o StrictHostKeyChecking=no -tt ttm4200@$IP \"echo ttm4200 | \
sudo -S usermod -p ’$PWHASHED’ ttm4200\""
echo $MYCMD
done < pw-ip.txt
Modifying VM Images
If you realize that you need to make some adjustments and don’t want to create a new image from scratch,
you can navigate to “Project > Compute > Instances” to make a snapshot of the currently running modified
VM. When creating new instances, you can now change the boot source in the “Source” tab to “Instance
Snapshot”.