How to Create an Instance within Nova via the CLI

Within this article we will show you how to create an instance within Nova via the CLI.

Available Images

First of all we list the images available to Nova.

root@openstack-lab:~# nova image-list
+--------------------------------------+--------------------------+--------+--------+
| ID | Name | Status | Server |
+--------------------------------------+--------------------------+--------+--------+
| 23e82-5d3c-43a2-82b5-457f5e7 | cirros-0.3.2-x86_64-disk | ACTIVE | |
+--------------------------------------+--------------------------+--------+--------+

Flavours

Next we check the flavours available.

root@openstack-lab:~# nova flavor-list
+----+-----------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+---------------------+-----------+
| 1 | m1.tiny | 512 | 1 | 1 | 1.0 | True |
| 2 | m1.small | 2048 | 20 | 1 | 1.0 | True |
| 3 | m1.medium | 4096 | 40 | 2 | 1.0 | True |
| 4 | m1.large | 8192 | 80 | 4 | 1.0 | True |
| 5 | m1.xlarge | 16384 | 160 | 8 | 1.0 | True |
+----+-----------+-----------+------+-------+-------------+-----------+

SSH-Keys

To enable us to log into the instance an SSH key will be required. First we create the key pair. We then upload this to Nova. These SSH keys are then used later when buildng instance along with when we finally loginto the instance. 

root@openstack-lab:~# ssh-keygen -q -f ssh-key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
root@openstack-lab:~# nova keypair-add novakey --pub-key ssh-key.pub
root@openstack-lab:~# nova keypair-list
+----------+-------------------------------------------------+
| Name | Fingerprint |
+----------+-------------------------------------------------+
| novakey | 7f:11:bf:53:ac:98:27:b7:f9:a9:f9:e4:13:eb:08:8f |
+----------+-------------------------------------------------+

Security Group

A rule to permit the SSH port (tcp22) to the instance is then added to the default security group.

root@openstack-lab:~# nova secgroup-add-rule default tcp 22 22 10.1.1.0/24
+-------------+-----------+---------+-------------+--------------+
| IP Protocol | From Port | To Port | IP Range | Source Group |
+-------------+-----------+---------+-------------+--------------+
| tcp | 22 | 22 | 10.1.1.0/24 | |
+-------------+-----------+---------+-------------+--------------+

Create Instance

Next we create the instance.

root@openstack-lab:~# nova boot instance1 --image 23e82-5d3c-43a2-82b5-457f5e7 \
--flavor m1.tiny \
--key-name novakey

+--------------------------------------+-----------------------------------------+
| Property | Value |
+--------------------------------------+-----------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | - |
| OS-EXT-SRV-ATTR:hypervisor_hostname | - |
| OS-EXT-SRV-ATTR:instance_name | instance-00000002 |
| OS-EXT-STS:power_state | 0 |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| status | BUILD |
| tenant_id | b2162649b18840efb18314255e958990 |
| updated | 2015-08-26T20:29:24Z |
| user_id | 21d5a7f580ce4b98a68fbd197cceedbb |
+--------------------------------------+-----------------------------------------+

Check Instance

We then check the instance and that it is running and active.

root@openstack-lab:~# nova list
+-----------------------+-----------+--------+-------------+------------------+
| ID | Name | Status | Power State | Networks |
+-----------------------+-----------+--------+-------------+------------------+
| f51f24-9eb0-a076-1f6c | instance1 | ACTIVE | Running | private=10.1.1.1 |
+-----------------------+-----------+--------+-------------+------------------+

Connect to Instance

To confirm connectivity to the instance we log into it via SSH using the previously created SSH Key. 

root@openstack-lab:~# ssh -i ssh-key [email protected]
The authenticity of host '10.1.1.1 (10.1.1.1)' can't be established.
RSA key fingerprint is a0:6b:93:34:10:44:e5:4e:91:d9:c1:21:55:3a:99:0e.
Are you sure you want to continue connecting (yes/no)? yes

Delete Instance

Should you need to delete your instance the following command is used, 

root@openstack-lab:~# nova delete instance1
Request to delete server instance1 has been accepted.

root@openstack-lab:~# nova list
+----------+-----------+--------+------------+-------------+------------------+
| ID | Name | Status | Task State | Power State | Networks |
+----------+-----------+--------+------------+-------------+------------------+
+----------+-----------+--------+------------+-------------+------------------+
Rick Donato

Want to become an OpenStack expert?

Here is our hand-picked selection of the best courses you can find online:
OpenStack Essentials course
Certified OpenStack Administrator course
Docker Mastery course
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial