Getting Started

Set Up A Python Environment

Install python from the python website or using your favorate package manager. We support versions of python supported by the python organization.

We recommend using poetry to make python development much easier. You can get poetry from the poetry website.

During setup poetry will be ask several questions about your project but your answers to these are not very important right now. Create a folder. In that folder, run the following command.

poetry init --python "python^3.6" --dependency "netlab" --dev-dependency "mypy^0.812"

Python will require you to be in this folder’s environment. You can run poetry shell to change your environment in your current commandline. You will need to enter the python environment every time you open a new terminal.

Configuration

Before starting, you must configure a Netlab system. Make sure you are in a python environment by using poetry shell. Then you can run netlab config add, which will walk you through the process of configuring this tool to connect to a Netlab.

For additional configuration, see netlab.config.

First Netlab Command

Create a file named ‘main.py’ with the following content:

import asyncio
from pprint import pprint
from netlab.async_client import NetlabClient


async def main():
    async with NetlabClient() as connection:
        info = await connection.system_status_get()
        pprint(info)

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

Remember to make sure you are in the python environment using poetry shell, then run python main.py. You should see output that looks like:

{'cpu_n': '2',
 'hostname': 'ndg-ve-dev-jj-015.netdevgroup.com',
 'sys_lic_exp_date': None,
 'sys_lic_op_state': 'ACTIVE',
 'sys_logins_enabled': True,
 'sys_maint_ends': None,
 'sys_mode': 'NORMAL',
 'sys_name': '',
 'sys_product_id': 'VE',
 'sys_sdn_release_date': datetime.date(2016, 4, 1),
 'sys_sdn_release_type': 'alpha',
 'sys_sdn_version': '21.1.2',
 'sys_serial': 'NDG-VE-E3BE-5FF2-7579-5E55',
 'uptime_sec': Decimal('1720907.59')}

You can check your program before running it by using the mypy tool. Run mypy main.py check the file we just created. You can use mypy to find errors before you ever need to run your program.

See netlab.api for a complete list of netlab commands. See netlab.async_client.NetlabClient for additional info on working with the Netlab SDK.