summaryrefslogtreecommitdiff
path: root/src/migration-scripts/pim/0-to-1
blob: ce24b23ba3677a337de3499bb7fc66c11c925950 (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
# Copyright 2023-2024 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/>.

# T5736: igmp: migrate "protocols igmp" to "protocols pim"

from vyos.configtree import ConfigTree

base = ['protocols', 'igmp']
pim_base = ['protocols', 'pim']

def migrate(config: ConfigTree) -> None:
    if not config.exists(base):
        # Nothing to do
        return

    for interface in config.list_nodes(base + ['interface']):
        base_igmp_iface = base + ['interface', interface]
        pim_base_iface = pim_base + ['interface', interface]

        # Create IGMP note under PIM interface
        if not config.exists(pim_base_iface + ['igmp']):
            config.set(pim_base_iface + ['igmp'])

        if config.exists(base_igmp_iface + ['join']):
            config.copy(base_igmp_iface + ['join'], pim_base_iface + ['igmp', 'join'])
            config.set_tag(pim_base_iface + ['igmp', 'join'])

            new_join_base = pim_base_iface + ['igmp', 'join']
            for address in config.list_nodes(new_join_base):
                if config.exists(new_join_base + [address, 'source']):
                    config.rename(new_join_base + [address, 'source'], 'source-address')

        if config.exists(base_igmp_iface + ['query-interval']):
            config.copy(base_igmp_iface + ['query-interval'], pim_base_iface + ['igmp', 'query-interval'])

        if config.exists(base_igmp_iface + ['query-max-response-time']):
            config.copy(base_igmp_iface + ['query-max-response-time'], pim_base_iface + ['igmp', 'query-max-response-time'])

        if config.exists(base_igmp_iface + ['version']):
            config.copy(base_igmp_iface + ['version'], pim_base_iface + ['igmp', 'version'])

    config.delete(base)