1 __author__ = "Basheeruddin Ahmed"
2 __copyright__ = "Copyright(c) 2014, Cisco Systems, Inc."
3 __license__ = "New-style BSD"
4 __email__ = "syedbahm@cisco.com"
8 from SSHLibrary import SSHLibrary
11 #Helps in making GET REST calls
14 def get(url, userId, password):
17 headers['Accept']= 'application/xml'
19 # Send the GET request
20 req = requests.get(url, params=None, headers=headers)
26 #Helps in making POST REST calls without outputs
28 def nonprintpost(url, userId, password,data):
31 headers['Content-Type'] = 'application/json'
32 #headers['Accept']= 'application/xml'
34 resp = requests.post(url,data.encode(),headers=headers)
40 #Helps in making POST REST calls
42 def post(url, userId, password,data):
43 print("post request with url "+url)
44 print("post request with data "+data)
46 headers['Content-Type'] = 'application/json'
47 #headers['Accept']= 'application/xml'
49 resp = requests.post(url,data.encode(),headers=headers)
51 #print (resp.raise_for_status())
57 #Helps in making DELET REST calls
59 def delete(url,userId,password):
60 print("delete all resources belonging to url"+url)
61 resp=requests.delete(url)
64 # use username and password of controller server for ssh and need
65 # karaf distribution location like /root/Documents/dist
67 def execute_ssh_command(ip, username, password, command):
68 print "executing ssh command"
70 lib.open_connection(ip)
71 lib.login(username=username,password=password)
73 lib.execute_command(command)
74 print "command executed : " + command
75 lib.close_connection()
77 def startcontroller(ip,username,password,karafhome):
78 execute_ssh_command(ip, username, password, karafhome+"/bin/start")
80 def stopcontroller(ip,username,password,karafhome):
81 execute_ssh_command(ip, username, password, karafhome+"/bin/stop")
83 def clean_journal(ip, username, password, karafHome):
84 execute_ssh_command(ip, username, password, "rm -rf " + karafHome + "/journal")
86 def kill_controller(ip, username, password, karafHome):
87 execute_ssh_command(ip, username, password, "ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
91 if __name__ != "__main__":
92 _cache = robot.utils.ConnectionCache('No sessions created')
93 # here create one session for each HTTP functions
94 _cache.register(requests.session(), alias='CLUSTERING_GET')
95 _cache.register(requests.session(),alias='CLUSTERING_POST')
96 _cache.register(requests.session(),alias='CLUSTERING_DELETE')