Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
18 views

ttm4200 Openstack Setup Guide

Uploaded by

uira.cocha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

ttm4200 Openstack Setup Guide

Uploaded by

uira.cocha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Setting up OpenStack for Labs

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:

$ sudo nano /etc/rc.local

#!/bin/bash
dhclient
exit 0

$ sudo chmod 755 /etc/rc.local


$ sudo nano /etc/systemd/system/rc-local.service

[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

$ sudo systemctl enable rc-local


$ sudo systemctl restart rc-local

• 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

Get an OpenStack Project


Contact the OpenStack responsible listed at https://www.ntnu.no/wiki/display/skyhigh (in my case this was
Lars Erik) to create an OpenStack project for your course. He will mainly need information on the number
of VMs you’re planning to have as well as the amount of CPU cores and RAM per instance. Additionally, he
helped me with converting the VirtualBox .ova image to the format needed in OpenStack after I provided
him a link to the original image hosted on https://filesender.uninett.no.

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.

Adding and Assigning Floating IPs


Via the web GUI, only one floating IP can be added at a time. Hence, it is more convenient to use the CLI
to add them in bulk. To this end, follow the guide at https://www.ntnu.no/wiki/display/skyhigh/Using+
the+commandline+clients for downloading the API script and sourcing it on login.ansatt.ntnu.no which
has the OpenStack CLI installed. There you can use the following script to add several floating IPs.

#!/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”.

You might also like