How to use the OpenStack CLI tools on Windows
Tutorials Intermediate

How to use the OpenStack CLI tools on Windows

This tutorial describes how to use the OpenStack Command Line Interface (CLI) tools on Windows. For example, you will learn how to list your instances and volumes by using the CLI. You will also learn how you can launch a new instance by using the CLI.

Prerequisites

For this tutorial you’ll need the following:

  1. A Fuga Cloud account
  2. A device running Windows

In case you’re running Mac OS X or Linux, please check out the following guides:

Step 1 - Installing Python

Use the latest stable Python web-based installer with these extra settings:

  • Add to PATH
  • Add to environment variables

In our experience the process is easier when using Firefox or Chrome instead of Edge

Use the following commands to test if Python is working and correctly added to the PATH variable:

python --version
pip --version

Step 2 - Installing C++ Compiler

Download and install the latest Build Tools for Visual Studio from here.

Step 3 - Setting environment variables

To communicate with your OpenStack API, you’ll need to configure some variables. The default OpenStack RC file is only built for UNIX-based systems, so it will not work on Windows.

This means that we have to set our environment variables manually, also we have to add the C++ compiler to the PATH variable. This can be accomplished by searching for “system” or “edit the system environment variables”, or going into your Control Panel, scrolling to the System and Security section, and clicking on System.

From that window, you will see an Advanced tab, wherein you can set your environment variables.

Or in short: System → Advanced → Environment Variables → System Variables → PATH → Edit, then add the “VC\bin” folder of the visual studio install-path to the system variable PATH.

For example, add:

C:\Program Files(x86)\Microsoft Visual Studio 14.0.\VC\bin;

To the front of the line.

Now test if this works, go to PowerShell or the Command Prompt (restart PowerShell or the Command Prompt) and enter:

cl

If the version returns you did it correctly. Now add some variables for the OpenStack CLI.

Go to System → Advanced → Environment Variables

Add to variables (tried for v3 of OpenStack):

OS_AUTH_URL: https://identity.api.fuga.io:5000/v3
OS_PASSWORD: *password*
OS_REGION: cystack
OS_USERNAME: *username*
OS_IDENTITY_API_VERSION: 3

If you’re unsure what to fill out, you can download the OpenStack RC file from the Horizon dashboard (through Access and Security → API access). Open the RC file in Notepad and you will find these variables (except password) and their values. More advanced users can also add the environment variables directly in PowerShell. To do this, first look at your variables overview.

get-item env:*

To add a new one:

set-item env:OS_PASSWORD -value "password"

If you want to delete an environment variable:

remove-item env:OS_PASSWORD

Install OpenStackCLI

Now in powershell or commandprompt:

pip install -U buildtools
pip install python-openstackclient

Check if everything works:

openstack server list

If your servers are returned everything is set up.

Use the Fuga CLI

You have now installed and configured the OpenStack CLI client and you can start using the Fuga CLI.
The following are some examples you can try. You can also call openstack help for all available commands. For more in-depth information check out OpenStack command-line clients.

List your instances

$ openstack server list

List your volumes

$ openstack volume list

List the images

$ openstack image list

Interactive mode

If you only enter the command openstack, you enter interactive mode. This mode lets you interact faster with the Fuga CLI.

$ openstack

While in interactive mode enter: help to get all the different commands.

Pro tip

If you only need to find a specific command enter on PowerShell:

$ openstack help | Select-String -Pattern "<your command>"

Or on Windows CMD:

$ openstack help | FINDSTR /L "<your command>"

For instance on PowerShell:

$ openstack help | Select-String -Pattern list

And on Windows CMD:

$ openstack help | FINDSTR /L list

This will return all list commands.

Create a new server with the CLI

Start an interactive session with:

openstack

First create a new key, for example, named test_cli_key or use an existing key. This must be done using the API user. This is because your API user and your Fuga user are two different users.

Creating a key with the CLI can be done with the following command:

keypair create test_cli_key

This command returns the newly generated private key. Store this somewhere save.

Now test if the key is created:

keypair list

Next up is to list the images and flavors we can choose from.

image list
flavor list

In this example I chose to create an instance, named CLITest with debian 9 of a small server using the newly generated key.

server create cli_test --image 5a2a94e7-3364-4bf8-a66b-ac84bc2c92de --flavor c1.small --key-name test_cli_key

After a few seconds the server is created and built.

Was this article helpful?