forked from paolo-projects/unlocker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse-test.py
45 lines (35 loc) · 1.1 KB
/
parse-test.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
#!/usr/bin/env python
from __future__ import print_function
import sys
import xml.etree.ElementTree as ET
def main():
dom = ET.ElementTree(file='./samples/config.xml')
vmsvcpath = './/plugins//vmsvc'
sandboxpath = './/plugins//vmsvc//useVmxSandbox'
vmsvc = ET.ElementTree.find(dom, vmsvcpath)
sandbox = ET.ElementTree.find(dom, sandboxpath)
if vmsvc is None:
print('ESXi Config - config.xml is corrupt')
return False
else:
if sandbox is None:
sandbox = ET.Element('useVmxSandbox')
sandbox.text = 'false'
vmsvc.append(sandbox)
sandbox = ET.ElementTree.find(dom, sandboxpath)
if sys.argv[1] == 'off':
sandbox.text = 'false'
elif sys.argv[1] == 'on':
sandbox.text = 'true'
else:
print('ESXi Config - Error no or incorrect paramter passed')
return False
dom.write('./samples/output.xml')
return True
if __name__ == '__main__':
if len(sys.argv) == 1:
sys.exit(1)
if main():
sys.exit(0)
else:
sys.exit(1)