Learning Lab: How to set up your computer

Git Repository

The code is hosted in a Git Repository:

https://devhub.cisco.com/sf/projects/cosc_learning_labs/

(You will be re-directed to the login page if you are not already logged in to that website.)

Git Clone

You need to perform a git clone of the code from the Git Repository. This can be done in a command shell, as shown below. Alternatively, there are other ways of achieving this. For example, an IDE, such as Eclipse, can do this for you.

Command Line

From the command line of a shell, the clone is performed by a single command:

git clone ssh://<you>@gerrit-open1.cisco.com:29418/cosc-learning-labs

where <you> is your username as registered with the website. This will create directory

cosc-learning-labs

in the current directory.

The convention is for the current directory to be named git, but that is your choice.

Download Git

If you need to download the git command, visit this website:

http://git-scm.com/downloads

Change Directory

Change the current directory to the sub-directory:

cosc-learning-labs/src/learning_lab

The shell command is usually either:

cd cosc-learning-labs/src/learning_lab

or

cd cosc-learning-labs\src\learning_lab

Python

You need Python to be available. To download Python, visit website:

Due to the popularity of Python, many operating systems have pre-packaged it.
For Ubuntu, Python can be installed using apt-get:

sudo apt-get install python

For OSX, visit website:

Python Version

The Python website offers two major versions of Python: 3.x.x and 2.x.x. The version of Python employed by this Learning Lab is revealed by the following command:


In [6]:
import sys

print(sys.version)


2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2]

The command above was run inside an IPython Notebook. In a command line shell use:

python --version

3rd Party Libraries

The following Python libraries are required:

  • lxml
  • requests

The command to install a Python library is usually:

pip install <library>

or

easy_install <library>

You will probably need to prefix these commands with sudo on a Linux OS. For example:

sudo pip install lxml

Python Interactive Shell

The conventional Python interactive shell is entered with the command:

python

The response will be something like:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

The

>>>

is the prompt to enter Python code, for example:

>>> print('Hello, World!')
Hello, World!
>>>

Verify 3rd Party Libraries

To verify that the 3rd party libraries are available, we import them into the Python Interactive Shell.


In [7]:
import lxml
import requests

Enter the name of an imported module to see a description of it...


In [8]:
lxml


Out[8]:
<module 'lxml' from '/usr/lib/python2.7/dist-packages/lxml/__init__.pyc'>

In [9]:
requests


Out[9]:
<module 'requests' from '/usr/lib/python2.7/dist-packages/requests/__init__.pyc'>

PyDev Eclipse Plugin

There is a plug-in for Eclipse IDE, named PyDev, that offers a Python Interactive Shell in the Console view. You can this as an alternative to the Python Interactive Shell, described above.

When the PyDev Console is opened, you will see something similar to:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
Type "copyright", "credits" or "license" for more information.

IPython 2.3.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

PyDev -- Python IDE for Eclipse
For help on using PyDev's Console see http://pydev.org/manual_adv_interactive_console.html
PyDev console: using IPython 2.3.1
>>>
/usr/bin/python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2]
>>>

Note the familiar prompt where you can enter Python code.

>>>

The update site for PyDev is http://pydev.sf.net/updates/

Jupyter/IPython

PyDev for Eclipse, as shown above, uses IPython. Jupyter is the new name for IPython. The installation web page is http://ipython.org/install.html.

All the web pages for this Learning Lab are available as IPython Notebooks.

Assuming that your current directory is:

learning_lab

as per the instructions above, you can list the IPython Notebooks:


In [10]:
ls *.ipynb


01_device_connected.ipynb     Configure.ipynb
01_device_dismount.ipynb      Copyright.ipynb
01_device_mounted.ipynb       Dashboard.ipynb
01_device_dismount.ipynb   HowToSetUpYourComputer.ipynb
01_inventory.ipynb            Http.ipynb
01_inventory_json.ipynb       Interface.ipynb
01_inventory_mount.ipynb  Inventory.ipynb
01_inventory_mounted.ipynb    Menu.ipynb
01_inventory_mount.ipynb      Objectives.ipynb
02_interface_names.ipynb      Properties.ipynb
AccessControl.ipynb           QuickStartCurl.ipynb
Capabilities.ipynb            Settings.ipynb

To use these Notebooks, start IPython with the command:

ipython notebook

and it will open a web page that offers you a list of hyper-links to the Notebooks, including the document you are currently reading!

The advantage of IPython Notebooks is that they already contain the Python sample code, sparing you the chore of typing it yourself, or repetitive copy-and-paste.

Import Learning Lab

The final step is to import the Learning Lab module into your Python Interactive Shell.


In [11]:
import learning_lab

To confirm that the module is imported, use the 'help' command to describe the module:


In [12]:
help(learning_lab)


Help on package learning_lab:

NAME
    learning_lab

FILE
    /home/virl/git/cosc-learning-labs/src/learning_lab/__init__.py

PACKAGE CONTENTS
    00_controller
    00_devices
    00_settings
    01_device_connected
    01_device_dismount
    01_device_mounted
    01_inventory
    01_inventory_connected
    01_device_dismount
    01_inventory_integrity
    01_inventory_json
    01_inventory_mount
    01_inventory_mount
    01_inventory_mounted
    01_inventory_not_connected
    01_inventory_summary
    01_inventory_summary_html
    01_inventory_unmounted
    01_inventory_unreachable
    02_capability
    02_interface_names
    03_interface_configuration
    03_interface_configuration_update
    03_interface_properties
    03_interface_shutdown
    03_interface_startup
    04_routes
    04_topology
    05_access_group_toggle
    05_access_list_toggle
    05_acl_delete
    05_acl_detail
    05_acl_list
    05_port_deny
    05_port_permit
    05_unapply
    giles

FUNCTIONS
    doc(script)
    
    main(script)