Sunday, 7 June 2015

How to create a virtual machine using openstack nova python client

1) First create python nova client object

from novaclient.v2 import client
USER = "admin"
PASS = "cloud"
TENANT = "admin"
nova_conn = client.Client(USER, PASS, TENANT, AUTH_URL, service_type="compute")


#import client from novaclient.v2, since the class "Client" defined in
from novaclient.v2 import client

#Declare username, password, tenant/project and auth_url
#AUTH_URL tells where the authentication service (keystone) is running.
USER = "admin"
PASS = "cloud"
TENANT = "admin"

#Create a object of class Client (create a connection to nova).
nova_conn = client.Client(USER, PASS, TENANT, AUTH_URL, service_type="compute")

 2) Create a vm

a) Find image id:

 >>> [(, for x in nova_conn.images.list()]

b) Find flavor id:

>>> [(, for x in nova_conn.flavors.list()]

c) Create a vm named "myvm2"

>>> nova_conn.servers.create("myvm2", "b935b518-8bed-4947-91ae-a2ed78f591e6", "1")
  • b935b518-8bed-4947-91ae-a2ed78f591e6  --->  id of image "newimage"
  • 1 --->  id of flavor "m1.tiny"
d) List all vms

>>> [(, for x in nova_conn.servers.list()]

3) How to find methods and attributes:

a) Find methods and attribute of "nova_conn".

>>> dir(nova_conn)

 b) Find methods and attribute of "nova_conn.servers".

>>> dir(nova_conn.servers)

 4) How to get help page.

a)find help of "nova_conn.servers.create".

>>> help(nova_conn.servers.create)

Saturday, 6 June 2015

Python How to Install and activate Virtualenv

How to Install and activate Virtualenv

1) Install virtualenv

           $ sudo apt-get install python-virualenv

2) Create virtual environment for our project

          $ virtualenv myenv

virtualenv venv will create a folder in the current directory which will contain the Python executable files. The name of virtualenv is "myenv".

3) To begin using the virtual environment, it needs to be activated

           $ source myenv/bin/activate

The name of the current virtual environment will now appear on the left of the prompt.Like this ,


If you want to install any python packages inside the virtual environment then do not use the command: "$ sudo apt-get install packagename".

I am going to show you install python package "django" inside the virtual environment "myenv" using command "$ pip install django" and don't  use     "$ sudo" command before "$ pip" command:

            $ pip install django

4) If you are done working in the virtual environment for the moment, you can deactivate it:

$ deactivate

The packages which i am installing into virtual environment "myenv" are stored in "myenv/lib/python2.7/site-packages"

In this screenshot you can see the package "django" i installed.

Wednesday, 3 June 2015

OpenStack Keystone Operations Using CLI

Keystone Operations using CLI

1) Create a project

anusreee@anusreee-VirtualBox:~/devstack$ keystone tenant-create --name accounting

Then list of all project using the command:

anusreee@anusreee-VirtualBox:~/devstack$ keystone tenant-list

2) Create a user

 anusreee@anusreee-VirtualBox:~/devstack$ keystone user-create --name mily --pass mily123 --enabled true

Then list all the users using the command :

anusreee@anusreee-VirtualBox:~/devstack$ keystone user-list

3) Add the user "mily" to the project "accounting" with "member" role.

anusreee@anusreee-VirtualBox:~/devstack$ keystone user-role-add --user 4a64febe98c8458990dd1c30914092c8 --role 705cd9b1bd494d83848b8252d3609ddc --tenant 1233d68292f94f8e9f422c47fe7270c

ie: keystone user-role-add --user <user-id> --role <role-id> --tenant <tenant-id>

After add the user "mily" to the project "accounting" with role "member" we have to go to browser and login as the user "mily"

After login:

Monday, 1 June 2015

OpenStack CLI Examples

Goto devstack folder
$ cd devstack

Run to run all services
$ ./

* Press "Ctrl" + "A", then press "D" to exit from "" window.

Export OpenStack admin user credentials
$ source openrc admin

Run some keystone commands
$ keystone tenant-list

$ keystone user-list

$ keystone role-list

$ keystone tenant-get <id>

$ keystone user-get <id>

$ keystone role-get <id>

* To see all tenant, user and role related commands
$ keystone --help | grep tenant

$ keystone --help | grep user

$ keystone --help | grep role

* To see all keystone commands
$ keystone --help

Run some nova commands
$ nova list

$ nova show <id>

 $ nova flavor-list

 $ nova flavor-show <id>

* To see all flavor related commands
$ nova --help | grep flavor

* To see all nova commands
$ nova --help

Run some glance commands
$ glance image-list

 $ glance image-show <id>

* To see all glance commands
$ glance --help

Run some cinder commands
$ cinder list

$ cinder show <id>

* To see all cinder commands
$ cinder --help

Run some nova network commands
 $ nova net-list

$ nova net <id>

Goto horizon dashboad

* Compare outpot of all above commands with what you are seeing in horizon dashboad.