Mirantis OpenStack Express — Automating VM Launch and Configuration
This is the ninth in a series of short tutorials showing how to perform common cloud operations tasks in Mirantis OpenStack Express 2.0 — Mirantis’ “Private Cloud as a Service”
In our last tutorial, we learned how to log into our Mirantis OpenStack Express cloud's Controller Node, so we can issue commands via the OpenStack CLI. Now, we’re going to do something practical with our new-found CLI capabilities: define and launch a VM with a specific image, VM flavor, network connection and SSH key, and pass in a script for execution post-boot that installs Apache for us, along with a custom index file for testing. Thanks to Mirantis Product Architect, Christopher Aedo, for inspiration and code-snippets.
Basic Ops Tutorials
Mirantis OpenStack Express — Mirantis' "Private Cloud as a Service" — is the fastest way to get your hands on a fully-functional, optimally-configured, private OpenStack cloud, running on hosted bare metal and able to scale on demand. This series of short tutorials shows how to perform common cloud operations tasks in MOX, and offers links to documentation and learning resources. Though aimed at Mirantis OpenStack Express, many of the techniques discussed here will also work on a private OpenStack cloud deployed using Mirantis OpenStack.
Tutorials:
- Adding New Custom Boot Images
- Launching a VM from a Boot Image
- Creating a Block Storage Volume
- Attaching and Using Volumes
- Creating new VM Flavors
- Setting Up a project
- Murano in a Minute
- Mirantis OpenStack Express VPN-as-a-Service
- Running OpenStack from the Command Line
- Automating VM Launch and Apache Installation
Step by Step
To start, log into your cloud's Controller node (following the instructions in our prior post and issue the command source openrc
to authenticate.
Now we can begin to gather the information and prepare the resources we need to use the nova boot
command to launch and install Apache on our VM.
First, we’ll get the image ID for an appropriate image, using the command glance image-list
. We’ll grab the ID for the Ubuntu 14.04 x64 LTS dev image that's available by default in Mirantis OpenStack Express.
glance image-list
lists the images we have available. We'll use the Ubuntu 14.04 LTS dev image, so we'll need its ID.Then we’ll set up the following script in the root of our Controller node, using vi, calling the script install-apache.sh:
#!/bin/bash
/usr/bin/apt-get -qy update
/usr/bin/apt-get -qy install apache2
echo "<h1>Hello world!</h1>" > /var/www/html/index2.html
As you can see, this is the script we want to execute post-boot, to run update on our VM, install Apache2, and create an index.html file. The reason we call that file index2 is that we don’t want to conflict with the default index.html Apache installs.
Now we can check out the VM flavors available to us by entering nova flavor-list
. We’ll pick the medium flavor for our instance, which is index 3.
We can also remind ourselves of the keypairs we have available by executing nova keypair-list
. We'll need the name of a key to launch our instance.
We'll find IDs for the networks we have available by executing nova network-list
. We’ll attach this VM to the toplevel internal network, net04. Later, we’ll go to Horizon to give it a floating IP to make it accessible from the internet.
nova network-list
to find IDs for available networks, and attach our instance to the net04 internal network.Finally, we'll take all the information we've assembled and include it as arguments to the nova boot
command, which will launch our instance and install Apache. Note the way arguments are referenced: argument flags and data types are consistent throughout the OpenStack CLI.
nova boot
will be used to launch our instance. Note the way arguments are referenced: argument flags and data types are consistent throughout the OpenStack CLI.Nova compute gives us back a table of VM parameters and status info.
Now let’s go to Horizon for this cloud, and look at the instance list. There’s our new VM. Let’s give it a floating IP by popping down the More menu and associating one of the floating IPs we have available (I only have two assigned to this demo cloud).
And now, let’s browse to that IP address and filename, and see if Apache is working. It is!
This is just the beginning. In future tutorials, we’ll be digging much deeper into OpenStack command-line functions. Stay tuned!
Resources:
- Mirantis OpenStack Express 2.0 Documentation
- Mirantis OpenStack Express Operations Guide
- OpenStack Command-Line Reference
Check out Express for yourself at https://express.mirantis.com.