White Papers
Example scripts
40 Dell EMC SC Series: VMware Site Recovery Manager Best Practices | 2007-M-BP-V
A Example scripts
A.1 REST API script: TakeSnapshot.py
This is an example REST API script that can be folded into an SRM recovery plan. It leverages the Dell
RESTful API to take a snapshot (replay) of the source replication system volume to make sure that the most
current snapshot is replicated to the DR site.
#
# main.py
#
# import modules into Python script
import requests, json, http, httplib, urllib, urllib2
import os, sys, subprocess, math
import math, time
import logging
from simplejson import scanner
# setup logging to scapi.log
logging.basicConfig(level=logging.DEBUG, filename='scapi.log',
format='[%(asctime)s] %(levelname)s %(message)s')
if __name__ == '__main__':
# define env incl. DSM IP addr, port & login credentials
DSM_ip = '192.168.1.10' # IP address of DSM instance
DSM_port = '3033' # Default port of DSM instance
DSM_id = 'Admin' # Login credentials for DSM
DSM_pass = 'mmm' # Password
verify_cert = False # Default = False
apiversion = '2.0' # Default = 2.0
# disable warnings from requests module
if not verify_cert:
requests.packages.urllib3.disable_warnings()
# define base URL for DSM REST API interface
baseURL = 'https://%s:%s/api/rest/' % (DSM_ip, DSM_port)
# define HTTP content headers
header = {}
header['Content-Type'] = 'application/json; charset=utf-8'
header['Accept'] = 'application/json'
header['x-dell-api-version'] = apiversion
# define the connection session
connection = requests.Session()
connection.auth = (DSM_id, DSM_pass)