OpenStack CLI and APIs, Tenant Model and Quotas
You can manage OpenStack through Horizon's web pages or by typing commands. The typed method is called the command-line interface (CLI).
Commands and programs use OpenStack's APIs (Application Programming Interfaces) to request work. In this lesson, you will also learn projects, which group resources, and quotas, which limit how many resources a project can use.
Horizon is like using the TV's on-screen menu – easy, one step at a time. The CLI is like a universal remote with shortcut buttons – faster, and you can record a sequence (a script) and replay it any time.
The OpenStack CLI
The unified client python-openstackclient gives one command, openstack, for all services:
pip install python-openstackclient
openstack --version
General pattern: openstack <object> <action> [options] [name]
openstack server create– create a server (VM (Virtual Machine))openstack network list– list networksopenstack volume delete– delete a volume
Logging in with an openrc file
The CLI needs your login details and the Keystone address. These are usually put in environment variables inside an openrc file (you can download it from Horizon → API Access):
# demo-openrc.sh
export OS_AUTH_URL=http://192.168.56.10/identity/v3
export OS_PROJECT_NAME=demo
export OS_PROJECT_DOMAIN_NAME=Default
export OS_USERNAME=demo
export OS_USER_DOMAIN_NAME=Default
export OS_PASSWORD=secret
export OS_IDENTITY_API_VERSION=3
export OS_REGION_NAME=RegionOne
source demo-openrc.sh
openstack token issue # proves that login works
source loads the variables into your terminal session. If openstack token issue prints a token, you are logged in.
Another way: a ~/.config/openstack/clouds.yaml file, used with --os-cloud mycloud.
The complete instance workflow in commands
These commands do in the terminal exactly what you did in Horizon:
# 1. Image
openstack image create cirros \
--file cirros-0.6.2-x86_64-disk.img --disk-format qcow2 --container-format bare --public
openstack image list
# 2. Flavor (admin) and listing
openstack flavor create m1.lab --vcpus 1 --ram 512 --disk 1
openstack flavor list
# 3. Key pair
openstack keypair create mykey > mykey.pem && chmod 600 mykey.pem
# 4. Network, subnet, router
openstack network create private-net
openstack subnet create private-subnet --network private-net \
--subnet-range 10.10.0.0/24 --gateway 10.10.0.1 --dns-nameserver 8.8.8.8
openstack router create router1
openstack router set router1 --external-gateway public
openstack router add subnet router1 private-subnet
# 5. Security group rules
openstack security group create web-sg --description "SSH, HTTP, ping"
openstack security group rule create web-sg --protocol tcp --dst-port 22 --remote-ip 0.0.0.0/0
openstack security group rule create web-sg --protocol tcp --dst-port 80
openstack security group rule create web-sg --protocol icmp
# 6. Launch the instance
openstack server create web-01 --image cirros --flavor m1.tiny \
--network private-net --security-group web-sg --key-name mykey --wait
openstack server list
# 7. Floating IP for external access
openstack floating ip create public
openstack server add floating ip web-01 172.24.4.150
ssh -i mykey.pem cirros@172.24.4.150
# 8. Volume
openstack volume create --size 5 data-vol
openstack server add volume web-01 data-vol
# Lifecycle
openstack server stop web-01 ; openstack server start web-01
openstack server reboot --hard web-01
openstack server resize --flavor m1.small web-01 ; openstack server resize confirm web-01
openstack server image create --name web-01-snap web-01
openstack console log show web-01
openstack server delete web-01
- Upload an image (CirrOS – a tiny test Linux) and list images.
- Create a flavor (VM size) – admins only – and list flavors.
- Create a key pair, save the private key to
mykey.pem, and protect it withchmod 600. - Create a private network and subnet (
10.10.0.0/24), a router, connect the router to the public network and to the subnet. - Create a security group and open SSH (Secure Shell) (22), HTTP (Hypertext Transfer Protocol) (80) and ping (ICMP (Internet Control Message Protocol)).
- Launch the VM
web-01with all of the above and wait until it is ready. - Get a floating (public) IP (Internet Protocol), attach it to the VM, and SSH in.
- Create a 5 GB volume and attach it.
- Lifecycle: stop/start, hard reboot, resize to a bigger flavor, take a snapshot, see the boot log, delete.
$ openstack server list
+--------------------------------------+--------+--------+-------------------------------------------+--------+---------+
| ID | Name | Status | Networks | Image | Flavor |
+--------------------------------------+--------+--------+-------------------------------------------+--------+---------+
| 6f1d…-…-9b2e | web-01 | ACTIVE | private-net=10.10.0.23, 172.24.4.150 | cirros | m1.tiny |
+--------------------------------------+--------+--------+-------------------------------------------+--------+---------+
Useful commands
| Command | Purpose |
|---|---|
openstack catalog list |
Show the address of every service (from Keystone) |
openstack server show NAME |
Full details of one VM |
openstack server list --all-projects |
(admin) VMs of all tenants |
openstack hypervisor list / hypervisor stats show |
(admin) how much compute capacity exists |
openstack network agent list |
Health of the Neutron agents |
openstack compute service list |
Status of the Nova services |
openstack limits show --absolute |
Your quota usage |
openstack --debug server list |
Shows the raw HTTP API calls behind the command – great for learning |
Virtual lab · OpenStack · 35 min
Multi-tenancy and quotas with the OpenStack CLI
As cloud admin, onboard a new tenant from the command line – project, user, role and quotas – then work as that tenant, build self-service networking and watch Nova enforce the instance quota.
OpenStack APIs
Every service has a versioned REST (Representational State Transfer) API. Their addresses are listed in the service catalogue that Keystone gives you at login.
| Service | Typical address (endpoint) |
|---|---|
| Keystone (identity v3) | http://controller:5000/v3 |
| Nova (compute v2.1) | http://controller:8774/v2.1 |
| Neutron (network v2.0) | http://controller:9696/v2.0 |
| Glance (image v2) | http://controller:9292/v2 |
| Cinder (volume v3) | http://controller:8776/v3/{project_id} |
| Heat (orchestration v1) | http://controller:8004/v1/{project_id} |
Using an API always takes two steps:
Step 1 – get a token from Keystone
curl -i -X POST http://controller:5000/v3/auth/tokens \
-H "Content-Type: application/json" -d '{
"auth": {
"identity": { "methods": ["password"],
"password": { "user": { "name": "demo", "domain": {"name": "Default"}, "password": "secret" } } },
"scope": { "project": { "name": "demo", "domain": {"name": "Default"} } }
}}'
# Response header: X-Subject-Token: gAAAAABl… (valid ~1 hour)
You send your username, password and project; Keystone replies with a token in the X-Subject-Token header.
Step 2 – call a service with the token
curl -s http://controller:8774/v2.1/servers -H "X-Auth-Token: gAAAAABl…"
curl -s -X POST http://controller:8774/v2.1/servers -H "X-Auth-Token: gAAAAABl…" \
-H "Content-Type: application/json" -d '{
"server": { "name": "api-vm", "imageRef": "<image-uuid>", "flavorRef": "1",
"networks": [{"uuid": "<net-uuid>"}], "key_name": "mykey" } }'
The first call lists your VMs; the second creates one. Each request carries the token in X-Auth-Token.
Ready-made libraries (SDKs (Software Development Kits)) wrap these calls: openstacksdk (Python), gophercloud (Go), jclouds (Java). Tools such as Terraform and Ansible use the same APIs.
The tenant model
OpenStack is multi-tenant: many independent organisations or teams share one cloud, but each sees only its own resources.
flowchart TB
D1[Domain: Default] --> P1[Project: demo]
D1 --> P2[Project: finance]
D2[Domain: university.edu] --> P3[Project: cs-lab]
U1[User: priya] -- role: member --> P1
U1 -- role: reader --> P2
U2[User: admin] -- role: admin --> P1 & P2
G1[Group: students] -- role: member --> P3
| Concept | Meaning |
|---|---|
| Domain | The top-level box of projects, users and groups – often one per organisation |
| Project (tenant) | The unit of ownership and separation – it owns VMs, networks, volumes; quotas apply here |
| User | An identity – a person or a service account |
| Group | A set of users; roles can be given to a whole group |
| Role | A set of permissions (admin, member, reader) – given to a user/group on a specific project or domain |
| Policy | Each service's policy.yaml says which role is needed for each API action |
Older documents and the Keystone v2 API say tenant; Keystone v3 says project. They mean the same thing.
Tenant model operations (admin)
openstack project create --domain default --description "Finance team" finance
openstack user create --domain default --password-prompt ravi
openstack role add --project finance --user ravi member
openstack role assignment list --project finance --names
openstack project list ; openstack user list ; openstack role list
openstack project set --disable finance # suspend a tenant
The commands create the finance project and user ravi, assign a role, list the results and disable the project. Check each result before moving to the next command.
How tenants are kept apart (isolation):
- each tenant's networks are separate (VXLAN (Virtual Extensible Local Area Network)/VLAN (Virtual Local Area Network) segmentation in Neutron),
- security groups belong to one project,
- every API call checks who owns the resource,
- quotas are per project.
Quotas
A quota is a limit on how many resources a project may use. It helps prevent one project from using all the shared capacity.
Default quotas (typical)
| Service | Resource | Default |
|---|---|---|
| Nova | instances (VMs) | 10 |
| cores (vCPUs) | 20 | |
| RAM (Random Access Memory) | 51200 MB | |
| key pairs | 100 | |
| Neutron | networks · subnets · routers | 100 · 100 · 10 |
| floating IPs | 50 | |
| security groups · rules | 10 · 100 | |
| ports | 500 | |
| Cinder | volumes · snapshots | 10 · 10 |
| gigabytes | 1000 |
Viewing and setting quotas
openstack quota show demo # all quotas of a project
openstack quota set --instances 5 --cores 8 --ram 8192 demo
openstack quota set --floating-ips 2 --volumes 4 --gigabytes 100 demo
openstack quota show --default # defaults for new projects
openstack limits show --absolute --project demo # usage vs limits
In Horizon: Identity → Projects → Modify Quotas (admin). Users see their own usage as pie charts on Project → Compute → Overview.
If a request exceeds the project quota, OpenStack rejects it. For example, a project already using all 5 allowed instances cannot create a sixth. Check the error message and current usage.
Universities running OpenStack give each course a project with quotas (for example 30 instances, 60 cores, 2 floating IPs), so one class cannot use the whole cloud during exam week. Public OpenStack clouds raise quotas when customers ask – exactly like AWS (Amazon Web Services) service quotas.
Summary
- The unified
openstackCLI uses object + action commands and logs in with an openrc file orclouds.yaml. - Every operation is a REST API call carrying a Keystone token (
X-Auth-Token). - Tenant model: domains contain projects, users and groups; roles are given to users/groups on projects.
- Quotas limit what each project can use (instances, cores, RAM, networks, floating IPs, volumes) and are managed with
openstack quota show/set.
Practice questions
- What is the OpenStack CLI? How do you authenticate it?
- Write the CLI commands to create a network, router, security group and launch an instance with a floating IP.
- Explain how an OpenStack REST API call is authenticated with Keystone.
- Explain the OpenStack tenant model (domain, project, user, group, role).
- What are quotas? Write commands to view and modify quotas of a project.
- What happens when a project exceeds its instance quota?
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.