This article provides a brief overview of the KEMP Python API SDK and answers some common questions, will review how to manage KEMP Virtual Loadmaster for Azure using Python. You can refer to other articles in this library for more detailed information on the different topics. Also, will assume we are working on Windows platform.
KEMP Technologies offers a Python SDK which provides a way for users to automate the manual, long-running, error-prone, and frequently repeated tasks that are commonly performed in a cloud environment within the KEMP Virtual Loadmaster for Azure. It saves time and increases the reliability of regular administrative tasks and even schedules them to be automatically performed at regular intervals.
- Python 3.6 which you can download here.
- Visual Studio Code: download here
- Install Python Extension for Visual Studio Code
Automating processes with KEMP Python API SDK
The KEMP Python API SDK gives you a set of tasks that perform some automated process for your Virtual Loadmaster. It may be a simple process such as starting a virtual loadmaster and creating a log entry, or you may have to perform a complex process across multiple resources or even multiple environments such as cloud and on premise environments.
For example, you might have an existing manual process for getting a log of your Real Servers Healtcheck or simply get the list of your current virtual services configured in your KEMP Loadmaster.
Install KEMP Python API
- Install the Python Kemp Package – this article assumes you already installed python
- Install pylint using Visual Studio Code
- Install travis-sphinx from console
- Install sphinx rth theme from console
Please be sure to setup this configuration on your Virtual Loadmaster for Azure:
- Certificates & Security -> Remote Access-> Enable API - Certificates & Security -> Remote Access-> Allow Multiple Interface Access - Certificates & Security -> Admin WUI Access -> Enable session management - Certificates & Security -> Admin WUI Access -> Unchecked "Require Basic Authentication"
This example shows the list of all virtual services running on our Virtual Loadmaster for Azure:
Get your Loadmaster current version:
All the commands in the article require the credentials of the loadmaster. Replace the value of top variables with the your loadmaster credentials. Create the variables.
# -*- coding: UTF-8 -*- import requests import json import sys import time from python_kemptech_api import LoadMaster as loadmaster # Assign static IP on Azure (DNS Name optional) loadmaster_ip = "192.168.1.20" # Your LoadMaster administrative IP # Note: To improve security, avoid using plaintext login and passwords and consider using environmental variables instead. loadmaster_login = "bal" # Your LoadMaster user login loadmaster_password = "" # Your LoadMaster user password loadmaster_port = "443" # By default this is 443. kemp_id= "firstname.lastname@example.org" kemp_id_password = "" lm = loadmaster(loadmaster_ip, loadmaster_login, loadmaster_password, loadmaster_port) # Specify the Virtual Service and Real Server IDs here: virtual_service_id = 0 real_server_id = 0 #get Loadmaster version print("Your Loadmaster Version is:") print(lm['version'])
List all virtual services configured on your Loadmaster:
List all the current virtual services configured on your Loadmaster and export them into a json file:
virtual_services = lm.get_virtual_services() virtual_service_list =  for x in virtual_services: print(str(x)) virtual_service_list.append(str(x)) # Print Virtual service list print(virtual_service_list) with open('virtual_service_list.json', 'w') as outfile: json.dump(virtual_service_list, outfile)
Shutdown your Loadmaster:
The KEMP API also allows you to automate some easy common functions, such as reboot and shutdown the loadmaster:
try: lm.shutdown() except ValueError: lm.reboot()
- Learn how to use KEMP API using Linux / MacOS: https://kemptechnologies.com/blog/getting-started-kemp-python-sdk/
- Take advantage of the current examples available at the github repository: https://github.com/KEMPtechnologies/python-kemptech-api/tree/master/examples