---
title: Silver Peak SD-WAN Python Library
description: An area of interest of mine is around network automation so I like to use Python wherever possible. SD-WAN inherently has some form of automation around its platform as there is an overarching orchest
---

[Axians UK News and Insights](https://axiansuk.co.uk/blog)

# [Silver Peak SD-WAN Python Library](https://axiansuk.co.uk/blog/2019/04/11/silver-peak-sd-wan-python-library)

 Written by [Axians UK](https://axiansuk.co.uk/blog/author/axiansuk) | Apr 11, 2019 11:12:59 AM

Guest Blog from Axians Alex Gittings:[see original post on his blog](http://blog.alexgittings.com/silver-peak-python-library/)

A large part of the work I do is around the Silver Peak SD-WAN offering that [Axians](https://www.axians.co.uk/) offers its customers. An area of interest of mine is around network automation so I like to use Python wherever possible. SD-WAN inherently has some form of automation around its platform as there is an overarching orchestrator that manages all Silver Peak devices. However, when I do things I like to find programmatic ways of manipulating devices.

Silver Peak SD-WAN platforms offer a comprehensive REST API to manipulate their software using multiple methods.

To leverage these API's within Python natively, the code would have to handle logging in and then proceeding to call the required API to get or post information.

For example this Python snippet will show how to login and get the active alarms from the Orchestrator with native code, it will then output the data to a nice easy to read table.

```
import requests
import urllib3
from tabulate import tabulate
# Silence the insecure warning due to SSL Certificate urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# credentials username = "admin" password = "admin"
login_url = 'https://192.168.33.2:443/gms/rest/authentication/login' get_alarms = 'https://192.168.33.2:443/gms/rest/alarm/gms?view=active'
requestData = { "user": username, "password": password }
# start session s = requests.Session()
# login r = s.post(login_url, json=requestData, headers={'Content-Type': 'application/json'}, verify=False)
# print response from logging in print(r.text)
# request active alarms alarms = s.get(get_alarms, verify=False, headers = {'Content-Type': 'application/json'}, cookies=r.cookies)
# display the alarms in a nice table print("Active Alarms:") headers = ["ID", "Severity", "Name", "Source", "Service Affect"] table = list()
for item in alarms.json(): tr = [item['id'], item['severity'], item['name'], item['source'], item['serviceAffect']] table. append(tr)
```

## Output:

```
PS C:\Users\Alexander.Gittings\code\silverpeak> python.exe .\basic.py
successfully logged in
Active Alarms:
╒══════╤════════════╤══════════════════════════╤═════════════╤══════════════════╕
│   ID │ Severity   │ Name                     │ Source      │ Service Affect   │
╞══════╪════════════╪══════════════════════════╪═════════════╪══════════════════╡
│  107 │ MAJOR      │ SMTP_DEFAULT_NOT_CHANGED │ /email/smtp │ False            │
╘══════╧════════════╧══════════════════════════╧═════════════╧══════════════════╛
```

However, myself and [Adam](http://adjarvis.com/) set out to build a Python package to leverage the Silver Peak API's in a much easier fashion. The source code code can be seen on my Github here: [SilverPeak\_Python](https://github.com/minitriga/silverpeak_python).

### To install this package you can leverage PyPI:

```
pip install silverpeak
```

The package can then be imported into your python script using `from silverpeak import *`

## Creating a session is as easy as:

```
sp = Silverpeak(user="admin", user_pass="admin", sp_server="192.168.33.2", disable_warnings=True)
```

You can then leverage "sp" to call multiple modules that are currently implemented in the Python package:

- get\_appliances()
- get\_appliance()
- get\_reach\_app()
- get\_reach\_gms()
- get\_groups()
- get\_group()
- get\_group\_root()
- get\_grnodes()
- get\_grnode()
- get\_discovered()
- get\_approved()
- get\_denied()
- get\_interfaces()
- get\_device\_alarms()
- get\_alarms()
- get\_alarm\_summary()
- get\_alarm\_summary\_type()
- post\_preconfig()

### Example of get\_alarms:

`alarms = sp.get_alarms(view='active')`  
Most of these modules allow the user to input data, in this example the user can select what alarms to view: all, active, closed.

This will call the alarms API within the Orchestrator and return a tuple containing valuable information:

```
print(alarms)
```

#### The full code looks like the following including a fancy table for the output:

```
from silverpeak import *
from tabulate import tabulate
# login sp = Silverpeak(user="admin", user_pass="admin", sp_server="192.168.33.2", disable_warnings=True)
print("Active Alarms") headers = ["ID", "Severity", "Name", "Source", "Service Affect"] table = list()
# get active alarms alarms = sp.get_alarms(view='active')
# display the alarms in a nice table for item in alarms.data: tr = [item['id'], item['severity'], item['name'], item['source'], item['serviceAffect']] table. append(tr)
```

## Output:

```
PS C:\Users\Alexander.Gittings\code\silverpeak> python.exe .\package.py
Active Alarms:
╒══════╤════════════╤══════════════════════════╤═════════════╤══════════════════╕
│   ID │ Severity   │ Name                     │ Source      │ Service Affect   │
╞══════╪════════════╪══════════════════════════╪═════════════╪══════════════════╡
│  107 │ MAJOR      │ SMTP_DEFAULT_NOT_CHANGED │ /email/smtp │ False            │
╘══════╧════════════╧══════════════════════════╧═════════════╧══════════════════╛
```

I will update[my blog](http://blog.alexgittings.com/silver-peak-python-library/) with more examples of leveraging this Python module to manipulate the Silver Peak orchestrator.

[View full post](https://axiansuk.co.uk/blog/2019/04/11/silver-peak-sd-wan-python-library)

```json
{
  "@context" : "http://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Axians UK"
  },
  "dateModified" : "2020-08-19T08:52:58.409Z",
  "datePublished" : "2019-04-11T11:12:59Z",
  "headline" : "Silver Peak SD-WAN Python Library",
  "image" : {
    "@type" : "ImageObject",
    "height" : 902,
    "url" : "https://f.hubspotusercontent10.net/hubfs/7401012/Imported_Blog_Media/photo-1535551951406-a19828b0a76b.jpg",
    "width" : 1346
  },
  "mainEntityOfPage" : "https://axiansuk.co.uk/blog/2019/04/11/silver-peak-sd-wan-python-library",
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "height" : 60,
      "url" : "/hs/hsstatic/content_shared_assets/static-1.4092/img/default-amp-logo.png",
      "width" : 60
    },
    "name" : "Axians UK Blog "
  }
}
```