summaryrefslogtreecommitdiff
path: root/src/migration-scripts/vpp/7-to-8
blob: 1e95bb43ebbd8ecd6a2d77b491178b77f7a9b105 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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/>.
#
# Rename `vpp settings logging default-log-level` to
# `vpp settings logging default-level` (T8255)
#
# Move 'vpp nat44' and 'vpp settings nat44' to 'vpp nat nat44'.
# Drop settings for nat workers (T8254)
#
# Delete 'ipsec' node and all settings and replace it with single 'ipsec-acceleration' flag (T8262)


from vyos.configtree import ConfigTree


def _migrate_vpp_log(config: ConfigTree) -> None:
    base = ['vpp', 'settings', 'logging']
    if config.exists(base + ['default-log-level']):
        config.rename(base + ['default-log-level'], 'default-level')


def _migrate_vpp_nat44(config: ConfigTree) -> None:
    base_path = ['vpp', 'nat44']
    new_base_path = ['vpp', 'nat', 'nat44']
    settings_path = ['vpp', 'settings', 'nat44']

    if not config.exists(base_path):
        # Nothing to do
        return

    if not config.exists(['vpp', 'nat']):
        config.set(['vpp', 'nat'])

    # copy "vpp nat44" to "vpp nat nat44"
    config.copy(base_path, new_base_path)
    config.delete(base_path)

    # move 'vpp settings nat44' to 'vpp nat nat44'
    if config.exists(settings_path):
        if config.exists(settings_path + ['session-limit']):
            session_limit = config.return_value(settings_path + ['session-limit'])
            config.set(new_base_path + ['session-limit'], value=session_limit)
        if config.exists(settings_path + ['timeout']):
            config.copy(settings_path + ['timeout'], new_base_path + ['timeout'])
        config.delete(settings_path)

def _migrate_vpp_ipsec(config: ConfigTree) -> None:
    base = ['vpp', 'settings']

    if config.exists(base + ['ipsec']):
        config.set(base + ['ipsec-acceleration'])
        config.delete(base + ['ipsec'])


def migrate(config: ConfigTree) -> None:
    if not config.exists(['vpp']):
        # Nothing to do
        return

    _migrate_vpp_log(config)
    _migrate_vpp_nat44(config)
    _migrate_vpp_ipsec(config)