blob: 31a8930cc4ec851704b08a7d796b933f55fe5069 [file] [log] [blame]
adminbae64d82013-08-01 10:50:15 -07001#!/usr/bin/env python
2'''
3Created on 4-Jun-2013
4
5@author: Anil Kumar (anilkumar.s@paxterrasolutions.com)
6
7
8 TestON is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
12
13 TestON is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with TestON. If not, see <http://www.gnu.org/licenses/>.
20
21
22onosrestapidriver is the basic driver which will handle the onorestapi functions
23'''
24
25import struct
26import fcntl
27import os
28import signal
29import re
30import sys
31import time
32
33sys.path.append("../")
34from drivers.common.apidriver import API
35import urllib
36import __builtin__
37
38
39class OnosRestApiDriver(API):
40
41 def __init__(self):
42 super(API, self).__init__()
43
44
45 def connect(self,**connectargs):
46 for key in connectargs:
47 vars(self)[key] = connectargs[key]
48
49 self.name = self.options['name']
50 self.handle = super(OnosRestApiDriver,self).connect()
51 main.log.info(self.options['topology_url'])
52 try :
53 self.handle = urllib.urlopen(self.options['topology_url'])
54 except Exception,e:
55 main.log.error(e)
56
57 self.logFileName = main.logdir+"/"+self.name+".session"
58
59 if self.handle:
60 return self.handle
61 else :
62 return main.FALSE
63
64 def execute(self):
65 main.log.info(self.options['topology_url'])
66 response = main.FALSE
67 for i in [1,2] :
68 time.sleep(2)
69 response = self.http_request()
70 return response
71
72 def http_request(self):
73 try :
74 self.handle = urllib.urlopen(self.options['topology_url'])
75
76 resonse_lines = self.handle.readlines()
77 print resonse_lines
78 return resonse_lines
79 except Exception,e:
80 main.log.error(e)
81 return "url error"
82
83 def disconnect(self,handle):
84 response = ''
85 '''
86 if self.handle:
87 self.handle = handle
88 response = self.execute(cmd="exit",prompt="(.*)",timeout=120)
89 else :
90 main.log.error("Connection failed to the host")
91 response = main.FALSE
92 '''
93 return response
94
95
96
97