
Openstack, besides Horizon GUI Dashboard, can also be configured via command-line interface using commands in Bash. Below we present a list of common and useful commands for your reference.
Note: in OpenStack command-line interface you have to source appropriate keystonerc file in order to be able to invoke OpenStack commands within the specified Project Tenant. Sourcing of keystonerc file imports Tenant User/Admin credentials to environment variables during user session.
1. Keystone
1.1 Source admin keystonerc file (import admin credentials):
[root@controller ~]# source /root/keystonerc_admin 1.2 List all users
[root@controller ~(keystone_admin)]# keystone user-list1.3 List all user roles
[root@controller ~(keystone_admin)]# keystone role-list1.4 List all Project Tenants
[root@controller ~(keystone_admin)]# keystone tenant-list2. Glance
2.1 List images
[root@controller ~(keystone_admin)]# glance image-list2.2 Create public qcow2 based image named cirros_image from cirros-0.3.4-x86_64-disk.img file
[root@controller ~(keystone_admin)]# glance image-create --file cirros-0.3.4-x86_64-disk.img --disk-format qcow2 --container-format bare --is-public True --name cirros_image2.3 Delete image (specify image ID)
[root@controller ~(keystone_admin)]# glance image-delete aca1a00b-e5fc-4121-8c88-cef47b705a833. Nova
3.1 Display all nodes
[root@controller ~(keystone_admin)]# nova-manage host list3.2 Display status of services running on nodes
[root@controller ~(keystone_admin)]# nova-manage service list3.3 List instances within project tenant
[root@controller ~(tuxfixer@tuxfixer)]$ nova list3.4 List images
[root@controller ~(keystone_admin)]# nova image-list3.5 List flavors
[root@controller ~(keystone_admin)]# nova flavor-list3.6 Launch instance named instance2 using m1.tiny flavor, cirros image with 2 network interfaces connected to 2 internal networks (specify network IDs)
[root@controller ~(tuxfixer@tuxfixer)]$ nova boot --flavor m1.tiny --image cirros --nic net-id=c471aa63-813b-4588-9822-d8961801dd30 --nic net-id=b521aa63-514c-4577-9622-b8961801cc31 instance23.7 Start instance instance1
[root@controller ~(tuxfixer@tuxfixer)]$ nova start instance13.8 Stop instance instance1
[root@controller ~(tuxfixer@tuxfixer)]$ nova stop instance13.9 Terminate instance (shut down immediately and delete) instance1
[root@controller ~(tuxfixer@tuxfixer)]$ nova delete instance13.10 Allocate IP to Project Tenant from public_net pool
[root@controller ~(tuxfixer@tuxfixer)]$ nova floating-ip-create public_net3.11 Associate Floating IP 10.86.23.211 with instance1
[root@controller ~(tuxfixer@tuxfixer)]$ nova floating-ip-associate instance1 10.86.23.2113.12 Add allow-all security group to running instance cirros1
[root@controller ~(tuxfixer@tuxfixer)]$ nova add-secgroup cirros1 allow-all3.13 Remove default security group from running instance cirros1
[root@controller ~(tuxfixer@tuxfixer)]$ nova remove-secgroup cirros1 default 4. Neutron
4.1 List networks
[root@controller ~(keystone_admin)]# neutron net-list4.2 Show network details for pub_net
[root@controller ~(keystone_admin)]# neutron net-show pub_net4.3 List sub-networks
[root@controller ~(keystone_admin)]# neutron subnet-list4.4 Show sub-network details for pub_subnet
[root@controller ~(keystone_admin)]# neutron subnet-show pub_subnet4.5 Create router router1 in specified Project Tanant (specify ID)
[root@controller ~(tuxfixer@tuxfixer)]# neutron router-create --tenant-id 1bee77abc7744d918691a399e54f6b9f router14.6 List external (public) networks
[root@controller ~(keystone_admin)]# neutron net-external-list4.7 Create security group named allow-all-traffic in specified Project Tenant
[root@controller ~(tuxfixer@tuxfixer)]# neutron security-group-create --tenant-id 1bee77abc7744d918691a399e54f6b9f --description "Allow all traffic" allow-all-traffic4.8 Create rule in allow-all-traffic security group that allows for incoming (ingress) ping
[root@controller ~(tuxfixer@tuxfixer)]# neutron security-group-rule-create --tenant-id 1bee77abc7744d918691a399e54f6b9f --protocol icmp --direction ingress allow-all-traffic4.9 Create rule in allow-all-traffic security group that allows for outgoing (egress) TCP traffic in the whole port range (ports: 1 – 65535)
[root@controller ~(tuxfixer@tuxfixer)]# neutron security-group-rule-create --tenant-id 1bee77abc7744d918691a399e54f6b9f --protocol tcp --port-range-min 1 --port-range-max 65535 --direction egress allow-all-traffic4.10 Create network named priv_net1 in specified Tenant
[root@controller ~(tuxfixer@tuxfixer)]# neutron net-create --tenant-id 1bee77abc7744d918691a399e54f6b9f priv_net14.11 Create sub-network 192.168.10.0/24 named priv_subnet1 within priv_net1 network in specified Tenant
[root@controller ~(tuxfixer@tuxfixer)]# neutron subnet-create --tenant-id 1bee77abc7744d918691a399e54f6b9f --name priv_subnet1 priv_net1 192.168.10.0/244.12 Set gateway on router main_router from public network pub_net (attach router to public network)
[root@controller ~(tuxfixer@tuxfixer)]# neutron router-gateway-set main_router pub_net4.13 Add internal interface on main_router router for priv_net1 network (attach internal/private network to router)
[root@controller ~(tuxfixer@tuxfixer)]# neutron router-interface-add main_router priv_net14.14 Create port in priv_net1 network with fixed v4 IP 192.168.10.20
[root@controller ~(tuxfixer@tuxfixer)]# neutron port-create priv_net1 --fixed-ip ip_address=192.168.10.204.15 List provider / public networks (those with External flag)
[root@controller ~(keystone_admin)]# neutron net-external-list5. OVS (OpenVSwitch)
5.1 Display OVS based bridges with attached ports
[root@controller ~]# ovs-vsctl show5.2 Connect eth0 interface to br-ex bridge
[root@controller ~]# ovs-vsctl add-port br-ex eth05.3 Connect eth1 interface to br-eth1 bridge
[root@controller ~]# ovs-vsctl add-port br-eth1 eth16. Cinder
6.1 List Volumes
[root@controller ~(tuxfixer@tuxfixer)]$ cinder list6.2 Create 2GB sized volume named test_volume in specified Tenant
[root@controller ~(tuxfixer@tuxfixer)]$ cinder create 2 --display-name test_volume6.3 Delete volume named test_volume from Tenant
[root@controller ~(tuxfixer@tuxfixer)]$ cinder delete test_volumeNote: remember to detach volume from instance (if mounted) before deleting to avoid any problems with instance
6.4 Attach volume to existing instance (specify instance and volume ID)
[root@controller ~(tuxfixer@tuxfixer)]$ nova volume-attach b7b8c407-aa6a-4743-9cf4-7cba9c51ba2e b9e9f224-5625-48cc-b86f-41e26bc580ae auto6.5 Detach volume from instance (specify instance and volume ID)
[root@controller ~(tuxfixer@tuxfixer)]$ nova volume-detach b7b8c407-aa6a-4743-9cf4-7cba9c51ba2e b9e9f224-5625-48cc-b86f-41e26bc580ae6.6 Extend volume quota for tenant ID 7f3463da73a048b48054cd52541be970 up to 32 volumes
[root@controller ~(keystone_admin)]$ cinder quota-update --volumes 32 7f3463da73a048b48054cd52541be970Note: do not use tenant name in above command, it won’t work!
7. Swift
7.1 List containers
[root@controller ~(keystone_admin)]# swift list
This post is really good. It helped me a lot to set up my own cloud. Thanks !