Skip to content

Commit ba3b4bc

Browse files
committed
Add Python scripts to help migrate daemon and service configs to Spawnpoint 1.0
1 parent a02c543 commit ba3b4bc

3 files changed

Lines changed: 133 additions & 0 deletions

File tree

migration/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Overview
2+
These Python scripts have been provided to assist users migrating from early
3+
versions of Spawnpoint (0.x) to the latest version (1.x).
4+
5+
## Updating a Daemon Configuration File
6+
The script `convertDaemonConfig.py` is used to convert a `spawnd` 0.x
7+
configuration file into a new `spawnd` configuration that is compatible with
8+
the 1.x releases of the system. It is used like so:
9+
```
10+
$ python convertDaemonConfig.py oldConfig.yml newConfig.yml
11+
```
12+
13+
Here, `oldConfig.yml` is the name of the current configuration file, while
14+
`newConfig.yml` is the name of the new 1.x-compatible file that will be created.
15+
16+
Most of the features of the 0.x daemon configuration files have been preserved
17+
in the 1.x release. The exceptions are:
18+
1. The `containerRouter` field has been deprecated. Now, both the daemon and
19+
the containers it managers talk to the same Bosswave endpoint, which has
20+
been renamed to `bw2Agent` in configuration files for clarity.
21+
2. You may no longer specify an `alias` for the `spawnd` instance. Instead,
22+
this is assumed to be the last element of the daemon's base URI.
23+
24+
## Updating a Service Configuration File
25+
This is very similar to updating a daemon configuration. The script
26+
`convertServiceConfig.py` is used like so:
27+
```
28+
$ python convertServiceConfig.py oldDeploy.yml newDeploy.yml
29+
```
30+
31+
`oldDeploy.yml` is the 0.x-compatible service configuration file, and
32+
`newDeploy.yml` is the name of the 1.x-compatible file that will be created.
33+
34+
Most of the features of the 0.x service configuration files have been preserved.
35+
The exceptions are:
36+
1. The `overlayNet` field (and Docker overlay networking in general) has been
37+
deprecated.
38+
2. The `restartInt` field has been deprecated. `spawnd` now reserves the right
39+
to handle service restart intervals internally.

migration/convertDaemonConfig.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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")

migration/convertServiceConfig.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#! /usr/bin/env python
2+
import re
3+
import sys
4+
5+
if len(sys.argv) < 3:
6+
print "Usage: {} <service 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 = ["restartInt", "overlayNet"]
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 image 'jhkolb/spawnpoint:amd64' to 'jhkolb/spawnable:amd64'
38+
elif line.startswith("image"):
39+
line = line.replace("jhkolb/spawnpoint:amd64", "jhkolb/spawnable:amd64")
40+
41+
# Rename 'includedDirs' to 'includedDirectories'
42+
elif line.startswith("includedDirs"):
43+
line = line.replace("includedDirs", "includedDirectories", 1)
44+
45+
g.write(line + "\n")

0 commit comments

Comments
 (0)