Sunday 15 November 2015

Installation of OpenStack with Murano on Cloud (Digital Ocean)

As OpenStack and Murano's system prerequisites is high. (shown below)

System prerequisite for Murano:

Criteria Minimum Requirement
CPU 4 core @ 2.4 GHz
RAM 8 GB
HDD 2 x 500 GB (7200 rpm)
RAID Software RAID-1 (use mdadm as it will improve read performance almost two times)


It might not be possible for everyone to have it on local system. Here is the solution for this problem. You can install OpenStack and Murano on cloud. Here I am using Digital Ocean cloud service.

Lets follow some simple and basic steps:

Step 1: First sign up Digital Ocean website. (If you already have it skip this step)


Add required information and credit card and you are done with account setup formality.

Step 2: Now create a Droplate (a virtual machine).


Creation of Droplet requires:

1. Provide a host name for your droplet.

2. Select the size for droplet. (Recommended size is 8GB RAM)


3. Now select the region in which droplet will be hosted.


4. Select image to be installed on droplet. Here select Ubuntu 14.04 image.

5. Add ssh key of your local system. To generate ssh key on ubuntu
Run:


$ ssh-keygen -t rsa

This command will prompt you to:
a. Select a file to store key. (Hit enter if you want to store key in /home/demo/.ssh/id_rsa file)
b. Enter passphrase. (Hit enter if you don't want)

Copy ssh key from /home/demo/.ssh/id_rsa.pub file and enter it in the submission box.



6. Now hit "Create Drolet " button. Your Droplet is ready to use.


After successful creation of droplet, you will get public IP address of your droplet which will be used for login into droplet.

Step 3: Login into virtual machine via ssh
Open terminal of your local machine and run


$ ssh root@<IP address of droplet>

Now you are in virtual machine. Lets start installation of OpenStack.

Step 4: Installation of OpenStack via Devstack
DevStack is a set of scripts and utilities to quickly deploy an OpenStack cloud. So lets start with devstack.

a. Since you are using fresh new Ubuntu machine, first update and upgrade it.


$ apt-get update
$ apt-get upgrade

b. Install Git, since installation of devstack, will require cloning of repository.


$ apt-get install git

c. Clone Devstack repository that contains a script to install dev OpenStack. Clone it, where you want to reside your devstack.

$ git clone https://github.com/openstack-dev/devstack.git

now move into devstack directory.


$ cd devstack

d. Create stack user. Since you are logged in a system as root user, you need to create stack user to start installation. For it there is a script in devstack repo located in tools/create-stack-user.sh. It will create stack user.


$ ./tools/create-stack-user.sh

now provide ownership to the stack user.


$ chown -R stack:stack .

e. Now modify stackrc file to collect all the git repository via https protocol. For it open stackrc file and find GIT_BASE and alter it.


$ vim stackrc
GIT_BASE=${GIT_BASE:-https://github.com}

Step 5. Now install murano as plugin for horizon
1. The contrib/devstack directory contains the files necessary to integrate Murano with Devstack.  Copy this integration scripts at their respective places.

a. First copy contrib/devstack/lib/murano file inside devstack/lib.
b. Copy contrib/devstack/lib/murano-dashboard file inside devstack/lib.
c. Copy contrib/devstack/extras.d/70-murano.sh file inside devstack/extras.d.

2. Now create a "localrc" file as input to devstack. This file contains all the necessary settings for murano. It starts Murano, Heat and Neutron services.


$ vim localrc

and paste following


# Enable Neutron
ENABLED_SERVICES+=,q-svc,q-agt,q-dhcp,q-l3,q-meta,neutron

# Enable Heat
enable_service heat h-api h-api-cfn h-api-cw h-eng

# Enable Murano
enable_service murano murano-api murano-engine  

3. Change user from root to stack (newly created one).


$ su stack

4. Install devstack via running stack.sh script.


$ ./stack.sh

It will prompt you for passwords for various components of OpenStack. After successfully running script, it will provide end point for horizon service of OpenStack. Bu using this end point you can explore OpenStack services. Now you have successfully installed Openstack with murano.

Enjoy developing with OpenStack and Murano!

Sunday 8 November 2015

Installation of Django in Virtual Environment

This post will lead you through successful installation of Django in Virtual Environment on Debian based system like Ubuntu. Here we will create virtual environment using most popular and recommended tool virtualenv and virtualwrapper.

What is Virtual Environment?
Virtual environment is a isolated Python environment that keeps python files in a isolation manner from system's python files and other virtual environment's python files.

Some important note about virtual environment: 
  • If you install any program using apt-get repository from virtual environment (created by virtualenv or virtualwrapper) then it will get install on whole system.
  • To install python package only inside virtual environment, use pip or easy_install like python package managers.

Why to install Django in virtual environment?
After installing Django you will create several projects using it. It may happen that your two projects have same dependency but requires different version. And on a particular system, you can have only single version of any file. Now what??
Solution is Virtual Environment. Python virtual environment solves this problem easily because virtual environment keeps the dependencies required by different projects in separate places. It keeps your global site-packages directory clean and manageable.

What is virtualenv?
Virtualenv is a tool to cretae isolated Python environments. virtualenv creates a folder which contains all the executables you installed inside the virtual environment.

Now, what is virtualwrapper?
virtualenvwrapper is just a wrapper utility around virtualenv that makes easy to deal with virtual environments. This post will cover working with virtualenv via virtualwrapper to provide ease.
virtualenvwrapper includes set of shell functions that are guaranteed to work in the following shells:
bash (Bourne again shell)
ksh (Korn shell)
zsh (Z shell)

Good news for windows lover, virtualwrapper also has window version that is virtual-wrapper-win.

Installation Procees 
1. Before any installation, it is a best practice to update our packages so run:

sudo apt-get update


2. We will install virtaulenv and virtualwrapper using pip (pyhton index package). Hence first you need to install pip. For it use following command:

sudo apt-get -y install python-pip


3. Install virtualenv:

pip install virtualenv


4. Install virtualwrapper:

pip install virtualenvwrapper


Now you have installed virtualenv and virtualwrapper tool. Now you need to do some congifugration setting. Lets walk through that.


Configuration of virtualwrapper

To use virtualwrapper, you need to add following two lines in your shell startup file, most probably .bash_profile or .bashrc. Lets do it. First open shell startup file using your faviourite editor and add:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

The first line instructs virtualenvwrapper where to store the virtualenvs that will be created by you. Here we are storing it in a folder called .virtualenvs inside your home folder. The second line runs the shell script to set up the virtualenvwrapper commands. It should point to the location where virtualenvwrapper is installed.

Now you have done with installation and configuration process. Its time to play with it. Here are some basic commands, you need to create and manage virtual environments:
  • mkvirtualenv – It is used to create a new virtual environment. Created new environment automatically becomes the active environment. 
  • rmvirtualenv – It is used to remove an existing virtual environment. The environment must be deactivated (explained below) before it can be removed. 
  • workon – It is used to activate a virtual environment. Will also list all existing virtual environments if no argument is passed. 
  • deactivate - used to deactivate the currently active virtual environment. Note that workon will automatically deactivate the current environment before activating a new one.

Django In Virtual environment

1. Lets create virtual enviroment first. So run:
mkvirtualenv test


2. Now tou are in virtual environment. You can identify it by seeing test in round bracket at left side of your terminal. Now install Djnago:
pip install django


Now you have successfully installed Django in virtual environment. Thankyou for reading.

Wednesday 28 January 2015

MongoDB

Hello everyone,
This post is about mongoDB database, its installation process and its implementation through python.

 MongoDB is a scalable, open source, high performance, document oriented database. It is an open source product and developed and supported by a company called 10gen. MongoDB is available under general public license for free and commercial license from the manufacture.

MongoDB falls into a class of databases called document oriented databases. Document oriented databases is a class that falls under the broader category called NoSQL databases. Overall databases can be classified as per following figure:

What is extra in NoSQL?
1. Query language
2. Fast performance
3. Horizontal scalability

What is missing in NoSQL?
1. No join supports.
2. No complex transactions support.
3. No constraints support (It is not applicable at database level but at application level)

Comparison between RDBMS and MongoDB:


S. No. RDBMS MongoDB
1. Storage format Data is stored in form of table. Example:
Fname Lname Dept.
Hasan Mir 20
Bill Ellison 10
Data is stored in form of collections or in BSON format which is similar to JSON format in java script. Example: {"_id" : ObjectId(2jk4fr5), "Fname" : "Hasan", "Lname" : "Mir", "Dept" : "20" }, {"_id" : ObjectId("2jk4fr7"), "Fname" : "Bill", "Lname" : "Ellison", }
2. Object and instance concept In RDBMS table is a object and each row is instance of that object. In MongoDB collection is a object and each document stored in collection is instance of that object.
3. Flexibility RDBMS is less flexible than NoSQL as: - Each row must have same no. of fields/key in a table (as above example). - Single field multiple attribute property is not supported easily. - Embedded data model or nested structure is not supported in RDBMS. MongoDB is more flexible than RDBMS as: - Each document can have different no. of key value pair (as above example). - Single field multiple attribute property is supported easily as multiple values can be stored for a key easily. Example: {"_id" : ObjectId("2jk4fr5"), "Fname" : "Hasan", "Project" : ["p1", "p2"], "Dept" : "20" } - Embedded data model (document inside the document) is supported in MongoDB. Example: {"_id" : "1234", "name" : "Hasan Mir", "Address" : [{"street" : "45", "City" : "Goa" }, {"street" : "78", "City" : "Dhule" }] }
4. Primary Key. It should be created by programmer explicitly. It is automatically generated if not mentioned by programmer and always denoted by key "_id".
5. Schema RDBMS is schema dependent. MongoDB is schema independent.
6. Horizontal scalability. Does not support. It supports.
7. Big data problem Does not capable to handle problem arise by data explosion. It is capable.
8. Information conversion Information is stored in form of relation hence when implemented with OOP languages data conversion is required. Information is stored in form of objects & its instances hence no conversion is required when implemented with OOP languages. This makes mongoDB faster.


Features of MongoDB:
1. It supports Ad hoc queries means it supports searches by field, range queries and regular expression searches.
2. Indexing is supported means any field in a document can be indexed.
3. Master-slave replication is supported. A master can perform read and write operation. A slave copies data from the master and can only be used for read or backup.
4. MongoDB can run over multiple servers and data is duplicated to give protection over hardware failure.
5. Automatic load balancing is built-in feature of mongoDB.
6. Horizontal scalability is most important feature of mongoDB. It means new systems can be added to existing database. Since performance is linearly proportional to no. of computers so it also increases performance.
7. Capped collection is supported means this type of collection maintains insertion order and, once the specified size is reached, behaves like a circular queue.
8. File storage system is supported by a special feature called GridFS.
9. Aggregation is supported through map reduce feature.
10. In query language java script function can be used which is a strongest feature.
11. It offers special support for locations since it understand longitude & latitude natively. 

Installation Process (For Ubuntu):
1. Download the MongoDB setup from the following link:
2. To install the mongoDB:
    Open the terminal (ctrl+Alt+t) and run the following commands (one by one). 
    
a. Import the public key used by the package management system:
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

b. Create a list file for MongoDB:
    echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list

c. Reload local package database:
    sudo apt-get update
  
d. Install the MongoDB packages:
(i) To install the stable version of mongoDB:
    sudo apt-get install mongodb-org

(ii) To install the specific version of mongoDB (e.g. 2.6.1 version):
 apt-get install mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1

Run MongoDB:

To start mongoDB issue the following command on terminal:

sudo service mongod start

(mongod is the primary daemon process for the MongoDB system. It handles data requests, manages data format, and performs background management operations.)

To stop mongoDB:

sudo service mongod stop

MongoDB Implementation through python:

1: Install pymongo library. Then import it through following code to connect to the mongoDB.
    from pymongo import MongoClient
2: Set the connection string. Format for the connection string is MongoClient(“<Port address>”, “<port no.>”)
connection = MongoClient("localhost, 27017")
3: Now connect your database name and the collection name to mongoDB through above connection variable and store it in another variable for convenience. Here db variable is used. Students is the name of database and mva is the name of collection.
    db = connection.students.mca
4: Create document through following code:
    db.insert({'name':student_name,'grade':student_grade})
5: Delete the document through following code. It will delete the document           where name is equal to ‘a’.
   db.remove({'name': a})
6. Update the document through following instruction. It update the document where name is equal to ‘a’ by setting its grade value to ‘A++.’
   db.update({'name':'a'}, {'$set': {'grade':'A++'}})
7. View the document as follow:
(i) To view the single document from the collection use following instruction. It will print the first document from the collection. TO view the specific document condition can be provided I the round braces as in the remove instruction.
   print db.find_one()
(ii) To view all documents present in the collection use following instruction.
   db.find()