-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrpc_create_delete_client.py
More file actions
113 lines (95 loc) · 2.88 KB
/
rpc_create_delete_client.py
File metadata and controls
113 lines (95 loc) · 2.88 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#==============================================================================
# create_datarule_event.py
# Python script that creates a datarule for a device
#
#==============================================================================
## Tested with python 2.6.5
##
## Copyright (c) 2010, Exosite LLC
## All rights reserved.
##
## For License see LICENSE file
import socket
import sys
try:
if sys.version_info < (2 , 6):
json_module= 'python-simplejson'
import simplejson as json
else:
json_module= 'python-json'
import json
except ImportError:
print "The package '%s' is required." % json_module
sys.exit(1)
HOST = 'm2.exosite.com'
PORT = 80
PORTALCIK = 'YOURPORTALCIKHERE' #Get from: https://portals.exosite.com/account/portals
DEVICENAME = "TEST DEVICE"
print ''
print '-----------------'
print 'Create a New Device '
print 'Device Name:',DEVICENAME
print '-----------------'
LIMITS = {
"client":"infinity"
,"dataport":"infinity"
,"datarule":"infinity"
,"disk":"infinity"
,"dispatch":"infinity"
,"email":"infinity"
,"http":"infinity"
,"io":"infinity"
,"share":"infinity"
,"sms":"infinity"
,"xmpp":"infinity"
}
META = {"device": {"type":"generic"},"timezone": "America/Chicago","location":"here"}
META_STRING = json.dumps(META)
DESCRIPTION = {"limits":LIMITS, "name":DEVICENAME,"meta":META_STRING, "locked":False, "visilibility":"parent", "writeinterval":0}
TYPE = "client"
ARGUMENTS = [TYPE,DESCRIPTION]
PROCEDURE = "create"
CALLREQUEST1 = {"id" : 1, "procedure":PROCEDURE, "arguments":ARGUMENTS}
CALLS = [CALLREQUEST1]
AUTH = { "cik" : PORTALCIK }
RPC = { "auth" : AUTH, "calls":CALLS}
json_rpc = json.dumps(RPC)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('POST /api:v1/rpc/process HTTP/1.1\r\n')
s.send('Host: m2.exosite.com\r\n')
s.send('Content-Type: application/json; charset=utf-8\r\n')
body = json_rpc
s.send('Content-Length: '+ str(len(body)) +'\r\n\r\n')
s.send(body)
data = s.recv(1024)
print 'Received: \r\n', str(data)
response = data.split('\r\n\r\n')
objs = json.loads(response[1])
#print objs
rid = objs[0]["result"]
print rid
print ''
print '-----------------'
print 'Now lets delete that New Device '
print 'Device Name:',DEVICENAME
print '-----------------'
RESOURCEID = rid
ARGUMENTS = [RESOURCEID]
PROCEDURE = "drop"
CALLREQUEST1 = {"id" : 1, "procedure":PROCEDURE, "arguments":ARGUMENTS}
CALLS = [CALLREQUEST1]
AUTH = { "cik" : PORTALCIK }
RPC = { "auth" : AUTH, "calls":CALLS}
json_rpc = json.dumps(RPC)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('POST /api:v1/rpc/process HTTP/1.1\r\n')
s.send('Host: m2.exosite.com\r\n')
s.send('Content-Type: application/json; charset=utf-8\r\n')
body = json_rpc
s.send('Content-Length: '+ str(len(body)) +'\r\n\r\n')
s.send(body)
data = s.recv(1024)
print 'Received: \r\n', str(data)
s.close()