486b023f77d488a6abbd425b4f742122425a9b6f
[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 Optional, Dict, Union
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=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 = (
81             data.alarmState if data and data.alarmState else 0
82         )
83         self._usageState = (
84             data.usageState if data and data.usageState else UsageState.UNUSED
85         )
86         self._utilization = (
87             data.utilization if data and data.utilization else 0
88         )
89
90     @property
91     def id(self):
92         return self._id
93
94     @id.setter
95     def id(self, value):
96         self._id = value
97
98     @property
99     def name(self):
100         return self._name
101
102     @name.setter
103     def name(self, value):
104         self._name = value
105
106     @property
107     def administrativeState(self):
108         return self._administrativeState
109
110     @administrativeState.setter
111     def administrativeState(self, value):
112         self._administrativeState = value
113
114     @property
115     def operationalState(self):
116         return self._operationalState
117
118     @operationalState.setter
119     def operationalState(self, value):
120         self._operationalState = value
121
122     @property
123     def lifeCycleState(self):
124         return self._lifeCycleState
125
126     @lifeCycleState.setter
127     def lifeCycleState(self, value):
128         self._lifeCycleState = value
129
130     @property
131     def alarmState(self):
132         return self._alarmState
133
134     @alarmState.setter
135     def alarmState(self, value):
136         self._alarmState = value
137
138     @property
139     def usageState(self):
140         return self._usageState
141
142     @usageState.setter
143     def usageState(self, value):
144         self._usageState = value
145
146     @property
147     def utilization(self):
148         return self._utilization
149
150     @utilization.setter
151     def utilization(self, value):
152         self._utilization = value
153
154     def json(self):
155         return {
156             "id": self.id,
157             "name": self.name,
158             "administrativeState": self.administrativeState.value,
159             "operationalState": self.operationalState.value,
160             "lifeCycleState": self.lifeCycleState.value,
161             "alarmState": self.alarmState,
162             "usageState": self.usageState.value,
163             "utilization": self.utilization,
164         }
165
166     def __str__(self):
167         return str(self.json())