Guide: OpenStack CLI – Basic Usage

From bwCloud-OS
Revision as of 23:19, 25 April 2026 by Sia (talk | contribs)
Jump to navigation Jump to search

This guide provides a quick introduction to managing your bwCloud-OS resources using the OpenStack CLI. It covers basic authentication and the most common operations for compute, storage, and networking.


Prerequisites

Install the OpenStack SDK, e.g. for Ubuntu:

sudo apt install python3-openstackclient 

Alternatively, you can installit via pip (preferably inside a virtual environment):

python3 -mvenv openstackclient_venv
. openstackclient_venv
pip install python-openstackclient

Authentication

You can either:

  • source an OpenRC file, or
  • use a clouds.yaml file

For details, see the section Create an application credential.


Compute

Images

List available images:

openstack image list

Upload a new image:

openstack image create ubuntu-24.04 \
  --file=/path/to/images/ubuntu-24.04-server-cloudimg-amd64.img \
  --disk-format=qcow2 \
  --container-format=bare 

Show image details:

openstack image show <IMAGE_ID>

Delete an image:

openstack image delete <IMAGE_ID_OR_NAME>

Key Pairs (SSH Access)

Create a key pair:

openstack keypair create myKey > myKey.pem
chmod 600 myKey.pem

List key pairs:

openstack keypair list

Delete a key pair:

openstack keypair delete myKey

Instances

List instances:

openstack server list

Create an instance:

openstack server create \
  --image ubuntu-24.04 \
  --flavor p1.tiny \
  --network myNet \
  --key-name myKey \
  myVM

Show details of an instance:

openstack server show myVM

Delete an instance:

openstack server delete myVM

Storage

Volumes

List volumes:

openstack volume list

Create a volume:

openstack volume create --size 10 myVolume

Delete a volume:

openstack volume delete myVolume

Volume Management for Instances

Attach a volume to an instance:

openstack server add volume myVM myVolume

Detach a volume from an instance:

openstack server remove volume myVM myVolume


Networking

Networks

List networks:

openstack network list

Create a network:

openstack network create myNet

Delete a network (after detaching all ports from its subnets):

openstack network delete myNet

Subnets, Routers

Create a subnet:

openstack subnet create mySubnet \
  --network myNet \
  --subnet-range 192.168.1.0/24

Create a router:

openstack router create myRouter

Attach a subnet to a router:

openstack router add subnet myRouter mySubnet

Set external gateway of a router:

openstack router set myRouter --external-gateway provider_default_net

Detach a subnet from a router:

openstack router remove subnet myRouter mySubnet

Delete a router:

openstack router delete myRouter

Delete a subnet (after detaching all ports from the subnet):

openstack subnet delete mySubnet

Floating IPs

Create a floating IP (requires access to the provider network):

openstack floating ip create provider_default_net

List floating IPs:

openstack floating ip list

Associate a floating IP with an instance:

openstack server add floating ip myVM <FLOATING_IP>

Disassociate a floating IP from an instance:

openstack server remove floating ip myVM <FLOATING_IP>

Release a floating IP:

openstack floating ip delete <FLOATING_IP>

Security Groups

List security groups:

openstack security group list

Create a security group:

openstack security group create mySecGroup

Add a rule to a security group (e.g., HTTP access via port 80):

openstack security group rule create \
  --proto tcp \
  --dst-port 80 \
  --ingress \
  mySecGroup

Assign security group to instance:

openstack server add security group myVM mySecGroup

Remove security group from instance:

openstack server remove security group myVM mySecGroup

Delete a security group:

openstack security group delete mySecGroup