White Papers

Configuration details
57 Dell Storage Manager REST API Cookbook | 3089-WP-SAN
5 Sample script
This section presents the various components of the Storage Center REST API discussed in previous
sections and assembles it into a cohesive, functional, and complete sample script. This sample script is
annotated to explain statements or sections as needed.
Additional code can be injected into this complete sample script where denoted by the placeholder:
"===== YOUR CODE GOES HERE =====".
The following assumptions are made regarding the code:
Assumes a true or successful condition (return code) from each requested REST API call
Contains minimal error trapping and management to promote readability and understanding
Creates the data structures required to facilitate passing the data between REST API calls
#
# main.py
#
# import modules into Python script
import os, sys, subprocess, math
sys.path.append("/usr/lib64/python2.6/site-packages")
sys.path.append("/usr/local/lib/python2.7/site-packages")
import requests, json, http, httplib, urllib, urllib2
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')
def stdout_inspect(input, how_many):
for i in range(how_many):
for key in input[i]:
print ("%-25s: %s") % (key, input[i][key])
print("")
if __name__ == '__main__':
# define env incl. DSM IP addr, port & login credentials
DSM_ip = '<nnn.nnn.nnn.nnn>' # IP address of DSM instance
DSM_port = '3033' # Default port of DSM instance
DSM_id = '<Username>' # Login credentials for DSM
DSM_pass = '<Password>' # Password
verify_cert = False # Default = False