blob: bb069a569e3cec4b6b7ac73b5d64ca0d03e27a0b [file] [log] [blame]
Rizwan Haider30b33792016-08-18 02:11:18 -04001# models.py - Metro Network Service
2
3from django.db import models
4from core.models import Service
Rizwan Haidereb2cc772016-09-08 12:14:55 -04005from core.models import PlCoreBase
Rizwan Haider30b33792016-08-18 02:11:18 -04006
7METRONETWORK_KIND = "metronetwork"
8SERVICE_NAME = 'metronetwork'
Rizwan Haider65baf552016-09-28 16:47:28 -04009SERVICE_NAME_ELINE_VERBOSE = 'E-Line Service'
10SERVICE_NAME_ELAN_VERBOSE = 'E-LAN Service'
11SERVICE_NAME_ETREE_VERBOSE = 'E-Tree Service'
Rizwan Haider30b33792016-08-18 02:11:18 -040012
Rizwan Haider65baf552016-09-28 16:47:28 -040013class MetroNetworkSystem(PlCoreBase):
Rizwan Haider30b33792016-08-18 02:11:18 -040014
15 class Meta:
Rizwan Haider65baf552016-09-28 16:47:28 -040016 app_label = METRONETWORK_KIND
17 verbose_name = "Metro Network System"
Rizwan Haider30b33792016-08-18 02:11:18 -040018
19 ADMINISTRATIVE_STATE = (
20 ('enabled', 'Enabled'),
21 ('disabled', 'Disabled')
22 )
23
24 OPERATIONALSTATE = (
25 ('active', 'Active'),
26 ('inactive', 'Inactive')
27 )
28
Rizwan Haider65baf552016-09-28 16:47:28 -040029 name = models.CharField(unique=True,
30 verbose_name="Name",
31 max_length=256,
32 editable=True)
33
34 description = models.CharField(verbose_name="Description",
35 max_length=1024,
36 editable=True)
37
Rizwan Haider30b33792016-08-18 02:11:18 -040038 restUrl = models.CharField(verbose_name="Rest URL",
39 max_length=256,
40 editable=True)
41
42 administrativeState = models.CharField(choices=ADMINISTRATIVE_STATE,
43 default='disabled',
44 verbose_name="AdministrativeState",
45 max_length=16,
46 editable=True)
47
48 operationalState = models.CharField(choices=OPERATIONALSTATE,
49 verbose_name="OperationalState",
50 max_length=256,
51 editable=True)
52
53 def __init__(self, *args, **kwargs):
Rizwan Haider65baf552016-09-28 16:47:28 -040054 super(MetroNetworkSystem, self).__init__(*args, **kwargs)
Rizwan Haider30b33792016-08-18 02:11:18 -040055
56 def getAdminstrativeState(self):
57 return self.administrativeState
58
59 def setAdminstrativeState(self, value):
60 self.administrativeState = value
61
62 def getOperationalState(self):
63 return self.operationalState
64
65 def getRestUrl(self):
Rizwan Haidereb2cc772016-09-08 12:14:55 -040066 return self.restUrl
67
68
69class NetworkDevice(PlCoreBase):
70
71 class Meta:
Rizwan Haider65baf552016-09-28 16:47:28 -040072 app_label = METRONETWORK_KIND
73 verbose_name = "Network Device"
Rizwan Haidereb2cc772016-09-08 12:14:55 -040074
75 ADMINISTRATIVE_STATE = (
76 ('enabled', 'Enabled'),
77 ('disabled', 'Disabled'),
78 ('syncrequested', 'SyncRequested'),
79 ('syncinprogress', 'SyncInProgress')
80 )
81
82 AUTH_TYPE = (
83 ('basic', 'Basic'),
84 ('key', 'Key'),
85 ('oauth', 'OAuth')
86 )
87
88 # Leaving out the attributes below for now - not clear we will need them
89 # type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False)
90 # manufacturer = models.CharField(unique=False, verbose_name="Manufacturer", max_length=256, editable=False)
91 # serialNumber = models.CharField(unique=True, verbose_name="Serial Number", max_length=256, editable=False)
92 # chassisId = models.CharField(unique=False, verbose_name="Chassis ID", max_length=256, editable=False)
93
Matteo Scandoloddce4ec2016-09-26 13:11:03 -070094 name = models.CharField(max_length=20, help_text="Device friendly name", null=True, blank=True)
Rizwan Haidereb2cc772016-09-08 12:14:55 -040095 restCtrlUrl = models.CharField(unique=True,
96 verbose_name="RestCtrlURL",
97 max_length=256,
98 editable=True)
99 authType = models.CharField(choices=AUTH_TYPE, verbose_name='Auth Type', max_length=16, editable=True)
100 username = models.CharField(verbose_name='Username', max_length=32, editable=True, blank=True)
101 password = models.CharField(max_length=32, verbose_name='Password', editable=True, blank=True)
102 administrativeState = models.CharField(choices=ADMINISTRATIVE_STATE,
103 default='disabled',
104 verbose_name="AdministrativeState",
105 max_length=16,
106 editable=True)
107 id = models.CharField(unique=True,
108 verbose_name="Element Id",
109 primary_key=True,
110 max_length=256,
111 editable=True)
112
113 def __init__(self, *args, **kwargs):
114 super(NetworkDevice, self).__init__(*args, **kwargs)
115
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400116class NetworkEdgePort(PlCoreBase):
117
118 class Meta:
Rizwan Haider65baf552016-09-28 16:47:28 -0400119 app_label = METRONETWORK_KIND
120 verbose_name = "Network Edge Port"
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400121
122 element = models.ForeignKey(NetworkDevice, on_delete=models.CASCADE)
123 id = models.AutoField(verbose_name="id", primary_key=True, editable=False)
124 pid = models.CharField(unique=True, verbose_name="Port ID", max_length=256, editable=False)
125 bwpCfgCbs = models.IntegerField(verbose_name="Committed Burst Size", editable=False, blank=True)
126 bwpCfgEbs = models.IntegerField(verbose_name="Excess Burst Size", editable=False, blank=True)
127 bwpCfgCir = models.IntegerField(verbose_name="Committed Information Rate", editable=False, blank=True)
128 bwpCfgEir = models.IntegerField(verbose_name="Excess Information Rate", editable=False, blank=True)
129 name = models.CharField(verbose_name="Name", max_length=256, editable=True, blank=True)
130 location = models.CharField(verbose_name="Location", max_length=256, editable=True, blank=True)
131 latlng = models.CharField(verbose_name="Latitude/Longitude", max_length=50, editable=True, blank=True)
132
133 def __init__(self, *args, **kwargs):
134 super(NetworkEdgePort, self).__init__(*args, **kwargs)
135
136 def save(self, *args, **kwargs):
137
138 if self.latlng:
139 try:
140 latlng_value = getattr(self, 'latlng').strip()
141 if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0):
142 lat = latlng_value[1: latlng_value.index(',')].strip()
143 lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip()
144
145 #If lat and lng are not floats, the code below should result in an error.
146 lat_validation = float(lat)
147 lng_validation = float(lng)
148 else:
149 raise ValueError("The lat/lng value is not formatted correctly.")
150 except:
151 raise ValueError("The lat/lng value is not formatted correctly.")
152
153 super(NetworkEdgePort, self).save(*args, **kwargs)
154
Rizwan Haider65baf552016-09-28 16:47:28 -0400155#E-Line Service
156class NetworkEdgeToEdgePointConnection(Service):
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400157
158 class Meta:
159 app_label = SERVICE_NAME
Rizwan Haider65baf552016-09-28 16:47:28 -0400160 verbose_name = SERVICE_NAME_ELINE_VERBOSE
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400161
162 TYPE = (
163 ('direct', 'Direct'),
164 ('tunnel', 'Tunnel'),
165 ('optical', 'Optical'),
166 ('virtual', 'Virtual'),
167 ('Point_To_Point', 'Point To Point')
168 )
169
170 OPERATIONALSTATE = (
171 ('active', 'Active'),
172 ('inactive', 'Inactive')
173 )
174
175 ADMINISTRATIVESTATE = (
176 ('disabled', 'Disabled'),
177 ('activationrequested', 'ActivationRequested'),
178 ('enabled', 'Enabled'),
179 ('invalid', 'Invalid'),
180 ('deactivationrequested', 'DeactivationRequested')
181 )
182
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400183 sid = models.CharField(unique=True, verbose_name="Service ID", max_length=256, editable=True)
184 type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=True)
185 uni1 = models.ForeignKey(NetworkEdgePort,
186 related_name='EdgePointToEdgePointSrc',
187 verbose_name="UNI 1",
188 editable=True,
189 on_delete=models.CASCADE)
190 uni2 = models.ForeignKey(NetworkEdgePort,
191 related_name='EdgePointToEdgePointDst',
192 verbose_name="UNI 2",
193 editable=True,
194 on_delete=models.CASCADE)
195 operstate = models.CharField(choices=OPERATIONALSTATE, verbose_name="OperationalState", max_length=256, editable=True)
196 adminstate = models.CharField(choices=ADMINISTRATIVESTATE, verbose_name="AdministrativeState", max_length=256, editable=True)
197
Rizwan Haider65baf552016-09-28 16:47:28 -0400198 #uni1_createbuffer = models.CharField(max_length=256, default="{}", null=True)
199 #uni2_createbuffer = models.CharField(max_length=256, default="{}", null=True)
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400200
201 def __init__(self, *args, **kwargs):
202 super(NetworkEdgeToEdgePointConnection, self).__init__(*args, **kwargs)
203
Rizwan Haider65baf552016-09-28 16:47:28 -0400204#E-Tree Service
205class NetworkEdgeToMultipointConnection(Service):
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400206
207 class Meta:
208 app_label = SERVICE_NAME
Rizwan Haider65baf552016-09-28 16:47:28 -0400209 verbose_name = SERVICE_NAME_ETREE_VERBOSE
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400210
211 TYPE = (
212 ('vlan', 'VLAN'),
213 ('ip', 'IP'),
214 ('ethernet', 'Ethernet'),
215 )
216
Rizwan Haider65baf552016-09-28 16:47:28 -0400217 OPERATIONALSTATE = (
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400218 ('active', 'Active'),
219 ('inactive', 'Inactive')
220 )
221
Rizwan Haider65baf552016-09-28 16:47:28 -0400222 ADMINISTRATIVESTATE = (
223 ('disabled', 'Disabled'),
224 ('activationrequested', 'ActivationRequested'),
225 ('enabled', 'Enabled'),
226 ('invalid', 'Invalid'),
227 ('deactivationrequested', 'DeactivationRequested')
228 )
229
230 sid = models.CharField(unique=True, verbose_name="Service ID", max_length=256, editable=True)
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400231 type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False)
Rizwan Haider65baf552016-09-28 16:47:28 -0400232 root = models.ForeignKey(NetworkEdgePort,
233 related_name='EdgeToMultipointRoot',
234 verbose_name="Root",
235 editable=True,
236 on_delete=models.CASCADE)
237 eps = models.ManyToManyField(NetworkEdgePort,
238 related_name='%(class)s_eps',
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400239 verbose_name="Endpoints",
240 editable=False)
Rizwan Haider65baf552016-09-28 16:47:28 -0400241 operstate = models.CharField(choices=OPERATIONALSTATE, verbose_name="OperationalState", max_length=256,
242 editable=True)
243 adminstate = models.CharField(choices=ADMINISTRATIVESTATE, verbose_name="AdministrativeState", max_length=256,
244 editable=True)
245
246 # Scratch Area to help deal with the Many to Many relationship with the eps
247 #eps_createbuffer = models.CharField(max_length=1024, default="{}", null=True)
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400248
249 def __init__(self, *args, **kwargs):
Rizwan Haider65baf552016-09-28 16:47:28 -0400250 super(NetworkEdgeToMultipointConnection, self).__init__(*args, **kwargs)
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400251
Rizwan Haider65baf552016-09-28 16:47:28 -0400252#E-LAN Service
253class NetworkMultipointToMultipointConnection(Service):
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400254
255 class Meta:
256 app_label = SERVICE_NAME
Rizwan Haider65baf552016-09-28 16:47:28 -0400257 verbose_name = SERVICE_NAME_ELAN_VERBOSE
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400258
Rizwan Haider65baf552016-09-28 16:47:28 -0400259 TYPE = (
260 ('vlan', 'VLAN'),
261 ('ip', 'IP'),
262 ('ethernet', 'Ethernet'),
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400263 )
264
Rizwan Haider65baf552016-09-28 16:47:28 -0400265 OPERATIONALSTATE = (
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400266 ('active', 'Active'),
267 ('inactive', 'Inactive')
268 )
269
Rizwan Haider65baf552016-09-28 16:47:28 -0400270 ADMINISTRATIVESTATE = (
271 ('disabled', 'Disabled'),
272 ('activationrequested', 'ActivationRequested'),
273 ('enabled', 'Enabled'),
274 ('invalid', 'Invalid'),
275 ('deactivationrequested', 'DeactivationRequested')
276 )
277
278 sid = models.CharField(unique=True, verbose_name="Service ID", max_length=256, editable=True)
279 type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False)
280 eps = models.ManyToManyField(NetworkEdgePort,
281 related_name='%(class)s_eps',
282 verbose_name="Endpoints",
283 editable=False)
284
285 operstate = models.CharField(choices=OPERATIONALSTATE, verbose_name="OperationalState", max_length=256,
286 editable=True)
287 adminstate = models.CharField(choices=ADMINISTRATIVESTATE, verbose_name="AdministrativeState", max_length=256,
288 editable=True)
289
290 # Scratch Area to help deal with the Many to Many relationship with the eps
291 #eps_createbuffer = models.CharField(max_length=1024, default="{}", null=True)
Rizwan Haidereb2cc772016-09-08 12:14:55 -0400292
293 def __init__(self, *args, **kwargs):
Rizwan Haider65baf552016-09-28 16:47:28 -0400294 super(NetworkMultipointToMultipointConnection, self).__init__(*args, **kwargs)
295