How to configure the OpenStack Client (OSC)

OpenStack Client (also known as OSC) is a command line client for OpenStack that combines the command set for Compute, Identity, Image, Object Storage and Block Storage APIs into a single shell with a unified command structure.

This chapter describes how to install and configure the OCS.

Prerequisites

  • Basic knowledge of the Linux operating system (shell)
  • Access to running Linux VM (in our example Ubuntu) with open port (Egress 443) to OpenStack API
  • Application Credentials (cloud.yaml)

The steps to be taken are:

  • Installation python-openstackclient and python-keystoneclient packages
  • Configuration of Authentication (Application Credentials)

Note

We recommend python venv or/and pyenv. Python version 3.5.6 is currently the most suitable from our own experience.

Steps

1) install pyenv

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
exec "$SHELL"

2.) install python 3.5.x version into pyenv

sudo apt update
sudo apt install build-essential libbz2-dev libreadline-dev libssl-dev zlib1g-dev libsqlite3-dev wget curl libncurses5-dev libncursesw5-dev xz-utils libffi-dev liblzma-dev
pyenv install 3.5.6 # takes a couple of minutes
echo '3.5.6' > ~/.python-version
# you can use virtualenv from within pyenv as well...

3.) install all openstack clients

cd ~/  # this is important to guarantee the pyenv installed python 3.5.6 is used
pip install -U pip
pip install -U \
 gnocchiclient \
 "pankoclient<0.6.0" \
 "python-barbicanclient<4.8.0" \
 "python-cinderclient<4.0.1" \
 python-cloudkittyclient \
 "python-glanceclient<2.14.0" \
 "python-heatclient<1.17.0" \
 "python-keystoneclient<3.18.0" \
 "python-magnumclient<2.11.0" \
 "python-mistralclient<3.8.0" \
 "python-neutronclient<6.10.0" \
 "python-novaclient<11.1.0" \
 "python-octaviaclient<1.7.0" \
 "python-openstackclient<3.18.0" \
 "python-swiftclient<3.7.0"

Tip

In order to use the latest port forwarding features in the Python OpenStack Client, you also need to install the following package:

#Install customized python_openstack client with port forwarding support
pip install https://s3.ewstorage.ch/7a2bda4a58094225af3f0e3c06aee7fd:pub/python_openstackclient-3.19.3.dev3-py2.py3-none-any.whl

4.) extend bash_completion

openstack complete | sudo tee /etc/bash_completion.d/osc.bash_completion > /dev/null
. /etc/bash_completion

5.) Configure Application Credentials

mkdir -p ~/.config/openstack

# Paste your clouds.yaml file content or copy it to
vim ~/.config/openstack/clouds.yaml

# Define default connection
export OS_CLOUD=openstack

Note

OS_CLOUD=openstack refers to the configuration block in your clouds.yaml file, where you can have multiple blocks! If you do not export the OS_CLOUD variable, you can also specify the cloud configuration block in the command line. For example openstack –os-cloud=openstack image list

Example: clouds.yaml

6.) Test the configuration and connectivity

openstack image list
+--------------------------------------+----------------------------------------+--------+
| ID                                   | Name                                   | Status |
+--------------------------------------+----------------------------------------+--------+
| 09f60296-b845-4385-9adf-be9281866257 | CentOS 7.6                             | active |
| dfaa74e1-6e3a-4ec6-b2f7-5aadfc65761e | CirrOS 0.4.0                           | active |
| 62303abb-bcd3-4604-aedb-e282f1eef863 | Red Hat Enterprise Linux 7             | active |
| 6cbf2896-db07-4936-af5b-a0ed4b349f2b | Ubuntu 16.04                           | active |
| ddd20f25-ec89-44cf-aa01-8a8fd181c95f | Ubuntu 18.04                           | active |
| 406de35a-8473-4b43-9fc7-0d90fa153351 | Windows Server 2016                    | active |
| ffb46e0f-0445-4ffa-aec2-3d4f128e2f9d | Windows Server 2019                    | active |
| ac55797f-25a5-4eed-be4f-19dc4be21adf | snap-hle-u1804                         | active |
| 782c4208-36a8-4630-a792-839533c512bf | snap-hle-u1804                         | active |
| 2c087d07-1428-4ace-a67b-d7e10159a02b | snap-vm-win2019-nodisk                 | active |
| bc3a6538-e552-4d20-8f4a-5e43e503b30b | snap-vm1-win2019-m-flavor              | active |
| 4d601262-85b1-4a3f-9b0e-67ad88fb9e12 | snap-vm2-win2019-s-flavor-cneb         | active |
| fe00c862-3b91-4c5b-b449-eaa6f2fcbe66 | snap-vm3-win2016-s-flavor-cnx15k-600GB | active |
| c25babcf-5712-446f-a669-5e41638105a8 | snap-vm4-win2019-s-flavor-cn2k-200GB   | active |
| 1b5cc4b6-d730-4e40-88a5-d44eccf6eb37 | snap-vm5-win2019-m-flavor              | active |
| b711eb35-c6c1-42ae-a506-c3f66ca6e938 | snap2-vm4-win2019-s-flavor-cn2k-200GB  | active |
+--------------------------------------+----------------------------------------+--------+

Congratulations, your OpenStack client is working

More information about the available commands can be found on the following website: OpenStackClient User Manual