Skip to content

How to use the OpenStack CLI tools on Linux

Estimated time to read: 4 minutes

This tutorial describes how to use the OpenStack Command Line Interface (CLI) tools on Linux. 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 one of the following Linux distributions:

    • Debian
    • Ubuntu
    • CentOS
    • Fedora

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

Step 1 - Installing the OpenStack Command Line Interface

The first step is to install the OpenStack CLI tools. Depending on the Linux distribution you use, use one of the commands below.

For Debian 9:

$ sudo apt update
$ sudo apt install -y python3-pip python3-dev
$ sudo pip3 install --upgrade pip
$ sudo pip3 install python-openstackclient

For Debian 8:

$ sudo apt update
$ sudo apt install -y python3-pip python3-dev
$ sudo pip3 install --upgrade pip
$ sudo pip3 install setuptools --upgrade
$ sudo pip3 install python-openstackclient

For Ubuntu 18.04:

$ sudo apt update
$ sudo apt install -y python3-pip python3-dev
$ sudo pip3 install --upgrade pip
$ sudo pip3 install python-openstackclient
For Ubuntu 16.04:
$ sudo apt update
$ sudo apt install -y python3-pip python3-dev
$ sudo pip3 install --upgrade pip
$ sudo pip3 install python-openstackclient
For Ubuntu 14.04:
$ sudo apt update
$ sudo apt install -y python-pip python-dev
$ sudo pip install --upgrade pip
$ sudo pip install python-openstackclient
pyOpenSSL and Cryptography don’t like python2, so all the given instruction can also be done with python3 and pip3, or just use the instructions from Ubuntu 18.04/16.04

For CentOS 7:

$ sudo yum update
$ sudo easy_install pip
$ sudo pip install --upgrade pip
$ sudo yum install python-devel gcc
$ sudo pip install python-openstackclient

For Fedora 23:7:

$ sudo dnf update
$ sudo pip3 install --upgrade pip
$ sudo pip3 install -U setuptools
$ sudo dnf install gcc python3-devel redhat-rpm-config
$ sudo pip3 install python-openstackclient

Step 2 - Installing the configuration file

Now, follow the steps below to install the configuration file:

  1. Log in to the Fuga Cloud Dashboard
  2. Go to AccountAccessCredentials
  3. You can choose a user credential or team credential.
  4. If you haven’t already, you should create one of these credentials. Hold on to the password.
  5. Click on download OpenRC. This file contains all necessary configurations for the client.
  6. Now copy the contents of this file and paste this in a new text file on the machine where you have installed the OpenStack CLI clients, for example: ~/.fuga-openrc.sh
  7. Run the following command to use the configuration file:

    source ~/.fuga-openrc.sh 
    
  8. Enter the password which matches the username of the contents of the OpenRC file.

Step 3 - Using the OpenStack CLI

You have now installed and configured the OpenStack CLI client and you can start using the OpenStack 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 Interface.

List your instances

$ openstack server list

List your volumes

$ openstack volume list

List the images

$ openstack image list

Interactive mode

This might not work on Ubuntu 18.04 depending on your configuration.

If you only enter the command openstack, you enter interactive mode. This mode lets you interact faster with the OpenStack 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:

$ openstack help | grep "your command"
For instance:
$ openstack help | grep list
This will return all list commands.

Step 4 - Creating a new server with CLI

Start an interactive session with:

$ openstack
If you get an error whilst using the interactive session, just prepend openstack to all commands without using the interactive session.

First, create a new key named, for example, test_cli_key or use an existing key.

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. Make sure to store this somewhere secure.

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 a c2.small instance, named CLI Test, on the IPv4 public network and running Ubuntu 18.04 using the newly generated key.2
server create cli_test --image Ubuntu 18.04 LTS --flavor c2.small --key-name test_cli_key --network public
After a few seconds, the server is created and built.

Conclusion

In this tutorial, you’ve learned how to use the OpenStack Command Line Interface tools on a Linux distribution, like Debian or Ubuntu. By using these tools you learned how to list your instances and volumes. Besides this, you also learned how to launch a new instance by using the CLI.

More tutorials about using the Command Line Interface can be found here.