-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhost.py
51 lines (49 loc) · 1.16 KB
/
host.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
#!/usr/bin/python
#coding:utf8
import json
import api
import urllib2
import option
class hostMethod():
def __init__(self):
self.Variables = api.variables()
self.loginAuth = api.main()
def gethostData(self,hostip=""):
data = json.dumps({
"jsonrpc": "2.0",
"method": "host.get",
"params": {
"output": "extend",
"filter": {
"host":[]
}
},
"auth": self.loginAuth,
"id": 1
})
re = self.Variables.dataGet(data)
return re['result']
def createhostData(self, tempid="10382", groupid="93",hostname="",hostip=""):
data = json.dumps({
"jsonrpc": "2.0",
"method": "host.create",
"params": {
"host": hostname,
"interfaces": [
{
"type": 1,
"main": 1,
"useip": 1,
"ip": hostip,
"dns": "",
"port": "10050"
}
],
"groups": [{"groupid": groupid }],
"templates": [{"templateid": tempid}],
},
"auth": self.loginAuth,
"id": 1
})
re = self.Variables.dataGet(data)
return re['result']