Getting started with the OpenStack command line client

OpenStack is open-source software that allows you to create private and public clouds. A command line tool is available which makes it easy to work with. This article explains how to install this client on your cloud server.

https://docs.openstack.org/python-ironicclient/pike/cli/osc_plugin_cli.html

Installation

The OpenStack command line client can be installed in several ways. This article shows how to install it using pip in a virtualenv as well as installing globally.

Install python-dev

Install python-dev so you can build Python extensions. This is necessary to install the openstackclient using pip.

If you're using Python 2:

[user@localhost]$ sudo apt-get install python2.7-dev

If you're using Python 3:

[user@localhost]$ sudo apt-get install python3-dev

Install pip

First, run the following to see if 'pip' is installed:

If you're running Python 2

[user@localhost]$ pip -V

If you're running Python 3

[user@localhost]$ pip3 -V

If it's not, install with the following:

If you're running Python 2

[user@localhost]$ sudo apt-get install python-pip

If you're running Python 3

[user@localhost]$ sudo apt-get install python3-pip

Install virtualenv

One way to install the OpenStack CLI is in a virtual environment. Now that pip is installed, run the following to install virtualenv:

[user@localhost]$ sudo apt-get install python-virtualenv

Install OpenStack CLI

Installing within a virtualenv

This is a safe method as your installation is housed within a virtual environment and does not touch anything else in your system. To do this, create a virtual environment, activate it, and install the OpenStack CLI within it.

If you're using Python 2, run the command pip. If you're using Python 3, run the command pip3.

[user@localhost]$ virtualenv ~/venv
[user@localhost]$ source ~/venv/bin/activate
(venv)user@localhost$ pip install python-openstackclient

This installs the client in a virtual environment separated from the rest of your system. In order to be able to use the client you will have to activate the virtual environment using the source command above.

Installing globally

You can also install on your system globally using pip

[user@localhost]$ sudo pip install python-openstackclient

Configuration

The easiest way to configure the client is to use the OpenRC file. View the following article for instructions on how to download this file:

In order to use the OpenRC file, run:

[user@localhost]$ source openrc.sh

Basic commands

The OpenStack command line client combines the functionality of all of the other OpenStack service specific command line clients, such as the nova client and the cinder client. Here are some basic commands that are useful:

[user@localhost]$ openstack server list
+--------------------------------------+-------------+--------+--------------------------------------------------------------+--------------+
| ID                                   | Name        | Status | Networks                                                     | Image Name   |
+--------------------------------------+-------------+--------+--------------------------------------------------------------+--------------+
| 4c40d015-33b3-4bc3-ba50-d794356eef4f | mariadb     | ACTIVE | public=2607:f298:5:101d:f816:3eff:feeb:ca8c, 208.113.133.156 | Ubuntu-16.04 |
| bf500ff3-7b37-4d01-a77e-5efc086de5f0 | nextcloud-1 | ACTIVE | public=2607:f298:5:101d:f816:3eff:fef1:9c6a, 208.113.131.81  | Ubuntu-16.04 |
| af01d391-7604-482e-84b9-3ccee872d69f | nextcloud   | ACTIVE | public=2607:f298:5:101d:f816:3eff:fea9:a69f, 208.113.129.184 | Ubuntu-16.04 |
| 72c4271b-d447-444c-b5f6-0af401ca14d2 | wordpress   | ACTIVE | public=2607:f298:5:101d:f816:3eff:fe08:54c5, 208.113.133.184 | Ubuntu-16.04 |
+--------------------------------------+-------------+--------+--------------------------------------------------------------+--------------+

This lists the servers you have in your tennant with some basic information about them.

[user@localhost]$ openstack image list
+--------------------------------------+--------------+--------+
| ID                                   | Name         | Status |
+--------------------------------------+--------------+--------+
| afa49adf-2831-4a00-9c57-afe1624d5557 | CentOS-6     | active |
| 842c207f-6964-4ed7-a41a-06ec66a7c954 | Ubuntu-14.04 | active |
| 30a2a55a-2045-4ed8-a605-2d1c1143edd3 | Ubuntu-16.04 | active |
| 713f2fbc-05c5-491b-9e02-e000861e7b30 | Fedora-24    | active |
| 5cb9c233-5867-4e47-80a1-9d774f800444 | Debian-7     | active |
| f84868a5-5261-404a-9c54-ec317ea16b94 | CentOS-7     | active |
| b105ad3b-7df8-4318-9c3d-4e4fa4cc4563 | Debian-8     | active |
| b67b74bc-c3a8-4087-9c28-de02161fdedd | CoreOS       | active |
+--------------------------------------+--------------+--------+

This lists the images available to your tennant.

[user@localhost]$ openstack volume list
+--------------------------------------+-----------------------------+-----------+------+---------------------------------+
| ID                                   | Display Name                | Status    | Size | Attached to                     |
+--------------------------------------+-----------------------------+-----------+------+---------------------------------+
| 21cb1ef8-8541-4919-a8e0-2af66e547b03 | db_volume                   | available |   10 |                                 |
| 2b3ce54e-7445-4d9e-a153-d03b120f1d1a | Meretricious Nibblet Volume | available |   10 |                                 |
+--------------------------------------+-----------------------------+-----------+------+---------------------------------+

This lists the volumes you have created.

[user@localhost]$ openstack server create --key-name my_key --image Ubuntu-16.04 --flavor 100 awesome_server
+--------------------------------------+-----------------------------------------------------+
| Field                                | Value                                               |
+--------------------------------------+-----------------------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                                              |
| OS-EXT-AZ:availability_zone          | iad-2                                               |
| OS-EXT-STS:power_state               | NOSTATE                                             |
| OS-EXT-STS:task_state                | scheduling                                          |
| OS-EXT-STS:vm_state                  | building                                            |
| OS-SRV-USG:launched_at               | None                                                |
| OS-SRV-USG:terminated_at             | None                                                |
| accessIPv4                           |                                                     |
| accessIPv6                           |                                                     |
| addresses                            |                                                     |
| adminPass                            | DCa8su7uHQUR                                        |
| config_drive                         |                                                     |
| created                              | 2016-12-02T19:46:41Z                                |
| flavor                               | gp1.subsonic (100)                                  |
| hostId                               |                                                     |
| id                                   | 24c4538d-6607-4546-95b4-49ee9aa4a26a                |
| image                                | Ubuntu-16.04 (30a2a55a-2045-4ed8-a605-2d1c1143edd3) |
| key_name                             | my_key                                              |
| name                                 | awesome_server                                      |
| os-extended-volumes:volumes_attached | []                                                  |
| progress                             | 0                                                   |
| project_id                           |                                                     |
| properties                           |                                                     |
| security_groups                      | [{u'name': u'default'}]                             |
| status                               | BUILD                                               |
| updated                              | 2016-12-02T19:46:42Z                                |
| user_id                              |                                                     |
+--------------------------------------+-----------------------------------------------------+

This creates an Ubuntu 16.04 server with the gp1.subsonic flavor (ID 100), and uses the key called my_key.

 

Did this article answer your questions?

Article last updated .