Getting Started with KEMP Python SDK

Posted on

KEMP Technologies Python SDK

One of our goals at KEMP is to help our customers move faster. The LoadMaster provides a user-friendly web interface and a REST API to aid in this ideal. In order to make development on top of our REST API easier, KEMP offers a Python SDK that is constantly improving. If you’re interested in using the Python SDK for automation, the following “hello world” walkthrough will help you get setup and running quickly.

Requirements

To get started using the Python SDK you’ll need the following:

  • Python > 2.7 or 3.4
  • Pip
  • Virtualenv (Linux / Mac OSX, optional)
  • A development environment that can connect to your LoadMaster’s administrative IP address
  • A LoadMaster with the “Enable API Interface” option enabled

To enable your LoadMaster’s API interface Login to the WUI, go to: Certificates & Security – Remote Access – Enable API Interface

Screenshot of LoadMaster 7.2.36.2 WUI

Getting setup: Linux / Mac OSX

This tutorial expects users of Linux and Mac OSX to be capable of installing python, pip and virtualenv without assistance. Create the directory `kemp_python_demo` and change your current working directory to it. Next, run the following commands:

~/kemp_python_demo $: virtualenv .
~/kemp_python_demo $: source bin/activate
~/kemp_python_demo $: pip install python-kemptech-api

Run the following command to confirm that your environment is setup and the library is installed correctly:

~/kemp_python_demo $: python -c "import python_kemptech_api; print(type(python_kemptech_api))"

This should result in the following output:

<class 'module'>

Demonstration

 

Getting setup: Windows

At the time of this blog post the newest stable version of Python for Windows is Python 3.6 which you can download here. This tutorial expects you’ve downloaded the “Windows x86-64 executable installer.” Once you’ve downloaded the installer, run it and check the “Add Python 3.6 to PATH” checkbox.2

When the installation is complete go to: Start – Run – cmd. Next, create a directory `kemp_python_demo` and change your current working directory to it. Example:

C:\Users\User_Name> mkdir kemp_python_demo
C:\Users\User_Name>cd kemp_python_demo
C:\Users\User_Name\kemp_python_demo>

Once the directory is created and your prompt is set to work from that directory run:

C:\Users\User_Name\kemp_python_demo> pip install python_kemptech_api

pip should successfully install the python_kemptech_api library.

Run the following command to confirm that your environment is setup and the library is installed correctly:

C:\Users\User_Name\kemp_python_demo> python -c "import python_kemptech_api; print(type(python_kemptech_api))"

This should result in the following output:

<class 'module'>

Code Snippet

At this point our environmental installation is complete. Let’s create a script that lists all the Virtual Services that are in the LoadMaster. Open up your favorite text editor or IDE and paste the following block. Make sure that the code snippet maintains its tabbing and edit the appropriate variables.

# -*- coding: UTF-8 -*-
from python_kemptech_api import LoadMaster as loadmaster
LoadMaster_IP = "" # Your LoadMaster’s administrative IP
# Note: To improve security, avoid using plaintext login and passwords and consider using environmental variables instead.
LoadMaster_User = "" # Your LoadMaster’s Login User
LoadMaster_Password = "" # Your LoadMaster’s User’s Password
LoadMaster_Port = "443" # By default this is 443.
lm = loadmaster(LoadMaster_IP, LoadMaster_User, LoadMaster_Password, LoadMaster_Port)
virtual_services = lm.get_virtual_services()
for each_virtual_service in virtual_services:

print(each_virtual_service)

Running the code in Linux / Mac OSX

Save the file as `”demo.py”` and run:

~/kemp_python_demo $: python demo.py

If everything worked correctly you should see the script output something like:

Virtual Service TCP 192.168.1.4:80 on LoadMaster 192.168.1.3

Running the code in Windows

Save the file as `”demo.py”` and run:

C:\Users\User_Name\kemp_python_demo> python demo.py

If everything worked correctly you should see the script output something like:

Virtual Service TCP 192.168.1.4:80 on LoadMaster 192.168.1.3

Updating the SDK library

If you’re interested in keeping up to date with the KEMP Python SDK you can run

pip install python-kemptech-api --upgrade

To upgrade the library using python’s pip package manager.

Viewing new changes

The KEMP Python SDK can be downloaded as a tar.gz file by visiting https://pypi.python.org/pypi/python-kemptech-api/. In this package is a CHANGES.rst file that contains a list of new changes to the project.

Congratulations. You’ve successfully created your first Python script for your LoadMaster. The Python SDK has numerous features and functions that make automating the LoadMaster easy and fast. Continue to read the KEMP Technologies blog for more how-tos and demo scripts in the future.

Posted on

Kemp Technologies

Kemp Technologies