Guide: OpenStack CLI – Basic Usage: Difference between revisions

From bwCloud-OS
Jump to navigation Jump to search
No edit summary
 
(25 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]].


<!--
<!--
Line 18: Line 41:
-->
-->


== Compute ==
== Images ==
 
=== Images ===


List available images:
List available images:
Line 34: Line 55:
   --file=/path/to/images/ubuntu-24.04-server-cloudimg-amd64.img \
   --file=/path/to/images/ubuntu-24.04-server-cloudimg-amd64.img \
   --disk-format=qcow2 \
   --disk-format=qcow2 \
   --container-format=bare  
   --container-format=bare
</pre>
</pre>


Line 46: Line 67:


<pre>
<pre>
openstack image delete &lt;IMAGE_ID_OR_NAME&gt;
openstack image delete &lt;IMAGE_ID&gt;
</pre>
</pre>
== Compute ==
=== Key Pairs (SSH Access) ===
=== Key Pairs (SSH Access) ===


Line 77: Line 102:
</pre>
</pre>


Create an instance:
Create an instance (ensure that the specified image, flavor, network, and key pair exist):


<pre>
<pre>
Line 83: Line 108:
   --image ubuntu-24.04 \
   --image ubuntu-24.04 \
   --flavor p1.tiny \
   --flavor p1.tiny \
  --network myNet \
   --key-name myKey \
   --key-name myKey \
   myVM
   myVM
Line 98: Line 124:
openstack server delete myVM
openstack server delete myVM
</pre>
</pre>


== Storage==
== Storage==
Line 112: Line 135:
</pre>
</pre>


Create a volume:
Create a volume (size in GB):


<pre>
<pre>
Line 132: Line 155:
</pre>
</pre>


Detach a volume:
Detach a volume from an instance:


<pre>
<pre>
openstack server remove volume myVM myVolume
openstack server remove volume myVM myVolume
</pre>
</pre>


== Networking ==
== Networking ==
Line 152: Line 177:
<pre>
<pre>
openstack network create myNet
openstack network create myNet
</pre>
Delete a network (after detaching all ports from its subnets):
<pre>
openstack network delete myNet
</pre>
</pre>


Line 169: Line 200:
</pre>
</pre>


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


<pre>
<pre>
Line 175: Line 206:
</pre>
</pre>


Set external gateway:
Set external gateway of a router:


<pre>
<pre>
Line 181: Line 212:
</pre>
</pre>


Detach subnet from router:
Detach a subnet from a router:


<pre>
<pre>
Line 193: Line 224:
</pre>
</pre>


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


<pre>
<pre>
Line 202: Line 233:
=== Floating IPs ===
=== Floating IPs ===


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


<pre>openstack floating ip create provider_default_net</pre>
<pre>openstack floating ip create provider_default_net</pre>
Line 224: Line 255:
</pre>
</pre>


Release a floating IP:
Release (delete) a floating IP:
<pre>
<pre>
openstack floating ip delete &lt;FLOATING_IP&gt;
openstack floating ip delete &lt;FLOATING_IP&gt;
Line 247: Line 278:
<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 258: Line 291:
</pre>
</pre>


Remove security group from instance:
Remove security group from an instance:


<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