Coverage for birdplan/plugins/cmdline/ospf/interface/ecmp_weight/remove.py: 68%
31 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-23 03:27 +0000
1#
2# SPDX-License-Identifier: GPL-3.0-or-later
3#
4# Copyright (c) 2019-2024, AllWorldIT
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
19"""BirdPlan commandline options for "ospf interface ecmp-weight remove"."""
21import argparse
22from typing import Any, Dict
24from ......cmdline import BirdPlanCommandLine, BirdPlanCommandlineResult
25from ....cmdline_plugin import BirdPlanCmdlinePluginBase
27__all__ = ["BirdPlanCmdlineOSPFInterfaceECMPWeightRemove"]
30class BirdPlanCmdlineOSPFInterfaceECMPWeightRemove(BirdPlanCmdlinePluginBase):
31 """BirdPlan "ospf interface ecmp-weight remove" command."""
33 def __init__(self) -> None:
34 """Initialize object."""
36 super().__init__()
38 # Plugin setup
39 self.plugin_description = "birdplan ospf interface ecmp-weight remove"
40 self.plugin_order = 40
42 def register_parsers(self, args: Dict[str, Any]) -> None:
43 """
44 Register commandline parsers.
46 Parameters
47 ----------
48 args : Dict[str, Any]
49 Method argument(s).
51 """
53 plugins = args["plugins"]
55 parent_subparsers = plugins.call_plugin("birdplan.plugins.cmdline.ospf.interface.ecmp_weight", "get_subparsers", {})
57 # CMD: ospf interface ecmp-weight remove
58 subparser = parent_subparsers.add_parser("remove", help="Remove OSPF interface ECMP weight override")
59 subparser.add_argument(
60 "--action",
61 action="store_const",
62 const="ospf_interface_ecmp_weight_remove",
63 default="ospf_interface_ecmp_weight_remove",
64 help=argparse.SUPPRESS,
65 )
66 subparser.add_argument(
67 "area",
68 nargs=1,
69 metavar="AREA",
70 help="Area in which the interface is in",
71 )
72 subparser.add_argument(
73 "interface",
74 nargs=1,
75 metavar="IFACE",
76 help="Interface to remove OSPF ECMP weight override for",
77 )
79 # Set our internal subparser property
80 self._subparser = subparser
81 self._subparsers = None
83 def cmd_ospf_interface_ecmp_weight_remove(self, args: Any) -> Any:
84 """
85 Commandline handler for "ospf interface ecmp-weight remove" action.
87 Parameters
88 ----------
89 args : Dict[str, Any]
90 Method argument(s).
92 """
94 if not self._subparser:
95 raise RuntimeError()
97 cmdline: BirdPlanCommandLine = args["cmdline"]
99 # Grab args
100 area = cmdline.args.area[0]
101 interface = cmdline.args.interface[0]
103 # Suppress info output
104 cmdline.birdplan.birdconf.birdconfig_globals.suppress_info = True
106 # Load BirdPlan configuration using the cache
107 cmdline.birdplan_load_config(ignore_irr_changes=True, ignore_peeringdb_changes=True, use_cached=True)
109 # Check if we're on the console
110 cmdline.birdplan.state_ospf_remove_interface_ecmp_weight(area, interface)
112 # Commit BirdPlan our state
113 cmdline.birdplan_commit_state()
115 return BirdPlanCommandlineResult(f"Removed OSPF area '{area}' interface '{interface}' ECMP weight override")