diff options
-rwxr-xr-x | src/conf_mode/interface-bridge.py | 58 | ||||
-rwxr-xr-x | src/migration-scripts/interfaces/0-to-1 | 120 |
2 files changed, 91 insertions, 87 deletions
diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 93eb3839c..543349e7b 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -30,7 +30,7 @@ default_config_data = { 'address': [], 'address_remove': [], 'aging': '300', - 'br_name': '', + 'arp_cache_timeout_ms': '30000', 'description': '', 'deleted': False, 'dhcp_client_id': '', @@ -42,7 +42,7 @@ default_config_data = { 'forwarding_delay': '15', 'hello_time': '2', 'igmp_querier': 0, - 'arp_cache_timeout_ms': '30000', + 'intf': '', 'mac' : '', 'max_age': '20', 'member': [], @@ -66,17 +66,17 @@ def get_config(): # determine tagNode instance try: - bridge['br_name'] = os.environ['VYOS_TAGNODE_VALUE'] + bridge['intf'] = os.environ['VYOS_TAGNODE_VALUE'] except KeyError as E: print("Interface not specified") # Check if bridge has been removed - if not conf.exists('interfaces bridge ' + bridge['br_name']): + if not conf.exists('interfaces bridge ' + bridge['intf']): bridge['deleted'] = True return bridge # set new configuration level - conf.set_level('interfaces bridge ' + bridge['br_name']) + conf.set_level('interfaces bridge ' + bridge['intf']) # retrieve configured interface addresses if conf.exists('address'): @@ -184,7 +184,7 @@ def verify(bridge): conf = Config() for br in conf.list_nodes('interfaces bridge'): # it makes no sense to verify ourself in this case - if br == bridge['br_name']: + if br == bridge['intf']: continue for intf in bridge['member']: @@ -207,91 +207,91 @@ def apply(bridge): cmd = '' if bridge['deleted']: # bridges need to be shutdown first - cmd += 'ip link set dev "{}" down'.format(bridge['br_name']) + cmd += 'ip link set dev "{}" down'.format(bridge['intf']) cmd += ' && ' # delete bridge - cmd += 'brctl delbr "{}"'.format(bridge['br_name']) + cmd += 'brctl delbr "{}"'.format(bridge['intf']) subprocess_cmd(cmd) else: # create bridge if it does not exist - if not os.path.exists("/sys/class/net/" + bridge['br_name']): + if not os.path.exists("/sys/class/net/" + bridge['intf']): # create bridge interface - cmd += 'brctl addbr "{}"'.format(bridge['br_name']) + cmd += 'brctl addbr "{}"'.format(bridge['intf']) cmd += ' && ' # activate "UP" the interface - cmd += 'ip link set dev "{}" up'.format(bridge['br_name']) + cmd += 'ip link set dev "{}" up'.format(bridge['intf']) cmd += ' && ' # set ageing time - cmd += 'brctl setageing "{}" "{}"'.format(bridge['br_name'], bridge['aging']) + cmd += 'brctl setageing "{}" "{}"'.format(bridge['intf'], bridge['aging']) cmd += ' && ' # set bridge forward delay - cmd += 'brctl setfd "{}" "{}"'.format(bridge['br_name'], bridge['forwarding_delay']) + cmd += 'brctl setfd "{}" "{}"'.format(bridge['intf'], bridge['forwarding_delay']) cmd += ' && ' # set hello time - cmd += 'brctl sethello "{}" "{}"'.format(bridge['br_name'], bridge['hello_time']) + cmd += 'brctl sethello "{}" "{}"'.format(bridge['intf'], bridge['hello_time']) cmd += ' && ' # set max message age - cmd += 'brctl setmaxage "{}" "{}"'.format(bridge['br_name'], bridge['max_age']) + cmd += 'brctl setmaxage "{}" "{}"'.format(bridge['intf'], bridge['max_age']) cmd += ' && ' # set bridge priority - cmd += 'brctl setbridgeprio "{}" "{}"'.format(bridge['br_name'], bridge['priority']) + cmd += 'brctl setbridgeprio "{}" "{}"'.format(bridge['intf'], bridge['priority']) cmd += ' && ' # turn stp on/off - cmd += 'brctl stp "{}" "{}"'.format(bridge['br_name'], bridge['stp']) + cmd += 'brctl stp "{}" "{}"'.format(bridge['intf'], bridge['stp']) for intf in bridge['member_remove']: # remove interface from bridge cmd += ' && ' - cmd += 'brctl delif "{}" "{}"'.format(bridge['br_name'], intf) + cmd += 'brctl delif "{}" "{}"'.format(bridge['intf'], intf) for intf in bridge['member']: # add interface to bridge # but only if it is not yet member of this bridge - if not os.path.exists('/sys/devices/virtual/net/' + bridge['br_name'] + '/brif/' + intf['name']): + if not os.path.exists('/sys/devices/virtual/net/' + bridge['intf'] + '/brif/' + intf['name']): cmd += ' && ' - cmd += 'brctl addif "{}" "{}"'.format(bridge['br_name'], intf['name']) + cmd += 'brctl addif "{}" "{}"'.format(bridge['intf'], intf['name']) # set bridge port cost if intf['cost']: cmd += ' && ' - cmd += 'brctl setpathcost "{}" "{}" "{}"'.format(bridge['br_name'], intf['name'], intf['cost']) + cmd += 'brctl setpathcost "{}" "{}" "{}"'.format(bridge['intf'], intf['name'], intf['cost']) # set bridge port priority if intf['priority']: cmd += ' && ' - cmd += 'brctl setportprio "{}" "{}" "{}"'.format(bridge['br_name'], intf['name'], intf['priority']) + cmd += 'brctl setportprio "{}" "{}" "{}"'.format(bridge['intf'], intf['name'], intf['priority']) subprocess_cmd(cmd) # Change interface MAC address if bridge['mac']: - VyIfconfig.set_mac_address(bridge['br_name'], bridge['mac']) + VyIfconfig.set_mac_address(bridge['intf'], bridge['mac']) # update interface description used e.g. within SNMP - VyIfconfig.set_description(bridge['br_name'], bridge['description']) + VyIfconfig.set_description(bridge['intf'], bridge['description']) # Ignore link state changes? - VyIfconfig.set_link_detect(bridge['br_name'], bridge['disable_link_detect']) + VyIfconfig.set_link_detect(bridge['intf'], bridge['disable_link_detect']) # enable or disable IGMP querier - VyIfconfig.set_multicast_querier(bridge['br_name'], bridge['igmp_querier']) + VyIfconfig.set_multicast_querier(bridge['intf'], bridge['igmp_querier']) # ARP cache entry timeout in seconds - VyIfconfig.set_arp_cache_timeout(bridge['br_name'], bridge['arp_cache_timeout_ms']) + VyIfconfig.set_arp_cache_timeout(bridge['intf'], bridge['arp_cache_timeout_ms']) # Configure interface address(es) for addr in bridge['address_remove']: - VyIfconfig.remove_interface_address(bridge['br_name'], addr) + VyIfconfig.remove_interface_address(bridge['intf'], addr) for addr in bridge['address']: - VyIfconfig.add_interface_address(bridge['br_name'], addr) + VyIfconfig.add_interface_address(bridge['intf'], addr) return None diff --git a/src/migration-scripts/interfaces/0-to-1 b/src/migration-scripts/interfaces/0-to-1 index b8e190f2c..38f2bd8f5 100755 --- a/src/migration-scripts/interfaces/0-to-1 +++ b/src/migration-scripts/interfaces/0-to-1 @@ -21,61 +21,65 @@ with open(file_name, 'r') as f: 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', '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) +if not config.exists(base): + # Nothing to do + sys.exit(0) +else: + # + # 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', '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) |