diff options
Diffstat (limited to 'src/migration-scripts')
21 files changed, 797 insertions, 10 deletions
diff --git a/src/migration-scripts/bgp/3-to-4 b/src/migration-scripts/bgp/3-to-4 new file mode 100755 index 000000000..0df2fbec4 --- /dev/null +++ b/src/migration-scripts/bgp/3-to-4 @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5150: Rework CLI definitions to apply route-maps between routing daemons +#        and zebra/kernel + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +bgp_base = ['protocols', 'bgp'] +# Check if BGP is configured - if so, migrate the CLI node +if config.exists(bgp_base): +    if config.exists(bgp_base + ['route-map']): +        tmp = config.return_value(bgp_base + ['route-map']) + +        config.set(['system', 'ip', 'protocol', 'bgp', 'route-map'], value=tmp) +        config.set_tag(['system', 'ip', 'protocol']) +        config.delete(bgp_base + ['route-map']) + + +# Check if vrf names are configured. Check if BGP is configured - if so, migrate +# the CLI node(s) +if config.exists(['vrf', 'name']): +    for vrf in config.list_nodes(['vrf', 'name']): +        vrf_base = ['vrf', 'name', vrf] +        if config.exists(vrf_base + ['protocols', 'bgp', 'route-map']): +            tmp = config.return_value(vrf_base + ['protocols', 'bgp', 'route-map']) + +            config.set(vrf_base + ['ip', 'protocol', 'bgp', 'route-map'], value=tmp) +            config.set_tag(vrf_base + ['ip', 'protocol', 'bgp']) +            config.delete(vrf_base + ['protocols', 'bgp', 'route-map']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/dns-forwarding/3-to-4 b/src/migration-scripts/dns-forwarding/3-to-4 new file mode 100755 index 000000000..55165c2c5 --- /dev/null +++ b/src/migration-scripts/dns-forwarding/3-to-4 @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5115: migrate "service dns forwarding domain example.com server" to +#                "service dns forwarding domain example.com name-server" + +import sys +from vyos.configtree import ConfigTree + +if (len(sys.argv) < 1): +    print("Must specify file name!") +    sys.exit(1) + +file_name = sys.argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +base = ['service', 'dns', 'forwarding', 'domain'] +if not config.exists(base): +    # Nothing to do +    sys.exit(0) + +for domain in config.list_nodes(base): +    if config.exists(base + [domain, 'server']): +        config.copy(base + [domain, 'server'], base + [domain, 'name-server']) +        config.delete(base + [domain, 'server']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print("Failed to save the modified config: {}".format(e)) +    sys.exit(1) diff --git a/src/migration-scripts/firewall/9-to-10 b/src/migration-scripts/firewall/9-to-10 new file mode 100755 index 000000000..6f67cc512 --- /dev/null +++ b/src/migration-scripts/firewall/9-to-10 @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5050: Log options +#  cli changes from:        +#  set firewall [name | ipv6-name] <name> rule <number> log-level <log_level> +#  To +#  set firewall [name | ipv6-name] <name> rule <number> log-options level <log_level> + +import re + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree +from vyos.ifconfig import Section + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['firewall'] +config = ConfigTree(config_file) + +if not config.exists(base): +    # Nothing to do +    exit(0) + +if config.exists(base + ['name']): +    for name in config.list_nodes(base + ['name']): +        if not config.exists(base + ['name', name, 'rule']): +            continue + +        for rule in config.list_nodes(base + ['name', name, 'rule']): +            log_options_base = base + ['name', name, 'rule', rule, 'log-options']  +            rule_log_level = base + ['name', name, 'rule', rule, 'log-level'] + +            if config.exists(rule_log_level): +                tmp = config.return_value(rule_log_level) +                config.delete(rule_log_level) +                config.set(log_options_base + ['level'], value=tmp) + +if config.exists(base + ['ipv6-name']): +    for name in config.list_nodes(base + ['ipv6-name']): +        if not config.exists(base + ['ipv6-name', name, 'rule']): +            continue + +        for rule in config.list_nodes(base + ['ipv6-name', name, 'rule']): +            log_options_base = base + ['ipv6-name', name, 'rule', rule, 'log-options']  +            rule_log_level = base + ['ipv6-name', name, 'rule', rule, 'log-level'] + +            if config.exists(rule_log_level): +                tmp = config.return_value(rule_log_level) +                config.delete(rule_log_level) +                config.set(log_options_base + ['level'], value=tmp) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print("Failed to save the modified config: {}".format(e)) +    exit(1)
\ No newline at end of file diff --git a/src/migration-scripts/interfaces/0-to-1 b/src/migration-scripts/interfaces/0-to-1 index ee4d6b82c..c7f324661 100755 --- a/src/migration-scripts/interfaces/0-to-1 +++ b/src/migration-scripts/interfaces/0-to-1 @@ -3,7 +3,7 @@  # Change syntax of bridge interface  # - move interface based bridge-group to actual bridge (de-nest)  # - make stp and igmp-snooping nodes valueless -# https://phabricator.vyos.net/T1556 +# https://vyos.dev/T1556  import sys  from vyos.configtree import ConfigTree diff --git a/src/migration-scripts/interfaces/1-to-2 b/src/migration-scripts/interfaces/1-to-2 index 050137318..c75404d85 100755 --- a/src/migration-scripts/interfaces/1-to-2 +++ b/src/migration-scripts/interfaces/1-to-2 @@ -2,7 +2,7 @@  # Change syntax of bond interface  # - move interface based bond-group to actual bond (de-nest) -# https://phabricator.vyos.net/T1614 +# https://vyos.dev/T1614  import sys  from vyos.configtree import ConfigTree @@ -40,7 +40,7 @@ else:      # some combinations were allowed in the past from a CLI perspective      # but the kernel overwrote them - remove from CLI to not confuse the users.      # In addition new consitency checks are in place so users can't repeat the -    # mistake. One of those nice issues is https://phabricator.vyos.net/T532 +    # mistake. One of those nice issues is https://vyos.dev/T532      for bond in config.list_nodes(base):          if config.exists(base + [bond, 'arp-monitor', 'interval']) and config.exists(base + [bond, 'mode']):              mode = config.return_value(base + [bond, 'mode']) diff --git a/src/migration-scripts/interfaces/16-to-17 b/src/migration-scripts/interfaces/16-to-17 index a6b4c7663..d123be06f 100755 --- a/src/migration-scripts/interfaces/16-to-17 +++ b/src/migration-scripts/interfaces/16-to-17 @@ -15,7 +15,7 @@  # along with this program.  If not, see <http://www.gnu.org/licenses/>.  # Command line migration of port mirroring -# https://phabricator.vyos.net/T3089 +# https://vyos.dev/T3089  import sys  from vyos.configtree import ConfigTree diff --git a/src/migration-scripts/interfaces/2-to-3 b/src/migration-scripts/interfaces/2-to-3 index a63a54cdf..68d41de39 100755 --- a/src/migration-scripts/interfaces/2-to-3 +++ b/src/migration-scripts/interfaces/2-to-3 @@ -2,7 +2,7 @@  # Change syntax of openvpn encryption settings  # - move cipher from encryption to encryption cipher -# https://phabricator.vyos.net/T1704 +# https://vyos.dev/T1704  import sys  from vyos.configtree import ConfigTree diff --git a/src/migration-scripts/interfaces/20-to-21 b/src/migration-scripts/interfaces/20-to-21 index 0bd858760..cb1c36882 100755 --- a/src/migration-scripts/interfaces/20-to-21 +++ b/src/migration-scripts/interfaces/20-to-21 @@ -15,7 +15,7 @@  # along with this program.  If not, see <http://www.gnu.org/licenses/>.  # T3619: mirror Linux Kernel defaults for ethernet offloading options into VyOS -#        CLI. See https://phabricator.vyos.net/T3619#102254 for all the details. +#        CLI. See https://vyos.dev/T3619#102254 for all the details.  # T3787: Remove deprecated UDP fragmentation offloading option  from sys import argv diff --git a/src/migration-scripts/interfaces/26-to-27 b/src/migration-scripts/interfaces/26-to-27 new file mode 100755 index 000000000..949cc55b6 --- /dev/null +++ b/src/migration-scripts/interfaces/26-to-27 @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T4995: pppoe, wwan, sstpc-client rename "authentication user" CLI node +#        to "authentication username" + +from sys import argv + +from vyos.ethtool import Ethtool +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +for type in ['pppoe', 'sstpc-client', 'wwam']: +    base = ['interfaces', type] +    if not config.exists(base): +        continue +    for interface in config.list_nodes(base): +        auth_base = base + [interface, 'authentication', 'user'] +        if config.exists(auth_base): +            config.rename(auth_base, 'username') + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/interfaces/27-to-28 b/src/migration-scripts/interfaces/27-to-28 new file mode 100755 index 000000000..6225d6414 --- /dev/null +++ b/src/migration-scripts/interfaces/27-to-28 @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5034: tunnel: rename "multicast enable" CLI node to "enable-multicast" +#        valueless node. + +from sys import argv + +from vyos.ethtool import Ethtool +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['interfaces', 'tunnel'] +config = ConfigTree(config_file) + +if not config.exists(base): +    exit(0) + +for ifname in config.list_nodes(base): +    print(ifname) +    multicast_base = base + [ifname, 'multicast'] +    if config.exists(multicast_base): +        tmp = config.return_value(multicast_base) +        print(tmp) +        # Delete old Config node +        config.delete(multicast_base) +        if tmp == 'enable': +            config.set(base + [ifname, 'enable-multicast']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/interfaces/4-to-5 b/src/migration-scripts/interfaces/4-to-5 index 2a42c60ff..f645c5aeb 100755 --- a/src/migration-scripts/interfaces/4-to-5 +++ b/src/migration-scripts/interfaces/4-to-5 @@ -50,7 +50,7 @@ def migrate_dialer(config, tree, intf):          # Remove IPv6 router-advert nodes as this makes no sense on a          # client diale rinterface to send RAs back into the network -        # https://phabricator.vyos.net/T2055 +        # https://vyos.dev/T2055          ipv6_ra = pppoe_base + ['ipv6', 'router-advert']          if config.exists(ipv6_ra):              config.delete(ipv6_ra) diff --git a/src/migration-scripts/ipsec/10-to-11 b/src/migration-scripts/ipsec/10-to-11 new file mode 100755 index 000000000..0707a5e3c --- /dev/null +++ b/src/migration-scripts/ipsec/10-to-11 @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['vpn', 'ipsec'] +config = ConfigTree(config_file) + +if not config.exists(base): +    # Nothing to do +    exit(0) + +# PEER changes +if config.exists(base + ['site-to-site', 'peer']): +    for peer in config.list_nodes(base + ['site-to-site', 'peer']): +        peer_base = base + ['site-to-site', 'peer', peer] + +        # replace: 'ipsec site-to-site peer <tag> authentication pre-shared-secret xxx' +        #       => 'ipsec authentication psk <tag> secret xxx' +        if config.exists(peer_base + ['authentication', 'pre-shared-secret']): +            tmp = config.return_value(peer_base + ['authentication', 'pre-shared-secret']) +            config.delete(peer_base + ['authentication', 'pre-shared-secret']) +            config.set(base + ['authentication', 'psk', peer, 'secret'], value=tmp) +            # format as tag node to avoid loading problems +            config.set_tag(base + ['authentication', 'psk']) + +            # Get id's from peers for "ipsec auth psk <tag> id xxx" +            if config.exists(peer_base + ['authentication', 'local-id']): +                local_id = config.return_value(peer_base + ['authentication', 'local-id']) +                config.set(base + ['authentication', 'psk', peer, 'id'], value=local_id, replace=False) +            if config.exists(peer_base + ['authentication', 'remote-id']): +                remote_id = config.return_value(peer_base + ['authentication', 'remote-id']) +                config.set(base + ['authentication', 'psk', peer, 'id'], value=remote_id, replace=False) + +            if config.exists(peer_base + ['local-address']): +                tmp = config.return_value(peer_base + ['local-address']) +                config.set(base + ['authentication', 'psk', peer, 'id'], value=tmp, replace=False) +            if config.exists(peer_base + ['remote-address']): +                tmp = config.return_values(peer_base + ['remote-address']) +                if tmp: +                    for remote_addr in tmp: +                        if remote_addr == 'any': +                            remote_addr = '%any' +                        config.set(base + ['authentication', 'psk', peer, 'id'], value=remote_addr, replace=False) + +            # get DHCP peer interface as psk dhcp-interface +            if config.exists(peer_base + ['dhcp-interface']): +                tmp = config.return_value(peer_base + ['dhcp-interface']) +                config.set(base + ['authentication', 'psk', peer, 'dhcp-interface'], value=tmp) + + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/ipsec/11-to-12 b/src/migration-scripts/ipsec/11-to-12 new file mode 100755 index 000000000..8bbde5efa --- /dev/null +++ b/src/migration-scripts/ipsec/11-to-12 @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# Remove legacy ipsec.conf and ipsec.secrets - Not supported with swanctl + +import re + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['vpn', 'ipsec'] +config = ConfigTree(config_file) + +if not config.exists(base): +    # Nothing to do +    exit(0) + +if config.exists(base + ['include-ipsec-conf']): +    config.delete(base + ['include-ipsec-conf']) + +if config.exists(base + ['include-ipsec-secrets']): +    config.delete(base + ['include-ipsec-secrets']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/isis/2-to-3 b/src/migration-scripts/isis/2-to-3 new file mode 100755 index 000000000..4490feb0a --- /dev/null +++ b/src/migration-scripts/isis/2-to-3 @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5150: Rework CLI definitions to apply route-maps between routing daemons +#        and zebra/kernel + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +isis_base = ['protocols', 'isis'] +# Check if IS-IS is configured - if so, migrate the CLI node +if config.exists(isis_base): +    if config.exists(isis_base + ['route-map']): +        tmp = config.return_value(isis_base + ['route-map']) + +        config.set(['system', 'ip', 'protocol', 'isis', 'route-map'], value=tmp) +        config.set_tag(['system', 'ip', 'protocol']) +        config.delete(isis_base + ['route-map']) + +# Check if vrf names are configured. Check if IS-IS is configured - if so, +# migrate  the CLI node(s) +if config.exists(['vrf', 'name']): +    for vrf in config.list_nodes(['vrf', 'name']): +        vrf_base = ['vrf', 'name', vrf] +        if config.exists(vrf_base + ['protocols', 'isis', 'route-map']): +            tmp = config.return_value(vrf_base + ['protocols', 'isis', 'route-map']) + +            config.set(vrf_base + ['ip', 'protocol', 'isis', 'route-map'], value=tmp) +            config.set_tag(vrf_base + ['ip', 'protocol', 'isis']) +            config.delete(vrf_base + ['protocols', 'isis', 'route-map']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/ntp/1-to-2 b/src/migration-scripts/ntp/1-to-2 index 4a701e7e5..d1e510e4c 100755 --- a/src/migration-scripts/ntp/1-to-2 +++ b/src/migration-scripts/ntp/1-to-2 @@ -37,6 +37,11 @@ if not config.exists(base_path):      # Nothing to do      sys.exit(0) +# config.copy does not recursively create a path, so create ['service'] if +# it doesn't yet exist, such as for config.boot.default +if not config.exists(['service']): +    config.set(['service']) +  # copy "system ntp" to "service ntp"  config.copy(base_path, new_base_path)  config.delete(base_path) diff --git a/src/migration-scripts/ospf/1-to-2 b/src/migration-scripts/ospf/1-to-2 new file mode 100755 index 000000000..a6beaf04e --- /dev/null +++ b/src/migration-scripts/ospf/1-to-2 @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5150: Rework CLI definitions to apply route-maps between routing daemons +#        and zebra/kernel + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +ospf_base = ['protocols', 'ospf'] +# Check if OSPF is configured - if so, migrate the CLI node +if config.exists(ospf_base): +    if config.exists(ospf_base + ['route-map']): +        tmp = config.return_value(ospf_base + ['route-map']) + +        config.set(['system', 'ip', 'protocol', 'ospf', 'route-map'], value=tmp) +        config.set_tag(['system', 'ip', 'protocol']) +        config.delete(ospf_base + ['route-map']) + +ospfv3_base = ['protocols', 'ospfv3'] +# Check if OSPFv3 is configured - if so, migrate the CLI node +if config.exists(ospfv3_base): +    if config.exists(ospfv3_base + ['route-map']): +        tmp = config.return_value(ospfv3_base + ['route-map']) + +        config.set(['system', 'ipv6', 'protocol', 'ospfv3', 'route-map'], value=tmp) +        config.set_tag(['system', 'ipv6', 'protocol']) +        config.delete(ospfv3_base + ['route-map']) + +# Check if vrf names are configured. Check if OSPF/OSPFv3 is configured - if so, +# migrate the CLI node(s) +if config.exists(['vrf', 'name']): +    for vrf in config.list_nodes(['vrf', 'name']): +        vrf_base = ['vrf', 'name', vrf] +        if config.exists(vrf_base + ['protocols', 'ospf', 'route-map']): +            tmp = config.return_value(vrf_base + ['protocols', 'ospf', 'route-map']) + +            config.set(vrf_base + ['ip', 'protocol', 'ospf', 'route-map'], value=tmp) +            config.set_tag(vrf_base + ['ip', 'protocol', 'ospf']) +            config.delete(vrf_base + ['protocols', 'ospf', 'route-map']) + +        if config.exists(vrf_base + ['protocols', 'ospfv3', 'route-map']): +            tmp = config.return_value(vrf_base + ['protocols', 'ospfv3', 'route-map']) + +            config.set(vrf_base + ['ipv6', 'protocol', 'ospfv3', 'route-map'], value=tmp) +            config.set_tag(vrf_base + ['ipv6', 'protocol', 'ospfv6']) +            config.delete(vrf_base + ['protocols', 'ospfv3', 'route-map']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/qos/1-to-2 b/src/migration-scripts/qos/1-to-2 index 41026cbd6..14d3a6e0a 100755 --- a/src/migration-scripts/qos/1-to-2 +++ b/src/migration-scripts/qos/1-to-2 @@ -118,6 +118,28 @@ if config.exists(netem_base):          if config.exists(netem_base + [policy_name, 'burst']):              config.delete(netem_base + [policy_name, 'burst']) +# Change bandwidth unit MBit -> mbit as tc only supports mbit +base = ['qos', 'policy'] +if config.exists(base): +    for policy_type in config.list_nodes(base): +        for policy in config.list_nodes(base + [policy_type]): +            policy_base = base + [policy_type, policy] +            if config.exists(policy_base + ['bandwidth']): +                tmp = config.return_value(policy_base + ['bandwidth']) +                config.set(policy_base + ['bandwidth'], value=tmp.lower()) + +            if config.exists(policy_base + ['class']): +                for cls in config.list_nodes(policy_base + ['class']): +                    cls_base = policy_base + ['class', cls] +                    if config.exists(cls_base + ['bandwidth']): +                        tmp = config.return_value(cls_base + ['bandwidth']) +                        config.set(cls_base + ['bandwidth'], value=tmp.lower()) + +            if config.exists(policy_base + ['default', 'bandwidth']): +                if config.exists(policy_base + ['default', 'bandwidth']): +                    tmp = config.return_value(policy_base + ['default', 'bandwidth']) +                    config.set(policy_base + ['default', 'bandwidth'], value=tmp.lower()) +  try:      with open(file_name, 'w') as f:          f.write(config.to_string()) diff --git a/src/migration-scripts/quagga/10-to-11 b/src/migration-scripts/quagga/10-to-11 new file mode 100755 index 000000000..04fc16f79 --- /dev/null +++ b/src/migration-scripts/quagga/10-to-11 @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5150: Rework CLI definitions to apply route-maps between routing daemons +#        and zebra/kernel + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +static_base = ['protocols', 'static'] +# Check if static routes are configured - if so, migrate the CLI node +if config.exists(static_base): +    if config.exists(static_base + ['route-map']): +        tmp = config.return_value(static_base + ['route-map']) + +        config.set(['system', 'ip', 'protocol', 'static', 'route-map'], value=tmp) +        config.set_tag(['system', 'ip', 'protocol']) +        config.delete(static_base + ['route-map']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/rip/0-to-1 b/src/migration-scripts/rip/0-to-1 new file mode 100755 index 000000000..60d510001 --- /dev/null +++ b/src/migration-scripts/rip/0-to-1 @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. + +# T5150: Rework CLI definitions to apply route-maps between routing daemons +#        and zebra/kernel + +from sys import argv +from sys import exit + +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] + +with open(file_name, 'r') as f: +    config_file = f.read() + +config = ConfigTree(config_file) + +ripng_base = ['protocols', 'ripng'] +# Check if RIPng is configured - if so, migrate the CLI node +if config.exists(ripng_base): +    if config.exists(ripng_base + ['route-map']): +        tmp = config.return_value(ripng_base + ['route-map']) + +        config.set(['system', 'ipv6', 'protocol', 'ripng', 'route-map'], value=tmp) +        config.set_tag(['system', 'ipv6', 'protocol']) +        config.delete(ripng_base + ['route-map']) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1) diff --git a/src/migration-scripts/snmp/0-to-1 b/src/migration-scripts/snmp/0-to-1 index a836f7011..096ba779d 100755 --- a/src/migration-scripts/snmp/0-to-1 +++ b/src/migration-scripts/snmp/0-to-1 @@ -33,18 +33,18 @@ if not config.exists(config_base):      # Nothing to do      sys.exit(0)  else: -    # we no longer support a per trap target engine ID (https://phabricator.vyos.net/T818) +    # we no longer support a per trap target engine ID (https://vyos.dev/T818)      if config.exists(config_base + ['v3', 'trap-target']):          for target in config.list_nodes(config_base + ['v3', 'trap-target']):              config.delete(config_base + ['v3', 'trap-target', target, 'engineid']) -    # we no longer support a per user engine ID (https://phabricator.vyos.net/T818) +    # we no longer support a per user engine ID (https://vyos.dev/T818)      if config.exists(config_base + ['v3', 'user']):          for user in config.list_nodes(config_base + ['v3', 'user']):              config.delete(config_base + ['v3', 'user', user, 'engineid'])      # we drop TSM support as there seem to be no users and this code is untested -    # https://phabricator.vyos.net/T1769 +    # https://vyos.dev/T1769      if config.exists(config_base + ['v3', 'tsm']):          config.delete(config_base + ['v3', 'tsm']) diff --git a/src/migration-scripts/system/25-to-26 b/src/migration-scripts/system/25-to-26 new file mode 100755 index 000000000..615274430 --- /dev/null +++ b/src/migration-scripts/system/25-to-26 @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program.  If not, see <http://www.gnu.org/licenses/>. +# +# syslog: migrate deprecated CLI options +#         - protocols -> local7 +#         - security -> auth + +from sys import exit, argv +from vyos.configtree import ConfigTree + +if (len(argv) < 1): +    print("Must specify file name!") +    exit(1) + +file_name = argv[1] +with open(file_name, 'r') as f: +    config_file = f.read() + +base = ['system', 'syslog'] +config = ConfigTree(config_file) + +if not config.exists(base): +    exit(0) + +def rename_facilities(config, base_tree, facility, facility_new) -> None: +    if config.exists(base + [base_tree, 'facility', facility]): +        # do not overwrite already existing replacement facility +        if not config.exists(base + [base_tree, 'facility', facility_new]): +            config.rename(base + [base_tree, 'facility', facility], facility_new) +        else: +            # delete old duplicate facility config +            config.delete(base + [base_tree, 'facility', facility]) + +# +# Rename protocols and securityy facility to common ones +# +replace = { +    'protocols' : 'local7', +    'security' : 'auth' +} +for facility, facility_new in replace.items(): +    rename_facilities(config, 'console', facility, facility_new) +    rename_facilities(config, 'global', facility, facility_new) + +    if config.exists(base + ['host']): +        for host in config.list_nodes(base + ['host']): +            rename_facilities(config, f'host {host}', facility, facility_new) + +# +# It makes no sense to configure udp/tcp transport per individual facility +# +if config.exists(base + ['host']): +    for host in config.list_nodes(base + ['host']): +        protocol = None +        for facility in config.list_nodes(base + ['host', host, 'facility']): +            tmp_path = base + ['host', host, 'facility', facility, 'protocol'] +            if config.exists(tmp_path): +                # We can only change the first one +                if protocol == None: +                    protocol = config.return_value(tmp_path) +                    config.set(base + ['host', host, 'protocol'], value=protocol) +                config.delete(tmp_path) + +try: +    with open(file_name, 'w') as f: +        f.write(config.to_string()) +except OSError as e: +    print(f'Failed to save the modified config: {e}') +    exit(1)  | 
