python 3.10 type definitions
[oam.git] / code / network-generator / model / python / top.py
1 # Copyright 2023 highstreet technologies GmbH
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 #!/usr/bin/python
16
17 """
18 An abstract Class for all classes
19 """
20 import uuid
21 from abc import ABC, abstractmethod
22 from typing import Any
23 from model.python.type_definitions import (
24     AddressType,
25     AdministrativeState,
26     OperationalState,
27     UsageState,
28     Utilization,
29     LifeCycleState,
30     AlarmState,
31 )
32 from model.python.geo_location import GeoLocation
33
34
35 # Define the ITop interface
36 class ITop:
37     def __init__(
38         self,
39         id: str = None,
40         name: str = None,
41         administrativeState: AdministrativeState = None,
42         operationalState: OperationalState = None,
43         lifeCycleState: LifeCycleState = None,
44         alarmState: AlarmState = None,
45         usageState: UsageState = None,
46         utilization: Utilization = None,
47     ):
48         self.id = id
49         self.name = name
50         self.administrativeState = administrativeState
51         self.operationalState = operationalState
52         self.lifeCycleState = lifeCycleState
53         self.alarmState = alarmState
54         self.usageState = usageState
55         self.utilization = utilization
56
57
58 # Define the Top class
59 class Top(ABC, ITop):
60     def __init__(self, data: [dict[str, Any] | None] = None):
61         self._id = data.id if data and data.id else str(uuid.uuid4())
62         self._name = (
63             data.name if data and data.name else " ".join(["Name", "of", self._id])
64         )
65         self._administrativeState = (
66             data.administrativeState
67             if data and data.administrativeState
68             else AdministrativeState.LOCKED
69         )
70         self._operationalState = (
71             data.operationalState
72             if data and data.operationalState
73             else OperationalState.DISABLED
74         )
75         self._lifeCycleState = (
76             data.lifeCycleState
77             if data and data.lifeCycleState
78             else LifeCycleState.PLANNED
79         )
80         self._alarmState = data.alarmState if data and data.alarmState else 0
81         self._usageState = (
82             data.usageState if data and data.usageState else UsageState.UNUSED
83         )
84         self._utilization = data.utilization if data and data.utilization else 0
85
86     @property
87     def id(self) -> str:
88         return self._id
89
90     @id.setter
91     def id(self, value: str):
92         self._id = value
93
94     @property
95     def name(self) -> str:
96         return self._name
97
98     @name.setter
99     def name(self, value: str):
100         self._name = value
101
102     @property
103     def administrativeState(self) -> AdministrativeState:
104         return self._administrativeState
105
106     @administrativeState.setter
107     def administrativeState(self, value: AdministrativeState):
108         self._administrativeState = value
109
110     @property
111     def operationalState(self) -> OperationalState:
112         return self._operationalState
113
114     @operationalState.setter
115     def operationalState(self, value: OperationalState):
116         self._operationalState = value
117
118     @property
119     def lifeCycleState(self) -> LifeCycleState:
120         return self._lifeCycleState
121
122     @lifeCycleState.setter
123     def lifeCycleState(self, value: LifeCycleState):
124         self._lifeCycleState = value
125
126     @property
127     def alarmState(self) -> AlarmState:
128         return self._alarmState
129
130     @alarmState.setter
131     def alarmState(self, value: AlarmState):
132         self._alarmState = value
133
134     @property
135     def usageState(self) -> UsageState:
136         return self._usageState
137
138     @usageState.setter
139     def usageState(self, value: UsageState):
140         self._usageState = value
141
142     @property
143     def utilization(self) -> Utilization:
144         return self._utilization
145
146     @utilization.setter
147     def utilization(self, value: Utilization):
148         self._utilization = value
149
150     def json(self) -> dict[str, Any]:
151         return {
152             "id": self.id,
153             "name": self.name,
154             "administrativeState": self.administrativeState.value,
155             "operationalState": self.operationalState.value,
156             "lifeCycleState": self.lifeCycleState.value,
157             "alarmState": self.alarmState,
158             "usageState": self.usageState.value,
159             "utilization": self.utilization,
160         }
161
162     def __str__(self) -> str:
163         return str(self.json())