summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py44
-rwxr-xr-xsrc/migration-scripts/interfaces/16-to-1752
2 files changed, 80 insertions, 16 deletions
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py
index 642738b09..a3f32fd2d 100755
--- a/src/conf_mode/protocols_bgp.py
+++ b/src/conf_mode/protocols_bgp.py
@@ -60,12 +60,22 @@ def verify(bgp):
if neigh not in asn_config:
continue
- for neighbor, config in asn_config[neigh].items():
- if 'remote_as' not in config and 'peer_group' not in config:
- raise ConfigError(f'BGP remote-as must be specified for "{neighbor}"!')
+ #for neighbor, config in asn_config[neigh].items():
+ '''
+ # These checks need to be modified. Because peer-group can be declared without 'remote-as'.
+ # When 'remote-as' configured for specific neighbor in peer-group. For example
+ #
- if 'remote_as' in config and 'peer_group' in config:
- raise ConfigError(f'BGP peer-group member "{neighbor}" cannot override remote-as of peer-group!')
+ set protocols nbgp 65001 neighbor 100.64.0.2 peer-group 'FOO'
+ set protocols nbgp 65001 neighbor 100.64.0.2 remote-as '65002'
+ set protocols nbgp 65001 peer-group FOO
+
+ '''
+ #if 'remote_as' not in config and 'peer_group' not in config:
+ # raise ConfigError(f'BGP remote-as must be specified for "{neighbor}"!')
+
+ #if 'remote_as' in config and 'peer_group' in config:
+ # raise ConfigError(f'BGP peer-group member "{neighbor}" cannot override remote-as of peer-group!')
return None
@@ -87,24 +97,26 @@ def generate(bgp):
def apply(bgp):
# Save original configuration prior to starting any commit actions
- frr_cfg = {}
- frr_cfg['original_config'] = frr.get_configuration(daemon='bgpd')
- frr_cfg['modified_config'] = frr.replace_section(frr_cfg['original_config'], bgp['new_frr_config'], from_re='router bgp .*')
+ frr_cfg = frr.FRRConfig()
+ frr_cfg.load_configuration(daemon='bgpd')
+ frr_cfg.modify_section(f'router bgp \S+', '')
+ frr_cfg.add_before(r'(ip prefix-list .*|route-map .*|line vty)', bgp['new_frr_config'])
+ frr_cfg.commit_configuration(daemon='bgpd')
+
+ # If FRR config is blank, rerun the blank commit x times due to frr-reload
+ # behavior/bug not properly clearing out on one commit.
+ if bgp['new_frr_config'] == '':
+ for a in range(5):
+ frr_cfg.commit_configuration(daemon='bgpd')
# Debugging
+ '''
print('')
print('--------- DEBUGGING ----------')
print(f'Existing config:\n{frr_cfg["original_config"]}\n\n')
print(f'Replacement config:\n{bgp["new_frr_config"]}\n\n')
print(f'Modified config:\n{frr_cfg["modified_config"]}\n\n')
-
- # FRR mark configuration will test for syntax errors and throws an
- # exception if any syntax errors is detected
- frr.mark_configuration(frr_cfg['modified_config'])
-
- # Commit resulting configuration to FRR, this will throw CommitError
- # on failure
- frr.reload_configuration(frr_cfg['modified_config'], daemon='bgpd')
+ '''
return None
diff --git a/src/migration-scripts/interfaces/16-to-17 b/src/migration-scripts/interfaces/16-to-17
new file mode 100755
index 000000000..a6b4c7663
--- /dev/null
+++ b/src/migration-scripts/interfaces/16-to-17
@@ -0,0 +1,52 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2020 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/>.
+
+# Command line migration of port mirroring
+# https://phabricator.vyos.net/T3089
+
+import sys
+from vyos.configtree import ConfigTree
+
+if __name__ == '__main__':
+ 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', 'ethernet']
+ if not config.exists(base):
+ # Nothing to do
+ sys.exit(0)
+
+ for interface in config.list_nodes(base):
+ mirror_old_base = base + [interface, 'mirror']
+ if config.exists(mirror_old_base):
+ intf = config.return_values(mirror_old_base)
+ if config.exists(mirror_old_base):
+ config.delete(mirror_old_base)
+ config.set(mirror_old_base + ['ingress'],intf[0])
+
+ 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)