diff options
| author | Daniil Baturin <daniil@vyos.io> | 2025-09-16 15:29:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-16 15:29:56 +0100 |
| commit | 8b0c9b7f7d54c876e12552296a4967f24d09afe9 (patch) | |
| tree | b9169170c46837cdbf46ecaca2bf7868387164cd /src/migration-scripts | |
| parent | 0687b1a039dc1766ccd463f67c997c94e7683b1f (diff) | |
| parent | e992fb4ec3d65674c794bdcb961b62485fec8d50 (diff) | |
| download | vyos-1x-8b0c9b7f7d54c876e12552296a4967f24d09afe9.tar.gz vyos-1x-8b0c9b7f7d54c876e12552296a4967f24d09afe9.zip | |
Merge pull request #4688 from hedrok/T75-migration-to-ipt-netflow
T75: migrate from pmacct to ipt_NETFLOW
Diffstat (limited to 'src/migration-scripts')
| -rw-r--r-- | src/migration-scripts/flow-accounting/2-to-3 | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/migration-scripts/flow-accounting/2-to-3 b/src/migration-scripts/flow-accounting/2-to-3 new file mode 100644 index 000000000..48292fc1d --- /dev/null +++ b/src/migration-scripts/flow-accounting/2-to-3 @@ -0,0 +1,65 @@ +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library. If not, see <http://www.gnu.org/licenses/>. + +# migrate from pmacct to ipt-NETFLOW: +# Remove 'timeout' subtree, 'buffer-size', 'disable-imt', 'packet-length' and +# 'syslog-facility' from 'system flow-accounting' +# +# Move "system flow-accounting interface" to "system flow-accounting netflow interface" +# +# Remove "system flow-accounting source" and add it to each server +# under "system flow-accounting netflow server SERVER source-address" + + +from vyos.configtree import ConfigTree + +base = ['system', 'flow-accounting'] +remove_keys = [ + ['buffer-size'], + ['disable-imt'], + ['netflow', 'timeout'], + ['packet-length'], + ['syslog-facility'], +] + +def migrate(config: ConfigTree) -> None: + if not config.exists(base): + # Nothing to do + return + + # Remove not needed pmacct fields + for k in remove_keys: + p = base + k + if config.exists(p): + config.delete(p) + + # Move "system flow-accounting interface" -> "system flow-accounting netflow interface" + if config.exists(base + ['interface']): + config.copy(base + ['interface'], base + ['netflow', 'interface']) + config.delete(base + ['interface']) + + # Remove old "source-address", add it to each server as "source-address" + source_prev_path = base + ['netflow', 'source-address'] + if config.exists(source_prev_path): + source_value = config.return_value(source_prev_path) + config.delete(source_prev_path) + + # So we loose 'source-address' value if there are no servers + # configured, but it is not valid configuration if there + # is no server, so it shouldn't be a problem + if config.exists(base + ['netflow', 'server']): + path = base + ['netflow', 'server'] + for server in config.list_nodes(path): + config.set(path + [server, 'source-address'], source_value) |
