Debian Codegraph @

networking_baremetal/openconfig/interfaces/aggregate.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 from xml.etree import ElementTree
13
14 from networking_baremetal import common
15 from networking_baremetal import constants
16 from networking_baremetal.openconfig.interfaces import types
17 from networking_baremetal.openconfig.vlan import vlan
18
19
20 class InterfacesAggregationConfig:
21
22 NAMESPACE = 'http://openconfig.net/yang/interfaces/aggregate'
23 PARENT = 'aggregation'
24 TAG = 'config'
25
26 def __init__(self,
27 operation: str = constants.NetconfEditConfigOperation.MERGE):
28 self.operation = operation
29 self._lag_type = None
30 self._min_links = None
31
32 @property
33 def operation(self):
34 """RFC 6241 - <edit-config> operation attribute"""
35 return self._operation.value if self._operation else None
36
37 @operation.setter
38 def operation(self, value):
39 """RFC 6241 - <edit-config> operation attribute"""
40 if isinstance(value, constants.NetconfEditConfigOperation):
41 self._operation = value
42 elif isinstance(value, str):
43 self._operation = constants.NetconfEditConfigOperation(value)
44 else:
45 raise TypeError('Invalid type {} for config operation attribute.'
46 .format(type(value)))
47
48 @operation.deleter
49 def operation(self):
50 self._operation = None
51
52 @property
53 def lag_type(self):
54 return self._lag_type.value if self._lag_type else None
55
56 @lag_type.setter
57 def lag_type(self, value: str):
58 """the type of LAG, i.e., how it is configured / maintained"""
59 self._lag_type = types.AggregationType(value)
60
61 @lag_type.deleter
62 def lag_type(self):
63 self._lag_type = None
64
65 @property
66 def min_links(self):
67 return self._min_links
68
69 @min_links.setter
70 def min_links(self, value: int):
71 self._min_links = value
72
73 @min_links.deleter
74 def min_links(self):
75 self._min_links = None
76
77 def to_xml_element(self):
78 """Create XML Element
79
80 :return: ElementTree Element with SubElements
81 """
82 elem = ElementTree.Element(self.TAG)
83 if self.operation:
84 elem.set('operation', self.operation)
85 if self.lag_type is not None:
86 common.txt_subelement(elem, 'lag-type', self.lag_type)
87 if self.min_links is not None:
88 common.txt_subelement(elem, 'min-links', str(self.min_links))
89 return elem
90
91
92 class InterfacesAggregation:
93 """Options for logical interfaces representing aggregates"""
94
95 NAMESPACE = 'http://openconfig.net/yang/interfaces/aggregate'
96 PARENT = 'interface'
97 TAG = 'aggregation'
98
99 def __init__(self):
100 self._switched_vlan = vlan.VlanSwitchedVlan()
101 self._config = InterfacesAggregationConfig()
102
103 @property
104 def switched_vlan(self):
105 return self._switched_vlan
106
107 @switched_vlan.setter
108 def switched_vlan(self, value):
109 if not isinstance(value, vlan.VlanSwitchedVlan):
110 raise TypeError('switched_vlan must be '
111 'OpenConfigVlanSwitchedVlan, got {}'
112 .format(type(value)))
113 self._switched_vlan = value
114
115 @switched_vlan.deleter
116 def switched_vlan(self):
117 self._switched_vlan = None
118
119 @property
120 def config(self):
121 return self._config
122
123 @config.setter
124 def config(self, value):
125 if not isinstance(value, InterfacesAggregationConfig):
126 raise TypeError('config must be InterfacesAggregationConfig, got '
127 '{}'.format(type(value)))
128 self._config = value
129
130 @config.deleter
131 def config(self):
132 self._config = None
133
134 def to_xml_element(self):
135 """Create XML Element
136
137 :return: ElementTree Element with SubElements
138 """
139 elem = ElementTree.Element(self.TAG)
140 elem.set('xmlns', self.NAMESPACE)
141 if self.config:
142 elem.append(self.config.to_xml_element())
143 if self.switched_vlan:
144 elem.append(self.switched_vlan.to_xml_element())
145 return elem