diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-02-23 15:32:51 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-02-23 15:32:51 +0100 |
commit | f4e60d02df629f903fc677ad519fecc3f2e2b7be (patch) | |
tree | 314508ae5e9222e9daf75ba744d114fc76b09b5b /src/migration-scripts/interfaces/4-to-5 | |
parent | 373fcb829e95b52c6edd5fafd087012988d66c07 (diff) | |
parent | 9621e4b7552df43876f153db1d1156ad8c4ba72c (diff) | |
download | vyos-1x-f4e60d02df629f903fc677ad519fecc3f2e2b7be.tar.gz vyos-1x-f4e60d02df629f903fc677ad519fecc3f2e2b7be.zip |
Merge branch 'pppoe-rewrite' of https://github.com/c-po/vyos-1x into current
* 'pppoe-rewrite' of https://github.com/c-po/vyos-1x: (23 commits)
pppoe: T2055: do not try to start a deleted dialer interface
pppoe: T1318: declutter name-server CLI nodes
pppoe: T2055: remove router-advert node in client interface
pppoe: T1318: migrate user-id and password nodes under an authentication node
pppoe: T1318: rename link to source-interface
pppoe: T1318: use include files for disable and descriptionx
pppoe: T1318: rephrase help text on default-route
interface-definitions: include: disable: rephrase help text
pppoe: T1318: extend migrator for firewall, qos and ip routing nodes
pppoe: T1318: proper delete old interfaces in migrator
pppoe: T1318: increase priority so PPPoE is run after bond interfaces
pppoe: T1318: fix migrator and add missing link statement
pppoe: T1318: use lists rather then strings on Config()
pppoe: T1318: support interface description
pppoe: T1318: remove obsolete ipv6-up.d script
pppoe: T1318: add op-mode commands for link information
pppoe: T1318: use systemd to manage connection
pppoe: T1318: remove process startup debug output
pppoe: T1318: move process startup to apply()
pppoe: T1318: "link" option is mandatory
...
Diffstat (limited to 'src/migration-scripts/interfaces/4-to-5')
-rwxr-xr-x | src/migration-scripts/interfaces/4-to-5 | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/migration-scripts/interfaces/4-to-5 b/src/migration-scripts/interfaces/4-to-5 new file mode 100755 index 000000000..2a42c60ff --- /dev/null +++ b/src/migration-scripts/interfaces/4-to-5 @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 + +# De-nest PPPoE interfaces +# Migrate boolean nodes to valueless + +import sys +from vyos.configtree import ConfigTree + +def migrate_dialer(config, tree, intf): + for pppoe in config.list_nodes(tree): + # assemble string, 0 -> pppoe0 + new_base = ['interfaces', 'pppoe'] + pppoe_base = new_base + ['pppoe' + pppoe] + config.set(new_base) + # format as tag node to avoid loading problems + config.set_tag(new_base) + + # Copy the entire old node to the new one before migrating individual + # parts + config.copy(tree + [pppoe], pppoe_base) + + # Instead of letting the user choose between auto and none + # where auto is default, it makes more sesne to just offer + # an option to disable the default behavior (declutter CLI) + if config.exists(pppoe_base + ['name-server']): + tmp = config.return_value(pppoe_base + ['name-server']) + if tmp == "none": + config.set(pppoe_base + ['no-peer-dns']) + config.delete(pppoe_base + ['name-server']) + + # Migrate user-id and password nodes under an 'authentication' + # node + if config.exists(pppoe_base + ['user-id']): + user = config.return_value(pppoe_base + ['user-id']) + config.set(pppoe_base + ['authentication', 'user'], value=user) + config.delete(pppoe_base + ['user-id']) + + if config.exists(pppoe_base + ['password']): + pwd = config.return_value(pppoe_base + ['password']) + config.set(pppoe_base + ['authentication', 'password'], value=pwd) + config.delete(pppoe_base + ['password']) + + # remove enable-ipv6 node and rather place it under ipv6 node + if config.exists(pppoe_base + ['enable-ipv6']): + config.set(pppoe_base + ['ipv6', 'enable']) + config.delete(pppoe_base + ['enable-ipv6']) + + # Source interface migration + config.set(pppoe_base + ['source-interface'], value=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 + ipv6_ra = pppoe_base + ['ipv6', 'router-advert'] + if config.exists(ipv6_ra): + config.delete(ipv6_ra) + + +if __name__ == '__main__': + if (len(sys.argv) < 1): + print("Must specify file name!") + exit(1) + + file_name = sys.argv[1] + + with open(file_name, 'r') as f: + config_file = f.read() + + config = ConfigTree(config_file) + pppoe_links = ['bonding', 'ethernet'] + + for link_type in pppoe_links: + if not config.exists(['interfaces', link_type]): + continue + + for interface in config.list_nodes(['interfaces', link_type]): + # check if PPPoE exists + base_if = ['interfaces', link_type, interface] + pppoe_if = base_if + ['pppoe'] + if config.exists(pppoe_if): + for dialer in config.list_nodes(pppoe_if): + migrate_dialer(config, pppoe_if, interface) + + # Delete old PPPoE interface + config.delete(pppoe_if) + + # bail out early if there are no VLAN interfaces to migrate + if not config.exists(base_if + ['vif']): + continue + + # Migrate PPPoE interfaces attached to a VLAN + for vlan in config.list_nodes(base_if + ['vif']): + vlan_if = base_if + ['vif', vlan] + pppoe_if = vlan_if + ['pppoe'] + if config.exists(pppoe_if): + for dialer in config.list_nodes(pppoe_if): + intf = "{}.{}".format(interface, vlan) + migrate_dialer(config, pppoe_if, intf) + + # Delete old PPPoE interface + config.delete(pppoe_if) + + # Add interface description that this is required for PPPoE + if not config.exists(vlan_if + ['description']): + config.set(vlan_if + ['description'], value='PPPoE link interface') + + 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) |