1 __author__ = "Basheeruddin Ahmed"
2 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
3 __license__ = "New-style BSD"
4 __email__ = "syedbahm@cisco.com"
8 from urllib import request
15 #Helps in making GET REST calls
18 def get(url, userId, password):
21 headers['Accept']= 'application/xml'
23 # Send the GET request
24 req = urllib.request.Request(url, None, headers)
27 return urllib.request.urlopen(req).read()
30 #Helps in making POST REST calls without outputs
32 def nonprintpost(url, userId, password,data):
35 headers['Content-Type'] = 'application/json'
36 #headers['Accept']= 'application/xml'
38 resp = requests.post(url,data.encode(),headers=headers)
44 #Helps in making POST REST calls
46 def post(url, userId, password,data):
47 print("post request with url "+url)
48 print("post request with data "+data)
50 headers['Content-Type'] = 'application/json'
51 #headers['Accept']= 'application/xml'
53 resp = requests.post(url,data.encode(),headers=headers)
55 #print (resp.raise_for_status())
61 #Helps in making DELET REST calls
63 def delete(url,userId,password):
64 print("delete all resources belonging to url"+url)
65 resp=requests.delete(url)