Creating a simple netmiko Django app, part I

January 31, 2018

I am currently teaching myself Django and in an attempt to cement my knowledge I am running through the setup of a super simple app. The app will connect and extract information from a network device and I will use that data to present it on a web page using Django.

I have spun up a virtual machine in GCP running Ubuntu 16.04 LTS.

The plan

Below is the overall steps to complete this tiny project.

Install virtualenv

Virtualenv is used to create a separate python environment for your app. This enables you to install whatever you want without having to think about dependencies and requirements of other apps running on the same machine.

sudo apt install virtualenv

After installing it, create your virtual environment:

martin_rodvand@netmiko:~$ virtualenv -p python3 django-netmiko
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/martin_rodvand/django-netmiko/bin/python3
Also creating executable in /home/martin_rodvand/django-netmiko/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.

Activate the environment (in the django-netmiko folder):

source bin/activate

You will notice the prompt adding a (django-netmiko) in front to indicate that the virtual environment is active.

Install Django and netmiko

Now that I have the virtual environment up and running I can start to install the essential stuff.

Let me start with Django:

(django-netmiko) martin_rodvand@netmiko:~/django-netmiko$ pip3 install django
Collecting django
Downloading Django-2.0.2-py3-none-any.whl (7.1MB)
100% |████████████████████████████████| 7.1MB 209kB/s
Collecting pytz (from django)
Downloading pytz-2017.3-py2.py3-none-any.whl (511kB)
100% |████████████████████████████████| 512kB 2.9MB/s
Installing collected packages: pytz, django
Successfully installed django-2.0.2 pytz-2017.3

That was simple enough, now I can verify that it’s accessible:

(django-netmiko) martin_rodvand@netmiko:~/django-netmiko$ python3 -m django version
2.0.2

Perfect! On to netmiko:

(django-netmiko) martin_rodvand@netmiko:~/django-netmiko$ pip3 install netmiko

To verify:

(django-netmiko) martin_rodvand@netmiko:~/django-netmiko$ python
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import netmiko

With these two components installed the next step will be to create the Django project and app! Stay tuned!

659