Pages

Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Sunday, February 8, 2015

VIRTUALENV in Python

virtualenv is a tool to create isolated virtual environments or sandboxes. One project written 2.7 does not affect the other project written in 3.4. Both can reside on the same machine without creating conflict.

Installation commands in Ubuntu:

#Get the installation file
sandesh@sandesh:~$wget https://pypi.python.org/packages/source/v/virtualenv/virtualenv-12.0.7.tar.gz

#the virtualenv zipped file will be downloaded

sandesh@sandesh:~$tar -xvzf virtualenv-12.0.7.tar.gz
sandesh@sandesh:~$cd virtualenv-12.0.7

#install virtualenv
sandesh@sandesh:~/virtualenv-12.0.7$python virtualenv.py myenv

#a new folder called myenv will be created

Use virtualenv in Ubuntu:


# this runs the activate file inside the bin folder
sandesh@sandesh:~/virtualenv-12.0.7$source myenv/bin/activate

#myenv is the name of the virtual environment I created above.

#To install any package inside this virutal environment we execute the following command.
(myenv)sandesh@sandesh:~/virtualenv-12.0.7$pip install django
Collecting django
  Using cached Django-1.7.4-py2.py3-none-any.whl
Installing collected packages: django

Successfully installed django-1.7.4

#we can check what packages are installed inside the virtualenv using following command.
(myenv)sandesh@sandesh:~/virtualenv-12.0.7$ pip freeze
Django==1.7.4

#to get out of the virtualenv

(myenv)sandesh@sandesh:~/virtualenv-12.0.7$ deactivate

sandesh@sandesh-S400CA:~/virtualenv-12.0.7$




Sunday, December 14, 2014

Custom topologies in Mininet : With and without the mn script

There are two ways to run custom mininet topologies.

Without the mn script:

One is without the mn script in the command line. In this case, we simply run the file just as we run a python file. If the custom topology is in a file named mytopo.py, the file should be run as follows.

mininet@mininet-vm:~$ sudo python mytopo.py

With the mn script:

 In this case, the topology named should be given the command line.

For eg.: If there is a custom topology in a python file named 'mytopo.py', there should be a line like below in the file.

topos = { 'mytopo': ( lambda: MyTopo() ) }

topos is a dictionary which stores a custom name as a key and the class name as the value.The name 'mytopo' here can be any name you want to give.It need NOT be same as the filename  MyTopo() is the class name that we have defined in the custom topology which is a sub-class of Topo class that needs to be imported as follows

from mininet.topo import Topo

The above file can be run as follows:

mininet@mininet-vm:~$ sudo mn --custom ~/mininet/custom/mytopo.py --topo mytopo --mac

Here mytopo is the key defined in topos dictionary and ~/mininet.custom/mytopo.py is the file location of the file.