How to connect to OpenStack using CLI [New]

How to connect to OpenStack using CLI [New]

The OpenStack Command Line Interface (CLI) enables you to manage your Leaseweb Public Cloud resources directly from the terminal. Using the CLI, you can create and manage instances, networks, volumes, security groups, floating IPs, and other OpenStack resources without relying on the Customer Portal.

This guide walks you through installing the OpenStack CLI using either Python’s pip package manager or your operating system’s native package manager. It also explains how to configure authentication using a clouds.yaml file, connect to your Leaseweb Public Cloud project, and verify that your CLI is ready to use.

Install Openstack CLI

Via pip

Prerequisites:

  • Your system must have Python 3 interpreter installed
  • Your Python interpreter must have venv module installed

1. Create a python virtual environment in some folder:

python3 -m venv openstack-venv

2. Load the virtual environment:

. openstack-venv/bin/activate

3. Install python-openstackclient package:

pip install python-openstackclient

On Windows

Windows does not have the Python interpreter installed by default. Therefore, you should install it first, either inside WSL, or by downloading the installer from the official website: https://www.python.org/downloads/windows/

When installing, we advice you set the “Add python.exec to PATH” enabled, so you don’t have to type full path to python binary.

Once the python is installed, you may use the following commands to install python-openstackclient:

# Create virtual environment
python.exe -m venv openstack-venv

# Load it (you may need to run "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned" in Powershell as Administrator
.\openstack-venv\Scripts\Activate.ps1

# Install python-openstackclient package
pip.exe install python-openstackclient

# Run openstack client
openstack

Via package manager

As the alternative for installing into a virtual environment directly from PyPi repository, you may use the openstack client packages most operating systems provide

Debian / Ubuntu

Install the python3-openstackclient package:

apt install python3-openstackclient

AlmaLinux / RockyLinux / Other RHEL-based

Install the python3-openstackclient package:

dnf install python3-openstackclient

Arch Linux

Install the python3-openstackclient package:

pacman -S python3-openstackclient

MacOS (Homebrew)

Install the openstackclient package:

brew install openstackclient

Connect to Leaseweb Public Cloud

Once the Openstack client is installed, you have to provide it with the clouds.yaml file with your credentials.

Obtain the credentials from Leaseweb Customer portal

  1. Log in to the Leaseweb customer portal at https://secure.leaseweb.com
  2. Navigate to the Public Cloud -> Settings page.
  3. Switch to the Users tab and create a new user if necessary.
  4. At the Projects tab, click Edit button next the project you want this user be member of.
  5. Switch to the Users tab, and add your user to the project.

Once the user is created, take a note of the following items:

  • Project name
  • User name you have created
  • The password for the user you have created
  • Your customer ID: you can find it by clicking on the icon of your customer portal user in the top right corner of the page. This number is displayed under your company name.
  • Availability zone name: it is displayed on the top right corner of most of the Public Cloud customer portal pages.

Create clouds.yaml file

Once you have all the credentials at hand, create the file ~/.config/openstack/clouds.yaml with the following content:

clouds:
  openstack:
    auth:
      auth_url: https://identity.leasewebcloud.com/v3
      username: "<the user you have created at previous step>"
      project_name: "<the name of the project>"
      project_domain_name: "<the customer ID you have obtained at previous step>"
      user_domain_name: "<the customer ID you have obtained at previous step>"
    region_name: "<the availability zone name, e.g. eu-west-3-az1>"
    interface: "public"
    identity_api_version: 3

Verify that the connection works:

openstack project list
# .. it should not return any error

Using clouds.yaml with multiple availability zones / regions

The clouds.yaml file allows storing multiple credentials in it so you don’t have to maintain multiple files with multiple regions, projects, and availability zones credentials. Simply define multiple credentials under the clouds: section:

clouds:
  az1-project1:
    auth:
      auth_url: https://identity.leasewebcloud.com/v3
      username: "<the user name>"
      project_name: "project1"
      project_domain_name: "1234567"
      user_domain_name: "1234567"
    region_name: "eu-west-3-az1"
    interface: "public"
    identity_api_version: 3
  az2-project2:
    auth:
      auth_url: https://identity.leasewebcloud.com/v3
      username: "<the user name>"
      project_name: "project2"
      project_domain_name: "1234567"
      user_domain_name: "1234567"
    region_name: "eu-west-3-az2"
    interface: "public"
    identity_api_version: 3

Set the value of the OS_CLOUD environment variable to the credentials you want to use, or use the command line argument –os-cloud=<credentials name> to use it:

# Set the environment variable OS_CLOUD to use credentials az1-project1
export OS_CLOUD="az1-project1"

# List instances
openstack server list

# Or set it via command line arguments
openstack --os-cloud=az2-project2 server list