-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPylREST.py
executable file
·57 lines (47 loc) · 1.33 KB
/
PylREST.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/python
#
import web
# TODO: This is a dumb way to reference:
urls = (
'/setvar/*(.*)', 'setvar',
'/(.*)', 'default'
)
PylRESTApp = web.application(urls, globals())
PylRESTObj = False
class PylREST(object):
global PylRESTObj
def __init__(self,devices):
global PylRESTObj
self.app = PylRESTApp
self.devices = devices
self.byip = {}
for device in devices:
self.byip[device.ip] = device
PylRESTObj = self
def run(self):
self.app.run()
class default:
def GET(self, name):
if not name:
name = 'World'
return 'Default, ' + name + '!'
class setvar:
def GET(self, path):
if not path:
return "varname/value not defined!"
# TODO: Allow value param to be passed in?
# TODO: Make sure split only returns 2 objects?
#udata = web.input(value=None)
li = path.split("/")
varname = li[0]
varvalue = li[1]
dip = web.ctx['ip']
print("device: " + dip)
# TODO: Generate error if device does not exist
device = PylRESTObj.byip[dip]
info = 'Device: ' + dip + ' varname='+ varname + ' value=' + str(varvalue)
print(info)
device.setvar(varname,varvalue)
return info
#if __name__ == "__main__":
# #PylREST.run()