Category: Uncategorized

Home / Category: Uncategorized

OpenStack client on Windows

April 9, 2019 | Uncategorized | No Comments

I was working on Windows with some powershell tooling and found the need to install the python OpenStack client(s) on my Windows vm. I found the documentation on docs.openstack.org a bit rough so i decided to share the necessary steps with you all.

The OpenStack client is written in python 2.7. Since this is not available by default in Windows we are going to install it. Download the latest python 2.7.x release from https://www.python.org/downloads/
Currently this is 2.7.16 wich is available for 32 bit and 64 bit.

Add the path to the python exe and the python scripts directory to your Windows Path. This is done by adding this text to the end of your path:

 ;c:\Python27\;c:\Python27\Scripts\
This is where you find the Path environment setting in Windows

Microsoft Visual C++ Compiler for Python 2.7 is needed in order to install the openstack client. Download and install it fromhttp://aka.ms/vcpython27

Start a new PowerShell session so the new paths are available in your environment. Then test if you can run python

 python --version

Pip should be already installed. If it is not, install the pip package

easy_install pip

And install the openstack client with pip

 pip install python-openstackclient

Optionally you can also install the deprecated openstack clients. These might have functions that are not yet in the common python-openstackclient.

pip install "python-cinderclient==3.5" python-glanceclient python-heatclient python-keystoneclient python-neutronclient python-novaclient python-swiftclient

Well, that was not so hard was it?
You are now ready to import your credentials through the rc file you find in Horizon. RC files are in bash format by default. I have made a small powershell script for you that will convert it, or let you enter your credentials manually.

It is available on github: https://github.com/ceesios/source-openrc/blob/master/Source-OpenRC.ps1

In the past i had a simple website with some contact info. Maintaining the website and webserver became too much hassle and the site got hacked a couple of times. Restoring it involved setting up a clean server, dropping Joomla on it and restoring the backups. All done by hand, so the last time i restored it has been some years ago. Surely these days this can be done smarter right?

Choosing the automation tool

Ansible is perfect for maintaining a relatively small number of servers. It is easy to setup and modify and has gained a lot of usable modules in the past three years. I use it a lot, so getting started will be easy. For a simple lamp server like this it still seems like too much work. Keep in mind that my preferred way to perform maintenance to it will involve just throwing it away and creating a new server.
You can also deploy to most clouds like OpenStack with Ansible, however this does not feel natural in Ansible. I will go into Ansible another time, it is really a great tool. For now, its just not the right tool for the job.

Salt is a perfect tool for managing a large set of servers like the cloud itself at CloudVPS. Salt works with salt minions (agents) which give the benefit of decentralized running tasks. That makes execution on a large set of servers much faster. Salt is not quick and easy to get started with and would surely not be done in one weekend for me.

There is one more automation tool. It’s really easy to learn, and fast to get started with, BASH!
It wont scale very well, wont automate your patches etc. But is is fast and easy to setup. And most important for this article, we can just put in in a userdata script.

What are userdata scripts?

Every cloud provider like AWS, RackSpace, Digital Ocean or other OpenStack based clouds like the one where i work allow you to customize your server with a script. Different providers use different names like userdata, customization scripts or droplet metadata. They all mean the same, a script that will be executed by a service called cloud-init on the first boot.

These scripts can contain anything from bash to Powershell, depending on your needs and OS. Typically you will use it to do some basic config like

  • installing python that will be required for Ansible
  • install your Salt minions so the Salt master kan then take over
  • update your apt cache so you wont have to wait for it later on

Start your userdata script with #!/bin/bash -v on a Linux instance. The -v makes sure that all output goes to the console log as well. A simple script for Ubuntu can look like the one below. It will update the apt cache, perform a dist-upgrade (keeping any default or existing config) and install python.

#!/bin/bash -v
apt update
DEBIAN_FRONTEND=noninteractive apt -y \
-o Dpkg::Options::="--force-confdef" \
-o Dpkg::Options::="--force-confold" \
dist-upgrade
apt install -y python

When using Windows start with #PS1
If you want to include a external script, powershell, bash or other use #Include http://your-script-url

​You could also write a bash script that will install a full lamp stack, configure it, deploy WordPress and setup letsencrypt. The script only runs once, so you won’t be able to manage the configuration later on as you would with automation tools like Ansible. For this usecase it will be fine since i will just setup a new instance instead. Also i will use it to setup a demo server when deploying it with other tools.

All that’s left is to either deploy it with Terraform (super cool tool, more on that later), with the OpenStack Horizon interface or with the CLI:

openstack server create --image "$image" \
--flavor $flavor \
--security-group "$securitygroup" \
--key-name "$keyname"\
--nic net-id=net-public\
--user-data ./userdata/Ubuntu/lamp_wordpress.sh cmto_lamp

If you would like to see more userdata scripts that might come in handy, take a look at my GitHub repo. You will also find the lamp_wordpress.sh there.

Last but not least, if you want to try for free how easy userdata scripts work, try out the free tier at AWS or request a free test account at one of the OpenStack providers like CloudVPS.