3 application = iotdm.application
4 container = iotdm.container
5 contentInstance = iotdm.contentInstance
8 def connect_to_iotdm(host, user, pw, p):
9 return iotdm.connect(host, base="InCSE1", auth=(user, pw), protocol=p)
12 def create_resource(connection, parent, restype, a=None):
13 restype = int(restype)
15 x = connection.create(parent, restype)
17 x = connection.create(parent, restype, attr=a)
19 raise AssertionError('Cannot create this resource')
20 elif hasattr(x, 'status_code'):
21 if x.status_code < 200 or x.status_code > 299:
23 'Cannot create this resource [%d] : %s' %
24 (x.status_code, x.text))
27 # this might not be necessary now that the library functions can take dicts
30 def create_subscription(connection, parent, ip, port):
31 uri = "http://%s:%d" % (ip, int(port))
32 x = connection.create(parent, "subscription", {
33 "notificationURI": uri,
34 "notificationContentType": "wholeResource"})
36 raise AssertionError('Cannot create this subscription')
37 elif hasattr(x, 'status_code'):
38 if x.status_code < 200 or x.status_code > 299:
39 raise AssertionError('Cannot create subscription [%d] : %s' %
40 (x.status_code, x.text))
44 def retrieve_resource(connection, resid):
45 x = connection.retrieve(resid)
47 raise AssertionError('Cannot retrieve this resource')
48 elif hasattr(x, 'status_code'):
49 if x.status_code < 200 or x.status_code > 299:
50 raise AssertionError('Cannot retrieve this resource [%d] : %s' %
51 (x.status_code, x.text))
55 def update_resource(connection, resid, attr):
56 x = connection.update(resid, attr)
58 raise AssertionError('Cannot update this resource')
59 elif hasattr(x, 'status_code'):
60 if x.status_code < 200 or x.status_code > 299:
61 raise AssertionError('Cannot update this resource [%d] : %s' %
62 (x.status_code, x.text))
66 def delete_resource(connection, resid):
67 x = connection.delete(resid)
69 raise AssertionError('Cannot delete this resource')
70 elif hasattr(x, 'status_code'):
71 if x.status_code < 200 or x.status_code > 299:
72 raise AssertionError('Cannot delete this resource [%d] : %s' %
73 (x.status_code, x.text))
90 return x.elapsed.total_seconds()