|
| 1 | +#! /usr/bin/env python |
| 2 | +import re |
| 3 | +import sys |
| 4 | + |
| 5 | +if len(sys.argv) < 3: |
| 6 | + print "Usage: {} <daemon config file> <output file>" |
| 7 | + sys.exit(1) |
| 8 | +daemon_config_file = sys.argv[1] |
| 9 | +output_file = sys.argv[2] |
| 10 | + |
| 11 | +deprecated_fields = ["containerRouter", "alias"] |
| 12 | + |
| 13 | +with open(daemon_config_file) as f: |
| 14 | + with open(output_file, 'w') as g: |
| 15 | + for line in f: |
| 16 | + line = line.strip() |
| 17 | + |
| 18 | + # Remove deprecated fields |
| 19 | + if any([line.startswith(x) for x in deprecated_fields]): |
| 20 | + continue |
| 21 | + |
| 22 | + # Rename 'entity' to 'bw2Entity' |
| 23 | + if line.startswith("entity"): |
| 24 | + line = line.replace("entity", "bw2Entity", 1) |
| 25 | + |
| 26 | + # Rename 'memAlloc' to 'memory' and convert to MiB |
| 27 | + elif line.startswith("memAlloc"): |
| 28 | + match = re.match(r'memAlloc\s*:\s*(\d+)([MmGg])', line) |
| 29 | + if match is None: |
| 30 | + raise ValueError("Invalid memory allocation: {}".format(line)) |
| 31 | + memQuantity = int(match.group(1)) |
| 32 | + memUnits = match.group(2) |
| 33 | + if memUnits == "G" or memUnits == "g": |
| 34 | + memQuantity *= 1024 |
| 35 | + line = "memory: {}".format(memQuantity) |
| 36 | + |
| 37 | + # Rename "localRouter" to "bw2Agent" |
| 38 | + elif line.startswith("localRouter"): |
| 39 | + line = line.replace("localRouter", "bw2Agent") |
| 40 | + |
| 41 | + # Rename 'allowHostNet' to 'enableHostNetworking' |
| 42 | + elif line.startswith("allowHostNet"): |
| 43 | + line = line.replace("allowHostNet", "enableHostNetworking") |
| 44 | + |
| 45 | + # Rename 'allowDeviceMappings' to 'enableDeviceMapping' |
| 46 | + elif line.startswith("allowDeviceMappings"): |
| 47 | + line = line.replace("allowDeviceMappings", "enableDeviceMapping") |
| 48 | + |
| 49 | + g.write(line + "\n") |
0 commit comments