In this article I will share some of the basic OpenStack command line cheat sheet which can be useful for beginners starting with OpenStack.

OpenStack command line cheat sheet

 

Identity (Keystone)

To list the installed users

openstack user list

Show provided user’s properties

openstack user show <username>

Create a user Willian with password redhat, email as [email protected] and is part of project Production

openstack user create --project Production --email [email protected] --password redhat --enable William

Assign admin role to user William

openstack role add --user William --project Production admin

Check the assigned role to user William

openstack role assignment list --user William --project Production

openstack role assignment list --user William --project Production --names

Enable or disable user William

openstack user set --disable William

openstack user set --enable William

 

Flavor

Create flavor named m1.petite with 1 vcpu, 1 GB RAM, 10 GB Disk and must not be publicly accessible

openstack flavor create --id auto --vcpus 1 --ram 1024 --disk 10 --private m1.petite

Assign flavor m1.petite to Engineering project

openstack flavor set --project Engineering m1.petite

 

Security Group

Create security group with name ssh

openstack security group create ssh

Add a rule to allow ssh and icmp in the ssh security group

openstack security group rule create --ingress --protocol tcp --dst-port 22 ssh

openstack security group rule create --ingress --protocol tcp --protocol icmp ssh

 

Keypair

Create a keypair with name webkey in your home folder

openstack keypair create webkey > ~/webkey.pem

 

Glance Image

Create a glance image webimage using a file osp-small.qcow2 available inside /tmp

openstack image create --disk-format qcow2 --file /tmp/osp-small.qcow2 webimage

 

Neutron (Network)

Create a public and private network under Engineering project

openstack network create --external --provider-network-type flat --provider-physical-network datacentre --project Engineering --enable --no-share public

openstack network create --internal --project Engineering --enable --no-share private

Create external network with subnet 172.25.250.20/24, gateway as 172.25.250.254, and an allocation pool between 172.25.250.100-150

openstack subnet create --network public --no-dhcp --project Engineering --subnet-range 172.25.250.0/24 --gateway 172.25.250.254 --allocation-pool start=172.25.250.100,end=172.25.250.150 external

Create internal network with subnet range 192.168.1.0/24

openstack subnet create --network private --project Engineering --subnet-range 192.168.1.0/24 internal

Create and configure a router with name Router1

openstack router add subnet Router1 internal

neutron router-gateway-set Router1 public

 

Server (Instance)

Create an instance/server using the flavor m1.petite, key as webkey, security group as ssh and Router1 network

openstack server create --image webimage --flavor m1.petite --key-name webkey --security-group ssh --nic net-id=private webserver

Create a floating IP for the instance

openstack ip floating create public

Assign floating IP to the webserver instance

openstack ip floating add 172.25.250.100 webserver

 

Block Storage

Create a 2GB block storage volume named storage

openstack volume create --size 2 --project Engineering storage

Attach the storage to the webserver instance as /dev/sdb

openstack server add volume --device /dev/sdb webserver storage

 

Snapshot

Before creating snapshot detach the volume from webserver instance

openstack server remove volume webserver storage

Here strgsnap is the snapshot name and storage is the name of the volume attached

openstack snapshot create --name strgsnap storage

Attach volume back to webserver after taking the snapshot

openstack server add volume --device /dev/sdb webserver storage

 

Guestfish

Edit an image using guestfish

yum install -y libguestfs-tools-c

Here osd-webserver.qcow2 is the image which we will edit

$ guestfish -i --network -a /root/osd-webserver.qcow2

><fs> command "yum -y install httpd"
><fs> command "systemctl enable httpd"

><fs> command "systemctl is-enabled httpd"
enabled

><fs> command "touch /var/www/html/index.html"

><fs> edit /var/www/html/index.html 
><fs> command "ls -l /var/www/html/index.html"
-rw-r--r-- 1 root root 20 Oct 18 16:14 /var/www/html/index.html

><fs> command "sudo useradd Sheila"
><fs> command "sudo grep Sheila /etc/shadow"

><fs> selinux-relabel /etc/selinux/targeted/contexts/files/file_contexts /
><fs> exit

Above we are installing httpd, enabling the service, creating a password less user Sheila, creating a dummy index.html file and updating the selinux context which is the most important part. Without this your image will not work.

 

Lastly I hope this article with OpenStack command line cheat sheet was helpful. So, let me know your suggestions and feedback using the comment section.

1 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *