Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 1 | # models.py - Metro Network Service |
| 2 | |
| 3 | from django.db import models |
| 4 | from core.models import Service |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 5 | from core.models import PlCoreBase |
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 6 | |
| 7 | METRONETWORK_KIND = "metronetwork" |
| 8 | SERVICE_NAME = 'metronetwork' |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 9 | SERVICE_NAME_ELINE_VERBOSE = 'E-Line Service' |
| 10 | SERVICE_NAME_ELAN_VERBOSE = 'E-LAN Service' |
| 11 | SERVICE_NAME_ETREE_VERBOSE = 'E-Tree Service' |
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 12 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 13 | class MetroNetworkSystem(PlCoreBase): |
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 14 | |
| 15 | class Meta: |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 16 | app_label = METRONETWORK_KIND |
| 17 | verbose_name = "Metro Network System" |
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 18 | |
| 19 | ADMINISTRATIVE_STATE = ( |
| 20 | ('enabled', 'Enabled'), |
| 21 | ('disabled', 'Disabled') |
| 22 | ) |
| 23 | |
| 24 | OPERATIONALSTATE = ( |
| 25 | ('active', 'Active'), |
| 26 | ('inactive', 'Inactive') |
| 27 | ) |
| 28 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 29 | 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 Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 38 | 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 Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 54 | super(MetroNetworkSystem, self).__init__(*args, **kwargs) |
Rizwan Haider | 30b3379 | 2016-08-18 02:11:18 -0400 | [diff] [blame] | 55 | |
| 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 66 | return self.restUrl |
| 67 | |
| 68 | |
| 69 | class NetworkDevice(PlCoreBase): |
| 70 | |
| 71 | class Meta: |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 72 | app_label = METRONETWORK_KIND |
| 73 | verbose_name = "Network Device" |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 74 | |
| 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 Scandolo | ddce4ec | 2016-09-26 13:11:03 -0700 | [diff] [blame] | 94 | name = models.CharField(max_length=20, help_text="Device friendly name", null=True, blank=True) |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 95 | 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 116 | class NetworkEdgePort(PlCoreBase): |
| 117 | |
| 118 | class Meta: |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 119 | app_label = METRONETWORK_KIND |
| 120 | verbose_name = "Network Edge Port" |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 121 | |
| 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 Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 155 | #E-Line Service |
| 156 | class NetworkEdgeToEdgePointConnection(Service): |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 157 | |
| 158 | class Meta: |
| 159 | app_label = SERVICE_NAME |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 160 | verbose_name = SERVICE_NAME_ELINE_VERBOSE |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 161 | |
| 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 183 | 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 Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 198 | #uni1_createbuffer = models.CharField(max_length=256, default="{}", null=True) |
| 199 | #uni2_createbuffer = models.CharField(max_length=256, default="{}", null=True) |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 200 | |
| 201 | def __init__(self, *args, **kwargs): |
| 202 | super(NetworkEdgeToEdgePointConnection, self).__init__(*args, **kwargs) |
| 203 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 204 | #E-Tree Service |
| 205 | class NetworkEdgeToMultipointConnection(Service): |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 206 | |
| 207 | class Meta: |
| 208 | app_label = SERVICE_NAME |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 209 | verbose_name = SERVICE_NAME_ETREE_VERBOSE |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 210 | |
| 211 | TYPE = ( |
| 212 | ('vlan', 'VLAN'), |
| 213 | ('ip', 'IP'), |
| 214 | ('ethernet', 'Ethernet'), |
| 215 | ) |
| 216 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 217 | OPERATIONALSTATE = ( |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 218 | ('active', 'Active'), |
| 219 | ('inactive', 'Inactive') |
| 220 | ) |
| 221 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 222 | 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 231 | type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False) |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 232 | 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 239 | verbose_name="Endpoints", |
| 240 | editable=False) |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 241 | 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 248 | |
| 249 | def __init__(self, *args, **kwargs): |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 250 | super(NetworkEdgeToMultipointConnection, self).__init__(*args, **kwargs) |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 251 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 252 | #E-LAN Service |
| 253 | class NetworkMultipointToMultipointConnection(Service): |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 254 | |
| 255 | class Meta: |
| 256 | app_label = SERVICE_NAME |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 257 | verbose_name = SERVICE_NAME_ELAN_VERBOSE |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 258 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 259 | TYPE = ( |
| 260 | ('vlan', 'VLAN'), |
| 261 | ('ip', 'IP'), |
| 262 | ('ethernet', 'Ethernet'), |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 263 | ) |
| 264 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 265 | OPERATIONALSTATE = ( |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 266 | ('active', 'Active'), |
| 267 | ('inactive', 'Inactive') |
| 268 | ) |
| 269 | |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 270 | 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 Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 292 | |
| 293 | def __init__(self, *args, **kwargs): |
Rizwan Haider | 65baf55 | 2016-09-28 16:47:28 -0400 | [diff] [blame] | 294 | super(NetworkMultipointToMultipointConnection, self).__init__(*args, **kwargs) |
| 295 | |