Guide: OpenStack CLI – Basic Usage: Difference between revisions

From bwCloud-OS
Jump to navigation Jump to search
No edit summary
No edit summary
 
(44 intermediate revisions by the same user not shown)
Line 1: Line 1:


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


__TOC__
__TOC__


== Prerequisites ==
Install the OpenStack client, e.g. for Ubuntu:
<pre>
sudo apt install python3-openstackclient
</pre>
Alternatively, you can install it via <code>pip</code> (preferably inside a virtual environment):
<pre>
python3 -m venv openstackclient_venv
source openstackclient_venv/bin/activate
pip install python-openstackclient
</pre>
== Authentication ==
You can either:
* source an OpenRC file, or
* use a <code>clouds.yaml</code> file
For details, see the section [[Programmatic Access and Automation#How can I create an application credential?|Create an application credential]].


<!--
== General Information about Cloud, Project, and User ==
== General Information about Cloud, Project, and User ==


Line 14: Line 38:
openstack token issue
openstack token issue
openstack region list
openstack region list
</pre>
-->
== Images ==
List available images:
<pre>
openstack image list
</pre>
Upload a new image:
<pre>
openstack image create ubuntu-24.04 \
  --file=/path/to/images/ubuntu-24.04-server-cloudimg-amd64.img \
  --disk-format=qcow2 \
  --container-format=bare
</pre>
</pre>


Show image details:


== Compute (Instances, Images) ==
<pre>
openstack image show &lt;IMAGE_ID&gt;
</pre>


Create an instance:
Delete an image:


<pre>
<pre>
openstack server create \
openstack image delete &lt;IMAGE_ID&gt;
  --image ubuntu-24.04 \
</pre>
  --flavor m1.small \
 
  --network myNet \
 
  --key-name myKey \
== Compute ==
  myVM
 
=== Key Pairs (SSH Access) ===
 
Create a key pair:
 
<pre>
openstack keypair create myKey > myKey.pem
chmod 600 myKey.pem
</pre>
 
List key pairs:
 
<pre>
openstack keypair list
</pre>
 
Delete a key pair:
 
<pre>
openstack keypair delete myKey
</pre>
</pre>
=== Instances ===


List instances:
List instances:
Line 34: Line 100:
<pre>
<pre>
openstack server list
openstack server list
</pre>
Create an instance (ensure that the specified image, flavor, network, and key pair exist):
<pre>
openstack server create \
  --image ubuntu-24.04 \
  --flavor p1.tiny \
  --network myNet \
  --key-name myKey \
  myVM
</pre>
</pre>


Line 48: Line 125:
</pre>
</pre>


List available images:
== Storage==


<pre>
=== Volumes ===
openstack image list
</pre>


Show image details:
List volumes:


<pre>
<pre>
openstack image show &lt;IMAGE_ID&gt;
openstack volume list
</pre>
</pre>


 
Create a volume (size in GB):
== Storage (Volumes) ==
 
Create a volume:


<pre>
<pre>
Line 69: Line 141:
</pre>
</pre>


List volumes:
Delete a volume:


<pre>
<pre>
openstack volume list
openstack volume delete myVolume
</pre>
</pre>
=== Volume Management for Instances ===


Attach a volume to an instance:
Attach a volume to an instance:
Line 81: Line 155:
</pre>
</pre>


Detach a volume:
Detach a volume from an instance:


<pre>
<pre>
Line 87: Line 161:
</pre>
</pre>


Delete a volume:
 
 
== Networking ==
 
=== Networks ===
 
List networks:


<pre>
<pre>
openstack volume delete myVolume
openstack network list
</pre>
</pre>


Create a network:


== Networking ==
<pre>
openstack network create myNet
</pre>


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


<pre>
<pre>
openstack network create myNet
openstack network delete myNet
</pre>
</pre>


=== Subnets, Routers ===
Create a subnet:
Create a subnet:


Line 116: Line 200:
</pre>
</pre>


Attach subnet to router:
Attach a subnet to a router:


<pre>
<pre>
Line 122: Line 206:
</pre>
</pre>


Set external gateway:
Set external gateway of a router:


<pre>
<pre>
openstack router set myRouter --external-gateway provider_net
openstack router set myRouter --external-gateway provider_default_net
</pre>
</pre>


List networks:
Detach a subnet from a router:


<pre>
<pre>
openstack network list
openstack router remove subnet myRouter mySubnet
</pre>
</pre>


Delete a router:


=== Floating IPs (Public Access) ===
<pre>
openstack router delete myRouter
</pre>


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


<pre>
<pre>
openstack floating ip create provider_net
openstack subnet delete mySubnet
 
</pre>
</pre>
=== Floating IPs ===
Create a floating IP (requires access to the provider network):
<pre>openstack floating ip create provider_default_net</pre>


List floating IPs:
List floating IPs:
Line 149: Line 243:
</pre>
</pre>


Associate floating IP with instance:
Associate a floating IP with an instance:


<pre>
<pre>
Line 155: Line 249:
</pre>
</pre>


Remove floating IP:
Disassociate a floating IP from an instance:


<pre>
<pre>
Line 161: Line 255:
</pre>
</pre>


Release (delete) a floating IP:
<pre>
openstack floating ip delete &lt;FLOATING_IP&gt;
</pre>


=== Security (Security Groups & Rules) ===
=== Security Groups ===


List security groups:
List security groups:
Line 176: Line 274:
</pre>
</pre>


Add SSH access (port 22):
Add a rule to a security group (e.g., HTTP access via port 80):
 
<pre>
openstack security group rule create \
  --proto tcp \
  --dst-port 22 \
  mySecGroup
</pre>
 
Add HTTP access (port 80):


<pre>
<pre>
openstack security group rule create \
openstack security group rule create \
  --ingress \
   --proto tcp \
   --proto tcp \
   --dst-port 80 \
   --dst-port 80 \
  --ethertype IPv4 \
   mySecGroup
   mySecGroup
</pre>
</pre>


Assign security group to instance:
Assign security group to an instance:


<pre>
<pre>
Line 200: Line 291:
</pre>
</pre>


 
Remove security group from an instance:
=== Key Pairs (SSH Access) ===
 
Create a key pair:


<pre>
<pre>
openstack keypair create myKey > myKey.pem
openstack server remove security group myVM mySecGroup
chmod 600 myKey.pem
</pre>
</pre>


List key pairs:
Delete a security group:


<pre>
<pre>
openstack keypair list
openstack security group delete mySecGroup
</pre>
 
Delete a key pair:
 
<pre>
openstack keypair delete myKey
</pre>
</pre>

Latest revision as of 15:57, 26 April 2026

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


Prerequisites

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

sudo apt install python3-openstackclient 

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

python3 -m venv openstackclient_venv
source openstackclient_venv/bin/activate
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.


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>


Compute

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 (ensure that the specified image, flavor, network, and key pair exist):

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 (size in GB):

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 (delete) 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 \
  --ingress \
  --proto tcp \
  --dst-port 80 \
  --ethertype IPv4 \
  mySecGroup

Assign security group to an instance:

openstack server add security group myVM mySecGroup

Remove security group from an instance:

openstack server remove security group myVM mySecGroup

Delete a security group:

openstack security group delete mySecGroup