Guide: OpenStack CLI – Basic Usage: Difference between revisions
Created page with " = Guide: OpenStack CLI – Basic Usage = This guide provides a quick introduction to managing your bwCloud-OS project using the OpenStack CLI. It covers the most common operations for instances, storage, networking, and security. == General Information about Cloud, Project, and User == Before working with resources, you can inspect your current configuration and context:<pre> openstack configuration show openstack project list openstack token issue openstack region lis..." |
No edit summary |
||
| (46 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
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. | |||
This guide provides a quick introduction to managing your bwCloud-OS | |||
__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 == | ||
Before working with resources, you can inspect your current configuration and context:<pre> | |||
Before working with resources, you can inspect your current configuration and context: | |||
<pre> | |||
openstack configuration show | openstack configuration show | ||
openstack project list | openstack project list | ||
openstack token issue | openstack token issue | ||
openstack region list | openstack region list | ||
</pre> | |||
--> | |||
== Images == | |||
List available images: | |||
<pre> | |||
openstack image list | |||
</pre> | </pre> | ||
== | Upload a new image: | ||
Create an instance:<pre> | |||
<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> | |||
Show image details: | |||
<pre> | |||
openstack image show <IMAGE_ID> | |||
</pre> | |||
Delete an image: | |||
<pre> | |||
openstack image delete <IMAGE_ID> | |||
</pre> | |||
== Compute == | |||
=== 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> | |||
=== Instances === | |||
List instances: | |||
<pre> | |||
openstack server list | |||
</pre> | |||
Create an instance (ensure that the specified image, flavor, network, and key pair exist): | |||
<pre> | |||
openstack server create \ | openstack server create \ | ||
--image ubuntu-24.04 \ | --image ubuntu-24.04 \ | ||
--flavor | --flavor p1.tiny \ | ||
--network myNet \ | --network myNet \ | ||
--key-name myKey \ | --key-name myKey \ | ||
myVM | myVM | ||
</ | </pre> | ||
Show details of an instance: | |||
<pre> | |||
openstack server show myVM | openstack server show myVM | ||
</pre>Delete an instance:<pre> | </pre> | ||
Delete an instance: | |||
<pre> | |||
openstack server delete myVM | openstack server delete myVM | ||
</pre> | </pre> | ||
== Storage | == Storage== | ||
Create a volume:<pre> | |||
=== Volumes === | |||
List volumes: | |||
<pre> | |||
openstack volume list | |||
</pre> | |||
Create a volume (size in GB): | |||
<pre> | |||
openstack volume create --size 10 myVolume | openstack volume create --size 10 myVolume | ||
</pre> | </pre> | ||
openstack volume | |||
</pre>Attach a volume to an instance:<pre> | Delete a volume: | ||
<pre> | |||
openstack volume delete myVolume | |||
</pre> | |||
=== Volume Management for Instances === | |||
Attach a volume to an instance: | |||
<pre> | |||
openstack server add volume myVM myVolume | openstack server add volume myVM myVolume | ||
</pre>Detach a volume:<pre> | </pre> | ||
Detach a volume from an instance: | |||
<pre> | |||
openstack server remove volume myVM myVolume | openstack server remove volume myVM myVolume | ||
</pre> | </pre> | ||
== Networking == | == Networking == | ||
Create a network:<pre> | |||
=== Networks === | |||
List networks: | |||
<pre> | |||
openstack network list | |||
</pre> | |||
Create a network: | |||
<pre> | |||
openstack network create myNet | openstack network create myNet | ||
</pre>Create a subnet:<pre> | </pre> | ||
Delete a network (after detaching all ports from its subnets): | |||
<pre> | |||
openstack network delete myNet | |||
</pre> | |||
=== Subnets, Routers === | |||
Create a subnet: | |||
<pre> | |||
openstack subnet create mySubnet \ | openstack subnet create mySubnet \ | ||
--network myNet \ | --network myNet \ | ||
--subnet-range 192.168.1.0/24 | --subnet-range 192.168.1.0/24 | ||
</pre>Create a router:<pre> | </pre> | ||
Create a router: | |||
<pre> | |||
openstack router create myRouter | openstack router create myRouter | ||
</pre>Attach subnet to router:<pre> | </pre> | ||
Attach a subnet to a router: | |||
<pre> | |||
openstack router add subnet myRouter mySubnet | openstack router add subnet myRouter mySubnet | ||
</pre> | </pre> | ||
== | Set external gateway of a router: | ||
List security groups:<pre> | |||
<pre> | |||
openstack router set myRouter --external-gateway provider_default_net | |||
</pre> | |||
Detach a subnet from a router: | |||
<pre> | |||
openstack router remove subnet myRouter mySubnet | |||
</pre> | |||
Delete a router: | |||
<pre> | |||
openstack router delete myRouter | |||
</pre> | |||
Delete a subnet (after detaching all ports from the subnet): | |||
<pre> | |||
openstack subnet delete mySubnet | |||
</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: | |||
<pre> | |||
openstack floating ip list | |||
</pre> | |||
Associate a floating IP with an instance: | |||
<pre> | |||
openstack server add floating ip myVM <FLOATING_IP> | |||
</pre> | |||
Disassociate a floating IP from an instance: | |||
<pre> | |||
openstack server remove floating ip myVM <FLOATING_IP> | |||
</pre> | |||
Release (delete) a floating IP: | |||
<pre> | |||
openstack floating ip delete <FLOATING_IP> | |||
</pre> | |||
=== Security Groups === | |||
List security groups: | |||
<pre> | |||
openstack security group list | openstack security group list | ||
</pre>Create a security group:<pre> | </pre> | ||
Create a security group: | |||
<pre> | |||
openstack security group create mySecGroup | openstack security group create mySecGroup | ||
</pre>Add | </pre> | ||
Add a rule to a security group (e.g., HTTP access via port 80): | |||
<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 an instance: | |||
<pre> | |||
openstack server add security group myVM mySecGroup | |||
openstack server add | |||
</pre> | </pre> | ||
Remove security group from an instance: | |||
<pre> | |||
openstack server remove security group myVM mySecGroup | |||
openstack | |||
</pre> | </pre> | ||
Delete a security group: | |||
openstack | <pre> | ||
openstack security group delete mySecGroup | |||
</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.yamlfile
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