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

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/>. 

18 

19"""BirdPlan commandline options for "ospf interface ecmp-weight remove".""" 

20 

21import argparse 

22from typing import Any, Dict 

23 

24from ......cmdline import BirdPlanCommandLine, BirdPlanCommandlineResult 

25from ....cmdline_plugin import BirdPlanCmdlinePluginBase 

26 

27__all__ = ["BirdPlanCmdlineOSPFInterfaceECMPWeightRemove"] 

28 

29 

30class BirdPlanCmdlineOSPFInterfaceECMPWeightRemove(BirdPlanCmdlinePluginBase): 

31 """BirdPlan "ospf interface ecmp-weight remove" command.""" 

32 

33 def __init__(self) -> None: 

34 """Initialize object.""" 

35 

36 super().__init__() 

37 

38 # Plugin setup 

39 self.plugin_description = "birdplan ospf interface ecmp-weight remove" 

40 self.plugin_order = 40 

41 

42 def register_parsers(self, args: Dict[str, Any]) -> None: 

43 """ 

44 Register commandline parsers. 

45 

46 Parameters 

47 ---------- 

48 args : Dict[str, Any] 

49 Method argument(s). 

50 

51 """ 

52 

53 plugins = args["plugins"] 

54 

55 parent_subparsers = plugins.call_plugin("birdplan.plugins.cmdline.ospf.interface.ecmp_weight", "get_subparsers", {}) 

56 

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 ) 

78 

79 # Set our internal subparser property 

80 self._subparser = subparser 

81 self._subparsers = None 

82 

83 def cmd_ospf_interface_ecmp_weight_remove(self, args: Any) -> Any: 

84 """ 

85 Commandline handler for "ospf interface ecmp-weight remove" action. 

86 

87 Parameters 

88 ---------- 

89 args : Dict[str, Any] 

90 Method argument(s). 

91 

92 """ 

93 

94 if not self._subparser: 

95 raise RuntimeError() 

96 

97 cmdline: BirdPlanCommandLine = args["cmdline"] 

98 

99 # Grab args 

100 area = cmdline.args.area[0] 

101 interface = cmdline.args.interface[0] 

102 

103 # Suppress info output 

104 cmdline.birdplan.birdconf.birdconfig_globals.suppress_info = True 

105 

106 # Load BirdPlan configuration using the cache 

107 cmdline.birdplan_load_config(ignore_irr_changes=True, ignore_peeringdb_changes=True, use_cached=True) 

108 

109 # Check if we're on the console 

110 cmdline.birdplan.state_ospf_remove_interface_ecmp_weight(area, interface) 

111 

112 # Commit BirdPlan our state 

113 cmdline.birdplan_commit_state() 

114 

115 return BirdPlanCommandlineResult(f"Removed OSPF area '{area}' interface '{interface}' ECMP weight override")