How to use the OpenStack CLI tools on Mac OS X

This tutorial describes how to use the OpenStack Command Line Interface (CLI) tools on Mac OS X. 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 Mac OS X

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

Step 1 - Installing Python 3

If you want to use the Dockerfile (explained in step 3), you can omit this step.

The OpenStack command line tools need Python and Python on OS X is utterly broken, but fortunately, you can install your own, up-to-date version.

Using brew

If you haven’t installed Homebrew on your system yet:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Using brew we’re going to install Python 3:

brew install python

Using a binary

Install a stable Python binary from Python.org downloads

Step 2 - Installing the OpenStack Command Line Tools

If you want to use the Dockerfile (explained in step 3), you can omit this step.

Now Python 3 is installed we can finally install the OpenStack command line tools:

sudo pip3 install python-openstackclient

Step 3 - Installing the configuration file

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

  1. Log in to the Fuga Cloud Dashboard
  2. Then go to the Access tab
  3. Here you can create OpenStack API Credentials (Remember to save the password in a safe place)
  4. Now you can choose to download one of three files (Dockerfile (recommended), OpenRC, Clouds.yaml). These files contain all necessary configurations for the clients.

Using the Dockerfile

In Release 2 we have also made a Dockerfile available so that if you have Docker installed, you don’t have to install Python and the CLI itself.

  1. Save this file to the folder where your project resides.

Using the OpenRC file

  1. Save this file to the folder on the machine where you have installed the OpenStack CLI clients, for example: ~/openrc.sh.
  2. Run the following command:

    source ~/openrc.sh
  3. Enter your OpenStack API Credentials password

Using the clouds.yaml file

In Release 2 we have made a clouds.yaml file available so that it’s easier to use the OpenStack CLI.

  1. Save this file to the folder where your project resides.

Step 4 - Using 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.

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:

openstack help | grep "<your command>"

For instance:

openstack help | grep list

This will return all list commands.

Using the Dockerfile

This method makes use of the Interactive mode described above.

Build the Docker container

$ docker build -t openstackcli --build-arg OS_PASSWORD=<$PASSWORD> - < <$PROJECT_DIR>/Dockerfile

Where <$PASSWORD> is the password of your OpenStack API Credentials and where <$PROJECT_DIR> is the directory where your project resides on your disk.

Run the interactive CLI

$ docker run -it --rm openstackcli

Where --rm openstackcli removes the container when you close it. This way your system doesn’t get cluttered with unused containers. You can check this with: docker ps --all.

List your instances

$ server list

List your volumes

$ volume list

List the images

$ image list

Using the OpenRC file

List your instances

$ openstack server list

List your volumes

$ openstack volume list

List the images

$ openstack image list

Using the clouds.yaml file

<$CLOUD_NAME> is the name of the cloud specified on line 2 in the clouds.yaml file. By default this is fuga.

List your instances

$ openstack --os-cloud <$CLOUD_NAME> server list

List your volumes

$ openstack --os-cloud <$CLOUD_NAME> volume list

List the images

$ openstack --os-cloud <$CLOUD_NAME> image list

Step 5 - Creating a new server with CLI

Start an interactive session with (for Docker you’re already in an interactive session):

$ openstack

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. Store this somewhere safe.

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 and running Ubuntu 18.04 LTS using the newly generated key.

 

$ server create cli_test --image b88f311a-b5f6-49d0-ad44-5304f9a8ef9b --flavor c2.small --key-name test_cli_key

After a few seconds, the server is created and built.

Step 6 - Exiting the environment

Using the OpenRC file

Deactivating the virtualenv

When you’re done with the virtualenv, run deactivate. You’ll see your prompt revert to normal.

Reactivating the virtualenv

Now, anytime you want to run your virtual environment, activate the “fugaio” virtualenv as shown above. This will put you into the appropriate virtualenv with all the necessary modules and dependencies. When you’re done, simply deactivate it.

Using the clouds.yaml file

Unless you’re in a virtualenv, you don’t have to do anything.

Using the Dockerfile

Press Ctrl-D or type exit in the active terminal to exit Interactive mode.

Conclusion

In this tutorial, you’ve learned how to use the OpenStack Command Line Interface tools on Mac OS X. 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.