Coverage for birdplan/bird_config/__init__.py: 86%

74 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"""Bird configuration package.""" 

20 

21from typing import Any, Dict, List, Optional 

22 

23from .globals import BirdConfigGlobals 

24from .sections import Sections 

25from .sections.constants import SectionConstants 

26from .sections.protocols import SectionProtocols 

27from .sections.tables import SectionTables 

28 

29__all__ = ["BirdConfig"] 

30 

31 

32class BirdConfig: 

33 """BirdConfig is responsible for configuring Bird.""" 

34 

35 _birdconfig_globals: BirdConfigGlobals 

36 

37 _sections: Sections 

38 

39 def __init__(self, test_mode: bool = False) -> None: 

40 """Initialize the object.""" 

41 self._birdconfig_globals = BirdConfigGlobals(test_mode=test_mode) 

42 self._sections = Sections(self.birdconfig_globals) 

43 

44 def get_config(self) -> List[str]: 

45 """Return the Bird configuration.""" 

46 

47 self.sections.configure() 

48 

49 return self.sections.conf.lines 

50 

51 @property 

52 def birdconfig_globals(self) -> BirdConfigGlobals: 

53 """Return our global configuration options.""" 

54 return self._birdconfig_globals 

55 

56 # HELPERS 

57 

58 @property 

59 def log_file(self) -> Optional[str]: 

60 """Return the log file to use.""" 

61 return self.birdconfig_globals.log_file 

62 

63 @log_file.setter 

64 def log_file(self, log_file: str) -> None: 

65 """Set the log file to use.""" 

66 self.birdconfig_globals.log_file = log_file 

67 

68 @property 

69 def debug(self) -> bool: 

70 """Return debugging mode.""" 

71 return self.birdconfig_globals.debug 

72 

73 @debug.setter 

74 def debug(self, debug: bool) -> None: 

75 """Set debugging mode.""" 

76 self.birdconfig_globals.debug = debug 

77 

78 @property 

79 def state(self) -> Dict[str, Any]: 

80 """Return the state to use.""" 

81 return self.birdconfig_globals.state 

82 

83 @state.setter 

84 def state(self, state: Dict[str, Any]) -> None: 

85 """Set the log file to use.""" 

86 self.birdconfig_globals.state = state 

87 

88 @property 

89 def test_mode(self) -> bool: 

90 """Return if we're running in test mode.""" 

91 return self.birdconfig_globals.test_mode 

92 

93 @test_mode.setter 

94 def test_mode(self, test_mode: bool) -> None: 

95 """Set test mode.""" 

96 self.birdconfig_globals.test_mode = test_mode 

97 

98 @property 

99 def router_id(self) -> str: 

100 """Return our router_id.""" 

101 return self.sections.router_id.router_id 

102 

103 @router_id.setter 

104 def router_id(self, router_id: str) -> None: 

105 """Set router_id.""" 

106 self.sections.router_id.router_id = router_id 

107 

108 @property 

109 def vrf(self) -> str: 

110 """Return the vrf to use.""" 

111 return self.birdconfig_globals.vrf 

112 

113 @vrf.setter 

114 def vrf(self, vrf: str) -> None: 

115 """Set the vrf to use.""" 

116 self.birdconfig_globals.vrf = vrf 

117 

118 @property 

119 def routing_table(self) -> int | None: 

120 """Return the routing table to use.""" 

121 return self.birdconfig_globals.routing_table 

122 

123 @routing_table.setter 

124 def routing_table(self, routing_table: int | None) -> None: 

125 """Set the routing table to use.""" 

126 self.birdconfig_globals.routing_table = routing_table 

127 

128 @property 

129 def sections(self) -> Sections: 

130 """Return our sections.""" 

131 return self._sections 

132 

133 @property 

134 def constants(self) -> SectionConstants: 

135 """Return our constants.""" 

136 return self.sections.constants 

137 

138 @property 

139 def tables(self) -> SectionTables: 

140 """Return our master config.""" 

141 return self.sections.tables 

142 

143 @property 

144 def protocols(self) -> SectionProtocols: 

145 """Return our protocols.""" 

146 return self.sections.protocols