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
15 #Helps in making GET REST calls
18 def get(url, userId=None, password=None):
21 headers['Accept']= 'application/xml'
23 # Send the GET request
24 session = _cache.switch("CLUSTERING_GET")
25 resp = session.get(url,headers=headers)
31 #Helps in making POST REST calls without outputs
33 def nonprintpost(url, userId, password,data):
36 headers['Content-Type'] = 'application/json'
37 #headers['Accept']= 'application/xml'
39 session = _cache.switch("CLUSTERING_POST")
40 resp = session.post(url,data.encode('utf-8'),headers=headers)
46 #Helps in making POST REST calls
48 def post(url, userId, password,data):
49 print("post request with url "+url)
50 print("post request with data "+data)
52 headers['Content-Type'] = 'application/json'
53 #headers['Accept']= 'application/xml'
54 session = _cache.switch("CLUSTERING_POST")
55 resp = session.post(url,data.encode('utf-8'),headers=headers)
57 #print (resp.raise_for_status())
63 #Helps in making DELET REST calls
65 def delete(url,userId,password):
66 print("delete all resources belonging to url"+url)
67 session = _cache.switch("CLUSTERING_DELETE")
68 resp=session.delete(url)
71 # use username and password of controller server for ssh and need
72 # karaf distribution location like /root/Documents/dist
74 def execute_ssh_command(ip, username, password, command):
75 print "executing ssh command"
77 lib.open_connection(ip)
78 lib.login(username=username,password=password)
80 lib.execute_command(command)
81 print "command executed : " + command
82 lib.close_connection()
84 def startcontroller(ip,username,password,karafhome):
85 execute_ssh_command(ip, username, password, karafhome+"/bin/start")
87 def stopcontroller(ip,username,password,karafhome):
88 execute_ssh_command(ip, username, password, karafhome+"/bin/stop")
90 def clean_journal(ip, username, password, karafHome):
91 execute_ssh_command(ip, username, password, "rm -rf " + karafHome + "/journal")
93 def kill_controller(ip, username, password, karafHome):
94 execute_ssh_command(ip, username, password, "ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sh")
98 if __name__ != "__main__":
99 _cache = robot.utils.ConnectionCache('No sessions created')
100 # here create one session for each HTTP functions
101 _cache.register(requests.session(), alias='CLUSTERING_GET')
102 _cache.register(requests.session(),alias='CLUSTERING_POST')
103 _cache.register(requests.session(),alias='CLUSTERING_DELETE')