Chapter 2: Nova - Basic Commands
In this chapter, we learn the frequently used nova commands.
The main purpose for Nova CLI is used for Managing the VMs and relavent Resources(such as keypair, flavor).
Commands :
1. Instances :
To list the instances,
nova list
To create a Instance,
Minimal Syntax:
nova boot --flavor <flavorid> --image <image name> --key-name <keyname> --security-groups <secgroup name> --nic net-name=<network name> <vm name>
Example:
nova boot --flavor 6 --image ubuntu14 --key-name testkey --security-groups default --nic net-name=N1 server1
Create two network interfaces:
nova boot --flavor 72604036-3967-4e87-a9b3-1b969e1c6f65 --image centos7 --key-name testkey --security-groups sureshsecgroup --nic port-id=d7cb2edd-9254-456d-89fd-0472423b36de --nic net-id=ea58220d-54dd-4cbc-932c-86995e1f7269 Xserv
To delete the instance,
nova delete <instance id or name >
nova delete server1
nova delete 05944df1-80ea-4407-80da-30c34494edf9
To stop the instance,
Running instances can be stopped(shutdown).
nova stop <instance id or name >
nova stop server1
To start the stopped(shut down) instance,
nova start <instance id or name >
nova start server1
To list the console logs for the instance,
nova console-log --lenght <no of lines> <vm-name>
nova console-log vrrp-master
nova console-log --length 10 vrrp-master
2. Flavor :
Flavor is a kind of profile used in VM creation. The profile consists of number of CPUs, Memory Size, HDD size, etc.
To List the flavors,
nova flavor-list
To create a flavor,
Note : flavor creation is authorized by admin user only.
Simple Syntax:
nova flavor-create <flavor Name> <flavor id> <RAM Size in MB> <HDD in GB> <Number of VCPUS>
nova flavor-create m1.tiny2 6 1024 4 1
To delete a flavor,
Note : flavor deletion is authorized by admin user only.
Syntax:
nova delete <flavor id>
nova flavor-delete 6
To create a flavor key
Flavor key is used for passing the args to libvirt (Ex: Limit the bandwidth of the VM Interface)
nova flavor-key m1.tiny2 set quota:vif_inbound_average=1000
nova flavor-key m1.tiny2 set quota:vif_inbound_peak=1000
nova flavor-key m1.tiny2 set quota:vif_inbound_burst=100
nova flavor-key m1.tiny2 set quota:vif_outbound_average=1000
nova flavor-key m1.tiny2 set quota:vif_outbound_peak=1000
nova flavor-key m1.tiny2 set quota:vif_outbound_burst=100
Note : here the values are in Kilobytes
3. Keypair :
Keypair(public, private key) is used by nova, to write the key in the VM for secure login using Metadata services
Create a new keypair,
Nova will create/generate a keypair(public /private key), we will save the private key in to a file.
Syntax:
nova keypair-add <keypair name>
Example :
nova keypair-add testkey
This will output the private key, this needs to be saved in to a file.
Import a existing keypair in to nova :
you have the existing keypair(private, pub files) and you want use that .
Note: You can generate the keypair using openssl tools
ssh-keygen -t rsa -b 4096 -C "email id"
Syntax:
nova keypair-add --pub-key <public key file name> <key name>
Example:
nova keypair-add --pub-key vmkey.pub vmkey
List keypairs:
nova keypair-list
Delete a keypair:
nova keypair-delete <keyname>
Example
nova keypair-delete testkey
4. Bootstrap/Cloudinit Script
we can pass the bootstrap(scripts which will execute at the time of VM boots up)script to perform some initialization tasks in the VM. This is technically refered as cloud-init.
- create the script file and pass this file name in option "--user-data <script name>" in "nova boot" command
Example :
nova boot --flavor 6 --image ubuntu14 --key-name testkey --security-groups default --user-data bootscript.sh --nic net-name=N1 VM1
Execution Logs:
1. Instances :
(osclient)cloud@db:~/osclient$ nova list
+--------------------------------------+------+--------+------------+-------------+----------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+----------------------------+
| 565acfca-a75a-4782-9d61-3caff6274efc | vm1 | ACTIVE | - | Running | N2=10.10.20.4, 172.24.4.12 |
+--------------------------------------+------+--------+------------+-------------+----------------------------+
(osclient)cloud@db:~/osclient$ nova boot --flavor 6 --image ubuntu14 --key-name testkey --security-groups default --nic net-nam
e=N1 server1
+--------------------------------------+-------------------------------------------------+
| Property | Value |
+--------------------------------------+-------------------------------------------------+
| OS-DCF:diskConfig | MANUAL |
| OS-EXT-AZ:availability_zone | |
| OS-EXT-STS:power_state | 0 |
| OS-EXT-STS:task_state | scheduling |
| OS-EXT-STS:vm_state | building |
| OS-SRV-USG:launched_at | - |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| adminPass | ChY3voYQwQhB |
| config_drive | |
| created | 2017-08-10T10:27:03Z |
| description | - |
| flavor | m1.tiny2 (6) |
| hostId | |
| id | 05944df1-80ea-4407-80da-30c34494edf9 |
| image | ubuntu14 (eb570c2e-46e2-4cc3-928a-fe5cdffa7822) |
| key_name | testkey |
| locked | False |
| metadata | {} |
| name | server1 |
| os-extended-volumes:volumes_attached | [] |
| progress | 0 |
| security_groups | default |
| status | BUILD |
| tags | [] |
| tenant_id | bccf45eee4544264a526c4bca56fdb3c |
| updated | 2017-08-10T10:27:03Z |
| user_id | 9b2d58dc14b2456fa5b7e5adae366f04 |
+--------------------------------------+-------------------------------------------------+
(osclient)cloud@db:~/osclient$
(osclient)cloud@db:~/osclient$ nova stop server1
Request to stop server server1 has been accepted.
(osclient)cloud@db:~/osclient$
(osclient)cloud@db:~/osclient$ nova list
+--------------------------------------+---------+---------+------------+-------------+----------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+---------+---------+------------+-------------+----------------------------+
| d089347b-50d1-456a-89c8-57454f3c705c | server1 | SHUTOFF | - | Shutdown | N1=10.10.10.12, 172.24.4.7 |
+--------------------------------------+---------+---------+------------+-------------+----------------------------+
(osclient)cloud@db:~/osclient$ nova start server1
Request to start server server1 has been accepted.
(osclient)cloud@db:~/osclient$ nova list
+--------------------------------------+---------+--------+------------+-------------+----------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+---------+--------+------------+-------------+----------------------------+
| d089347b-50d1-456a-89c8-57454f3c705c | server1 | ACTIVE | - | Running | N1=10.10.10.12, 172.24.4.7 |
+--------------------------------------+---------+--------+------------+-------------+----------------------------+
(osclient) cloud@dev1:~/osclient$ nova console-log --length 10 vrrp-master
ec2: 2048 6b:ff:f2:d5:33:4d:b3:b1:9a:1e:c8:03:a5:a6:1a:6c root@vrrp-master (RSA)
ec2: -----END SSH HOST KEY FINGERPRINTS-----
ec2: #############################################################
-----BEGIN SSH HOST KEY KEYS-----
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAahf7mXfsds9kwoxMyJbys867bfxzts2uCwTsTwUUYjlXyATPzkPNakiLUIoQiQJD6Ov/2dNi8VwedzzTgCd88= root@vrrp-master
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGJFovHmT983fXeBbJkjB5vzG7bAlYoIsHg3VYpP5oLA root@vrrp-master
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqW96oz+9oqX1Aouw9aS5A1cGy1ahGdeGPU7vWtI655FcNNaWyQBPlWzk4FUnZN0CMh7QK0Ci1/IfbfhxllHVA8TBljqzy4I2PJrL8fCrGjydL2SejbYJVS7gvC6tlkaCe3svs15eo3QT/6V+qr7R3JUu5tvqGcBxPpSZzohLWWPBR8AlBTMrbanQmm3gqlMukHxRuxS/fSNnSdqjWUtMkPwYRGw5Ks9A+OzAESKnBBMsTfe/fkUr51ak+vq9QOnHfZXXflwX/sHVto4VIAEdSvwCxHH3C6keeQCrlMhaFNpdOp7PmhehMyRk/XvlFuzJH4pgQ6m2PWkmLFPtFbmNf root@vrrp-master
-----END SSH HOST KEY KEYS-----
Cloud-init v. 0.7.5 finished at Sun, 27 Aug 2017 16:08:34 +0000. Datasource DataSourceOpenStack [net,ver=2]. Up 117.28 seconds
(osclient) cloud@dev1:~/osclient$
2. Flavors :
(osclient)cloud@db:~/osclient$ nova flavor-list
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
| 1 | m1.tiny | 512 | 1 | 0 | | 1 | 1.0 | True |
| 2 | m1.small | 2048 | 20 | 0 | | 1 | 1.0 | True |
| 3 | m1.medium | 4096 | 40 | 0 | | 2 | 1.0 | True |
| 4 | m1.large | 8192 | 80 | 0 | | 4 | 1.0 | True |
| 42 | m1.nano | 64 | 0 | 0 | | 1 | 1.0 | True |
| 5 | m1.xlarge | 16384 | 160 | 0 | | 8 | 1.0 | True |
| 6 | m1.tiny2 | 1024 | 4 | 0 | | 1 | 1.0 | True |
| 84 | m1.micro | 128 | 0 | 0 | | 1 | 1.0 | True |
| c1 | cirros256 | 256 | 0 | 0 | | 1 | 1.0 | True |
| d1 | ds512M | 512 | 5 | 0 | | 1 | 1.0 | True |
| d2 | ds1G | 1024 | 10 | 0 | | 1 | 1.0 | True |
| d3 | ds2G | 2048 | 10 | 0 | | 2 | 1.0 | True |
| d4 | ds4G | 4096 | 20 | 0 | | 4 | 1.0 | True |
+----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
#performed with admin user creds
$ nova flavor-create m1.tiny2 6 1024 4 1
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
| 6 | m1.tiny2 | 1024 | 4 | 0 | | 1 | 1.0 | True |
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
# performed with admin user creds
$ nova flavor-delete 6
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
| ID | Name | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
| 6 | m1.tiny2 | 1024 | 4 | 0 | | 1 | 1.0 | True |
+----+----------+-----------+------+-----------+------+-------+-------------+-----------+
cloud@dev1:~$
3. Keypair :
osclient)cloud@db:~/osclient$ nova keypair-add testkey1
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAyCTSDE8tfotPFMpLuoCsYQ7b14/Go1FkvphysHUSakV80KmV
7I+UMaxfGd07KdruME5RJiZInCwocL/3cP8+o48xb26GBRr1F95bwSI6I76MxH36
rolDdQydFUN8uyFsqbvmvubObsvwbdJesOtoqf3BnpU9Fy4rjLAFwyCTU64a3YYL
agTWNt8xbqR5LU8aM0e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Hmr/ox5Z+sBA43I
m295RsYn1YcLsXx4zpL/v3FPNzV4sTmbIYgYJAqTcdwvv9tYKINXrBgmh/zO4JWc
5fAI6himwEe5l5vF0HERk7PFiX7Z1A6SItJuci7CziQBqnZeMgrzhOxZhidwe59i
TPMfAoGBAJ3pclhur/AvJCcJahEW7yIEbbyd/PLJslXdZTcJT36khx2fKyhotodC
b293uHUrKHyE7hA99/cD2HAnf11YU2tIyBjUt99QjlrYUdghqUidhykHzuwxafhQ
ml95thk5xuOm5YRox7LZtR17ripPm8OHnQr4ucjkfmwkSAfUx16p
-----END RSA PRIVATE KEY-----
(osclient)cloud@db:~/osclient$
(osclient)cloud@db:~/osclient$ nova keypair-list
+----------+------+-------------------------------------------------+
| Name | Type | Fingerprint |
+----------+------+-------------------------------------------------+
| testkey | ssh | 34:33:a3:a5:a7:ad:3e:90:65:6a:b7:0c:4f:d6:0a:6b |
| testkey1 | ssh | 0c:46:3e:ed:13:5f:b8:94:f3:29:d3:53:46:b6:6c:68 |
+----------+------+-------------------------------------------------+
(osclient)cloud@db:~/osclient$
(osclient)cloud@db:~/osclient$ ssh-keygen -t rsa -b 4096 -C "email id"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/cloud/.ssh/id_rsa): mykey1
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in mykey1.
Your public key has been saved in mykey1.pub.
The key fingerprint is:
a3:3b:f6:48:9a:e9:94:97:0c:dd:7d:57:fb:3d:2b:5c email id
The key's randomart image is:
+--[ RSA 4096]----+
| |
| |
| .|
| . . . ..|
| . . S . . .. |
| + o . . . Eo|
| o * . ..o|
| . *oo o o|
| .=.oo. .. |
+-----------------+
(osclient)cloud@db:~/osclient$ ls mykey*
mykey1 mykey1.pub
(osclient)cloud@db:~/osclient$ nova keypair-add --pub-key mykey1.pub mykey1
(osclient)cloud@db:~/osclient$
4. Bootstrap /Cloudinit script:
cloud@devstack3:~/devstack$ cat bootscript.sh
#!/bin/bash
echo $'auto eth1\niface eth1 inet dhcp' | sudo tee /etc/network/interfaces.d/eth1.cfg > /dev/null
sudo ifup eth1
echo $'auto eth2\niface eth2 inet dhcp' | sudo tee /etc/network/interfaces.d/eth2.cfg > /dev/null
sudo ifup eth2
sudo sysctl net.ipv4.ip_forward net.ipv4.ip_forward=1
sudo apt-get install -f apache2
cloud@devstack3:~/devstack$
nova boot fwVNF --flavor 6 --image ubuntu14 --key-name testkey --security-groups default --user-data bootscript.sh --nic net-id=ab580d57-97d8-4b28-8800-42403b406609 --nic net-id=91eaa294-a5bc-4f9b-8dde-b8deeebb10bb