From 5b836709a15e4f6a8775e5dc26609febd5bc2480 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 2 Aug 2019 17:27:25 +0200 Subject: [bridge] T1156: support adding and removing bridge member interfaces This is the new syntax bridge br0 { member { interface eth0 { cost 10 } interface eth1 { cost 11 } } } --- src/migration-scripts/interfaces/0-to-1 | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 src/migration-scripts/interfaces/0-to-1 (limited to 'src/migration-scripts/interfaces') diff --git a/src/migration-scripts/interfaces/0-to-1 b/src/migration-scripts/interfaces/0-to-1 new file mode 100755 index 000000000..1c6119d86 --- /dev/null +++ b/src/migration-scripts/interfaces/0-to-1 @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 + +# 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 + +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 = ['interfaces', 'bridge'] + +# +# make stp and igmp-snooping nodes valueless +# +for br in config.list_nodes(base): + # STP: check if enabled + stp_val = config.return_value(base + [br, 'stp']) + # STP: delete node with old syntax + config.delete(base + [br, 'stp']) + # STP: set new node - if enabled + if stp_val == "true": + config.set(base + [br, 'stp'], value=None) + + + # igmp-snooping: check if enabled + igmp_val = config.return_value(base + [br, 'igmp-snooping', 'querier']) + # igmp-snooping: delete node with old syntax + config.delete(base + [br, 'igmp-snooping', 'querier']) + # igmp-snooping: set new node - if enabled + if igmp_val == "enable": + config.set(base + [br, 'igmp-snooping', 'querier'], value=None) + +# +# move interface based bridge-group to actual bridge (de-nest) +# +bridge_types = ['bonding', 'ethernet', 'l2tpv3', 'openvpn', 'vxlan', 'wireless'] +for type in bridge_types: + if not config.exists(['interfaces', type]): + continue + + for intf in config.list_nodes(['interfaces', type]): + # check if bridge-group exists + if config.exists(['interfaces', type, intf, 'bridge-group']): + bridge = config.return_value(['interfaces', type, intf, 'bridge-group', 'bridge']) + + # create new bridge member interface + config.set(base + [bridge, 'member', 'interface', intf]) + # format as tag node to avoid loading problems + config.set_tag(base + [bridge, 'member', 'interface']) + + # cost: migrate if configured + if config.exists(['interfaces', type, intf, 'bridge-group', 'cost']): + cost = config.return_value(['interfaces', type, intf, 'bridge-group', 'cost']) + # set new node + config.set(base + [bridge, 'member', 'interface', intf, 'cost'], value=cost) + + if config.exists(['interfaces', type, intf, 'bridge-group', 'priority']): + priority = config.return_value(['interfaces', type, intf, 'bridge-group', 'priority']) + # set new node + config.set(base + [bridge, 'member', 'interface', intf, 'priority'], value=priority) + + # Delete the old bridge-group assigned to an interface + config.delete(['interfaces', type, intf, 'bridge-group']) + + 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) -- cgit v1.2.3 From 74cd9b982a3e965d422bce84375f6283088ec593 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 4 Aug 2019 21:50:10 +0200 Subject: [bridge] T1156: rename igmp-snooping node to igmp --- interface-definitions/interfaces-bridge.xml | 6 +++--- src/conf_mode/interface-bridge.py | 4 ++-- src/migration-scripts/interfaces/0-to-1 | 3 +-- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'src/migration-scripts/interfaces') diff --git a/interface-definitions/interfaces-bridge.xml b/interface-definitions/interfaces-bridge.xml index af19d9438..16fd8b14c 100644 --- a/interface-definitions/interfaces-bridge.xml +++ b/interface-definitions/interfaces-bridge.xml @@ -139,14 +139,14 @@ Bridge Hello interval must be between 1 and 10 seconds - + - IGMP snooping settings + Internet Group Management Protocol (IGMP) settings - Enable or disable IGMP querier + Enable IGMP querier diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 1c9c6ec10..4f1cbd17c 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -121,8 +121,8 @@ def get_config(): if conf.exists('hello-time'): bridge['hello_time'] = conf.return_value('hello-time') - # Enable or disable IGMP querier - if conf.exists('igmp-snooping querier'): + # Enable Internet Group Management Protocol (IGMP) querier + if conf.exists('igmp querier'): bridge['igmp_querier'] = 1 # ARP cache entry timeout in seconds diff --git a/src/migration-scripts/interfaces/0-to-1 b/src/migration-scripts/interfaces/0-to-1 index 1c6119d86..b8e190f2c 100755 --- a/src/migration-scripts/interfaces/0-to-1 +++ b/src/migration-scripts/interfaces/0-to-1 @@ -33,14 +33,13 @@ for br in config.list_nodes(base): if stp_val == "true": config.set(base + [br, 'stp'], value=None) - # igmp-snooping: check if enabled igmp_val = config.return_value(base + [br, 'igmp-snooping', 'querier']) # igmp-snooping: delete node with old syntax config.delete(base + [br, 'igmp-snooping', 'querier']) # igmp-snooping: set new node - if enabled if igmp_val == "enable": - config.set(base + [br, 'igmp-snooping', 'querier'], value=None) + config.set(base + [br, 'igmp', 'querier'], value=None) # # move interface based bridge-group to actual bridge (de-nest) -- cgit v1.2.3