Usecase Backup

With the new REST API it is now possible to create and download savepoints of configurations automatically. To achieve this we are going to use the saveApplianceConfiguration and downloadApplianceConfiguration methods.

First we will call the saveApplianceConfiguration method, which will create a new savepoint on the server and return the name of the savepoint upon success.

In the second step we will then call the downloadApplianceConfiguration method with the filename we just received as a parameter to download the configuration file to our local computer.

The two scripts below automate the task of downloading a configuration savepoint using the two API functions we just discussed. In both scripts it is assumed that the IP address of the instance we want to backup is ME_IP and our API Key is API_KEY.

Python 2.7:

import requests
  
API_KEY = 'username;somehexcode'
URL = 'https://'+ ME_IP  +'/me/'
HEADERS = {'X-Api-Key': API_KEY}
  
resp = requests.get(URL+'saveApplianceConfiguration', headers=HEADERS)
remote_cfg = None
 
if resp.status_code == 200:
   data = resp.json()
   remote_cfg = data['name']
else:
    print('Unexpected status code: ' + str(resp.status_code))
    exit()
  
resp = requests.get(URL+'downloadApplianceConfiguration',
                    headers=HEADERS,
                    params={"name": remote_cfg})
  
if resp.status_code == 200:
    with open(remote_cfg, 'w') as f:
       f.write(resp.text)
else:
    print('Unexpected status code: ' + str(resp.status_code))
  

Even less code is required when Bash scripting is used. The Bash scripting example uses the curl command to call the REST API.

#!/usr/bin/env bash
  
API_KEY="X-Api-Key: username;somehexcode"
URL="https://ME_IP/me/"
SAVE_URL="${URL}saveApplianceConfiguration"
DOWNLOAD_URL="${URL}downloadApplianceConfiguration"
  
remote_cfg=$(curl -k -s -X GET -H"${API_KEY}" $SAVE_URL | grep -Po 'Palladion\-configuration.*\.cfg')
  
curl -k -s -H "${API_KEY}" -d"name=${remote_cfg}" -o ${remote_cfg} $DOWNLOAD_URL