-
Notifications
You must be signed in to change notification settings - Fork 92
/
query.py
91 lines (84 loc) · 2.41 KB
/
query.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
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
#!/usr/bin/env python
##############################################################
# written by Markus Nikulski
# 08 Mar 2022
##############################################################
import XMC_NBI
##############################################################
xmcServerIp = '192.168.162.50'
xmcClientID = 'DVDnjOaqMQ'
xmcSecret = '8c12a0e1-87f8-4b18-a8d1-2e8c74d27c65'
macAddress = '11:22:33:44:55:66'
esGroup = 'Printers'
##############################################################
session = XMC_NBI.XMC_NBI(xmcServerIp, xmcClientID, xmcSecret)
if session.error:
print( "ERROR: '%s'" % session.message )
exit(1)
query = '''
mutation {
accessControl {
addMACToEndSystemGroup(
input: {
group: "<GROUP>"
value: "<MAC>"
description: "just a test"
custom1: "first"
custom2: "second"
custom3: "third"
custom4: "four"
}
) {
status
message
}
}
}
'''
query = query.replace("<MAC>", macAddress)
query = query.replace("<GROUP>", esGroup)
data = session.query( query )
if not data['accessControl']['addMACToEndSystemGroup']['status'] == 'SUCCESS':
print("ERROR: unable to add MAC address: %s" % data['accessControl']['addMACToEndSystemGroup']['message'])
else:
print("INFO: add MAC address "+ macAddress)
queryInput = '''
{
accessControl {
endSystemInfoByMac(macAddress: "<MAC>") {
endSystemInfo {
custom1
custom2
custom3
custom4
groupDescr1
}
}
}
}
'''
data = session.query( queryInput.replace("<MAC>", macAddress) )
for item in data['accessControl']['endSystemInfoByMac']['endSystemInfo']:
print("INFO: MAC data: %s = %s" % (item, data['accessControl']['endSystemInfoByMac']['endSystemInfo'][item]) )
query = '''
mutation {
accessControl {
removeMACFromEndSystemGroup (input: {
value: "<MAC>"
group: "<GROUP>"
reauthenticate: true
}) {
status
message
}
}
}
'''
query = query.replace("<MAC>", macAddress)
query = query.replace("<GROUP>", esGroup)
data = session.query( query )
if not data['accessControl']['removeMACFromEndSystemGroup']['status'] == 'SUCCESS':
print("ERROR: unable to delete MAC address: %s" % data['accessControl']['removeMACFromEndSystemGroup']['message'])
else:
print("INFO: delete MAC address "+ macAddress)