forked from milos85vasic/Server-Factory-Parallels-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_machine_name.py
executable file
·51 lines (42 loc) · 1.7 KB
/
set_machine_name.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
#!/usr/bin/python
import os
import sys
import time
import xml.etree.ElementTree
def main():
if len(sys.argv) > 1:
image = sys.argv[1]
file_path = image + "/config.pvs"
if os.path.exists(file_path):
with open(file_path, 'r') as fp:
print(file_path + ": Configuration file")
"""
<ParallelsVirtualMachine dyn_lists="VirtualAppliance 0" schemaVersion="1.0">
<Identification dyn_lists="">
<VmName>VM_NAME</VmName>
</Identification>
</ParallelsVirtualMachine
"""
ext = "IDFR"
et = xml.etree.ElementTree.parse(file_path)
for child in et.getroot().findall('.//Identification'):
for vm_name in child.findall('.//VmName'):
millis = int(round(time.time() * 1000))
addition = " " + ext + str(millis)
current_name = vm_name.text
if ext in current_name:
parts = current_name.split(ext)
new_name = parts[0].strip() + addition
else:
new_name = current_name + addition
vm_name.text = new_name
et.write(file_path)
print("Machine name set to: " + new_name)
else:
print("ERROR: Configuration file was not found")
sys.exit(1)
else:
print("No image path provided")
sys.exit(1)
if __name__ == "__main__":
main()