diff options
| author | Daniil Baturin <daniil@baturin.org> | 2025-12-02 14:09:49 +0000 |
|---|---|---|
| committer | Daniil Baturin <daniil@baturin.org> | 2025-12-04 10:44:25 +0000 |
| commit | 4b9a008b24eafbb3bc0f81578ed22e96e2d72b6f (patch) | |
| tree | e09bc5990d1ce486a914a64bc4a2a7c6c8e51d90 /src | |
| parent | f4d46db92f9d95c2264c219304172b7b45094bb3 (diff) | |
| download | vyos-1x-4b9a008b24eafbb3bc0f81578ed22e96e2d72b6f.tar.gz vyos-1x-4b9a008b24eafbb3bc0f81578ed22e96e2d72b6f.zip | |
syslog: T8059: migrate host:port node names to the new syntax
with a dedicated port option
Diffstat (limited to 'src')
| -rw-r--r-- | src/migration-scripts/system/28-to-29 | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/migration-scripts/system/28-to-29 b/src/migration-scripts/system/28-to-29 index 310feaa2f..7d912b612 100644 --- a/src/migration-scripts/system/28-to-29 +++ b/src/migration-scripts/system/28-to-29 @@ -18,6 +18,16 @@ # - remove syslog user console logging # - move "global preserve-fqdn" one CLI level up # - rename "host" to "remote" +# +# T8059: +# - if a syslog remote contains a port (like 192.0.2.1:9000), +# migrate the port part to the new dedicated "port" option +# +# XXX: this script leads to data loss when a config +# has multiple remotes with the same host address but different ports. +# That issue needs to be addressed separately (T8058) + +import re from vyos.configtree import ConfigTree @@ -64,8 +74,35 @@ def migrate(config: ConfigTree) -> None: config.set(base + ['remote']) config.set_tag(base + ['remote']) for remote in config.list_nodes(base + ['host']): - config.copy(base + ['host', remote], base + ['remote', remote]) - config.set_tag(base + ['remote']) - if vrf: - config.set(base + ['remote', remote, 'vrf'], value=vrf) + # Check if the host address has a port + # to migrate the port part to the new dedicated "port" option + res = re.match(r'(?P<host>[^:]+):(?P<port>.*)', remote) + if res: + remote_host = res.group('host') + remote_port = res.group('port') + else: + remote_host = remote + remote_port = None + + # XXX: the fact that it was possible to use node names like "192.0.2.1:9000" + # made it possible to create configurations that would send different messages + # to different ports on the same server. + # At the moment, such configurations are unsupported + # so the script only keeps one of such remotes. + if config.exists(base + ['remote', remote_host]): + # Skip the remote if it already exists + # XXX: This tacitly implies that if multiple remotes + # with the same address but different ports are used, + # only the first one of those makes it into the migrated config. + continue + else: + config.copy(base + ['host', remote], base + ['remote', remote_host]) + + if remote_port: + config.set(base + ['remote', remote_host, 'port'], value=remote_port) + + config.set_tag(base + ['remote']) + if vrf: + config.set(base + ['remote', remote_host, 'vrf'], value=vrf) + config.delete(base + ['host']) |
