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' |
| 9 | SERVICE_NAME_VERBOSE = 'Metro Network Service' |
| 10 | |
| 11 | class MetroNetworkService(Service): |
| 12 | |
| 13 | KIND = METRONETWORK_KIND |
| 14 | |
| 15 | class Meta: |
| 16 | app_label = SERVICE_NAME |
| 17 | verbose_name = SERVICE_NAME_VERBOSE |
| 18 | |
| 19 | ADMINISTRATIVE_STATE = ( |
| 20 | ('enabled', 'Enabled'), |
| 21 | ('disabled', 'Disabled') |
| 22 | ) |
| 23 | |
| 24 | OPERATIONALSTATE = ( |
| 25 | ('active', 'Active'), |
| 26 | ('inactive', 'Inactive') |
| 27 | ) |
| 28 | |
| 29 | restUrl = models.CharField(verbose_name="Rest URL", |
| 30 | max_length=256, |
| 31 | editable=True) |
| 32 | |
| 33 | administrativeState = models.CharField(choices=ADMINISTRATIVE_STATE, |
| 34 | default='disabled', |
| 35 | verbose_name="AdministrativeState", |
| 36 | max_length=16, |
| 37 | editable=True) |
| 38 | |
| 39 | operationalState = models.CharField(choices=OPERATIONALSTATE, |
| 40 | verbose_name="OperationalState", |
| 41 | max_length=256, |
| 42 | editable=True) |
| 43 | |
| 44 | def __init__(self, *args, **kwargs): |
| 45 | super(MetroNetworkService, self).__init__(*args, **kwargs) |
| 46 | |
| 47 | def getAdminstrativeState(self): |
| 48 | return self.administrativeState |
| 49 | |
| 50 | def setAdminstrativeState(self, value): |
| 51 | self.administrativeState = value |
| 52 | |
| 53 | def getOperationalState(self): |
| 54 | return self.operationalState |
| 55 | |
| 56 | def getRestUrl(self): |
Rizwan Haider | eb2cc77 | 2016-09-08 12:14:55 -0400 | [diff] [blame] | 57 | return self.restUrl |
| 58 | |
| 59 | |
| 60 | class NetworkDevice(PlCoreBase): |
| 61 | |
| 62 | class Meta: |
| 63 | app_label = SERVICE_NAME |
| 64 | |
| 65 | ADMINISTRATIVE_STATE = ( |
| 66 | ('enabled', 'Enabled'), |
| 67 | ('disabled', 'Disabled'), |
| 68 | ('syncrequested', 'SyncRequested'), |
| 69 | ('syncinprogress', 'SyncInProgress') |
| 70 | ) |
| 71 | |
| 72 | AUTH_TYPE = ( |
| 73 | ('basic', 'Basic'), |
| 74 | ('key', 'Key'), |
| 75 | ('oauth', 'OAuth') |
| 76 | ) |
| 77 | |
| 78 | # Leaving out the attributes below for now - not clear we will need them |
| 79 | # type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False) |
| 80 | # manufacturer = models.CharField(unique=False, verbose_name="Manufacturer", max_length=256, editable=False) |
| 81 | # serialNumber = models.CharField(unique=True, verbose_name="Serial Number", max_length=256, editable=False) |
| 82 | # chassisId = models.CharField(unique=False, verbose_name="Chassis ID", max_length=256, editable=False) |
| 83 | |
Matteo Scandolo | ddce4ec | 2016-09-26 13:11:03 -0700 | [diff] [blame] | 84 | 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] | 85 | restCtrlUrl = models.CharField(unique=True, |
| 86 | verbose_name="RestCtrlURL", |
| 87 | max_length=256, |
| 88 | editable=True) |
| 89 | authType = models.CharField(choices=AUTH_TYPE, verbose_name='Auth Type', max_length=16, editable=True) |
| 90 | username = models.CharField(verbose_name='Username', max_length=32, editable=True, blank=True) |
| 91 | password = models.CharField(max_length=32, verbose_name='Password', editable=True, blank=True) |
| 92 | administrativeState = models.CharField(choices=ADMINISTRATIVE_STATE, |
| 93 | default='disabled', |
| 94 | verbose_name="AdministrativeState", |
| 95 | max_length=16, |
| 96 | editable=True) |
| 97 | id = models.CharField(unique=True, |
| 98 | verbose_name="Element Id", |
| 99 | primary_key=True, |
| 100 | max_length=256, |
| 101 | editable=True) |
| 102 | |
| 103 | def __init__(self, *args, **kwargs): |
| 104 | super(NetworkDevice, self).__init__(*args, **kwargs) |
| 105 | |
| 106 | class NetworkPort(PlCoreBase): |
| 107 | |
| 108 | class Meta: |
| 109 | app_label = SERVICE_NAME |
| 110 | |
| 111 | element = models.ForeignKey(NetworkDevice, on_delete=models.CASCADE) |
| 112 | id = models.AutoField(verbose_name="id", primary_key=True, editable=False) |
| 113 | pid = models.CharField(unique=True, verbose_name="Port ID", max_length=256, editable=False) |
| 114 | |
| 115 | def __init__(self, *args, **kwargs): |
| 116 | super(NetworkPort, self).__init__(*args, **kwargs) |
| 117 | |
| 118 | class NetworkEdgePort(PlCoreBase): |
| 119 | |
| 120 | class Meta: |
| 121 | app_label = SERVICE_NAME |
| 122 | |
| 123 | element = models.ForeignKey(NetworkDevice, on_delete=models.CASCADE) |
| 124 | id = models.AutoField(verbose_name="id", primary_key=True, editable=False) |
| 125 | pid = models.CharField(unique=True, verbose_name="Port ID", max_length=256, editable=False) |
| 126 | bwpCfgCbs = models.IntegerField(verbose_name="Committed Burst Size", editable=False, blank=True) |
| 127 | bwpCfgEbs = models.IntegerField(verbose_name="Excess Burst Size", editable=False, blank=True) |
| 128 | bwpCfgCir = models.IntegerField(verbose_name="Committed Information Rate", editable=False, blank=True) |
| 129 | bwpCfgEir = models.IntegerField(verbose_name="Excess Information Rate", editable=False, blank=True) |
| 130 | name = models.CharField(verbose_name="Name", max_length=256, editable=True, blank=True) |
| 131 | location = models.CharField(verbose_name="Location", max_length=256, editable=True, blank=True) |
| 132 | latlng = models.CharField(verbose_name="Latitude/Longitude", max_length=50, editable=True, blank=True) |
| 133 | |
| 134 | def __init__(self, *args, **kwargs): |
| 135 | super(NetworkEdgePort, self).__init__(*args, **kwargs) |
| 136 | |
| 137 | def save(self, *args, **kwargs): |
| 138 | |
| 139 | if self.latlng: |
| 140 | try: |
| 141 | latlng_value = getattr(self, 'latlng').strip() |
| 142 | if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0): |
| 143 | lat = latlng_value[1: latlng_value.index(',')].strip() |
| 144 | lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip() |
| 145 | |
| 146 | #If lat and lng are not floats, the code below should result in an error. |
| 147 | lat_validation = float(lat) |
| 148 | lng_validation = float(lng) |
| 149 | else: |
| 150 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 151 | except: |
| 152 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 153 | |
| 154 | super(NetworkEdgePort, self).save(*args, **kwargs) |
| 155 | |
| 156 | class NetworkPointToPointConnection(PlCoreBase): |
| 157 | |
| 158 | class Meta: |
| 159 | app_label = SERVICE_NAME |
| 160 | |
| 161 | TYPE = ( |
| 162 | ('direct', 'Direct'), |
| 163 | ('indirect', 'Indirect'), |
| 164 | ('edge', 'Edge'), |
| 165 | ('tunnel', 'Tunnel'), |
| 166 | ('optical', 'Optical'), |
| 167 | ('virtual', 'Virtual'), |
| 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 | |
| 183 | id = models.AutoField(verbose_name="PointToPointConnectionId", |
| 184 | primary_key=True, |
| 185 | editable=False) |
| 186 | |
| 187 | |
| 188 | sid = models.CharField(unique=True, verbose_name="Service ID", max_length=256, editable=True) |
| 189 | type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False) |
| 190 | src = models.ForeignKey(NetworkPort, |
| 191 | related_name='PointToPointSrc', |
| 192 | verbose_name="Source", |
| 193 | editable=False, |
| 194 | on_delete=models.CASCADE) |
| 195 | dest = models.ForeignKey(NetworkPort, |
| 196 | related_name='PointToPointDst', |
| 197 | verbose_name="Destination", |
| 198 | editable=False, |
| 199 | on_delete=models.CASCADE) |
| 200 | operstate = models.CharField(choices=OPERATIONALSTATE, verbose_name="OperationalState", max_length=256, editable=False) |
| 201 | adminstate = models.CharField(choices=ADMINISTRATIVESTATE, verbose_name="AdministrativeState", max_length=256, editable=True) |
| 202 | |
| 203 | |
| 204 | def __init__(self, *args, **kwargs): |
| 205 | super(NetworkPointToPointConnection, self).__init__(*args, **kwargs) |
| 206 | |
| 207 | class NetworkEdgeToEdgePointConnection(PlCoreBase): |
| 208 | |
| 209 | class Meta: |
| 210 | app_label = SERVICE_NAME |
| 211 | |
| 212 | TYPE = ( |
| 213 | ('direct', 'Direct'), |
| 214 | ('tunnel', 'Tunnel'), |
| 215 | ('optical', 'Optical'), |
| 216 | ('virtual', 'Virtual'), |
| 217 | ('Point_To_Point', 'Point To Point') |
| 218 | ) |
| 219 | |
| 220 | OPERATIONALSTATE = ( |
| 221 | ('active', 'Active'), |
| 222 | ('inactive', 'Inactive') |
| 223 | ) |
| 224 | |
| 225 | ADMINISTRATIVESTATE = ( |
| 226 | ('disabled', 'Disabled'), |
| 227 | ('activationrequested', 'ActivationRequested'), |
| 228 | ('enabled', 'Enabled'), |
| 229 | ('invalid', 'Invalid'), |
| 230 | ('deactivationrequested', 'DeactivationRequested') |
| 231 | ) |
| 232 | |
| 233 | id = models.AutoField(verbose_name="EdgePointToEdgePointConnectivityId", |
| 234 | primary_key=True, |
| 235 | editable=False) |
| 236 | sid = models.CharField(unique=True, verbose_name="Service ID", max_length=256, editable=True) |
| 237 | type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=True) |
| 238 | uni1 = models.ForeignKey(NetworkEdgePort, |
| 239 | related_name='EdgePointToEdgePointSrc', |
| 240 | verbose_name="UNI 1", |
| 241 | editable=True, |
| 242 | on_delete=models.CASCADE) |
| 243 | uni2 = models.ForeignKey(NetworkEdgePort, |
| 244 | related_name='EdgePointToEdgePointDst', |
| 245 | verbose_name="UNI 2", |
| 246 | editable=True, |
| 247 | on_delete=models.CASCADE) |
| 248 | operstate = models.CharField(choices=OPERATIONALSTATE, verbose_name="OperationalState", max_length=256, editable=True) |
| 249 | adminstate = models.CharField(choices=ADMINISTRATIVESTATE, verbose_name="AdministrativeState", max_length=256, editable=True) |
| 250 | |
| 251 | |
| 252 | def __init__(self, *args, **kwargs): |
| 253 | super(NetworkEdgeToEdgePointConnection, self).__init__(*args, **kwargs) |
| 254 | |
| 255 | |
| 256 | class NetworkMultipointConnection(PlCoreBase): |
| 257 | |
| 258 | class Meta: |
| 259 | app_label = SERVICE_NAME |
| 260 | |
| 261 | TYPE = ( |
| 262 | ('vlan', 'VLAN'), |
| 263 | ('ip', 'IP'), |
| 264 | ('ethernet', 'Ethernet'), |
| 265 | ) |
| 266 | |
| 267 | STATE = ( |
| 268 | ('active', 'Active'), |
| 269 | ('inactive', 'Inactive') |
| 270 | ) |
| 271 | |
| 272 | type = models.CharField(choices=TYPE, verbose_name="Type", max_length=256, editable=False) |
| 273 | eps = models.ManyToManyField(NetworkPort, |
| 274 | related_name='eps', |
| 275 | verbose_name="Endpoints", |
| 276 | editable=False) |
| 277 | state = models.CharField(choices=STATE, verbose_name="State", max_length=256, editable=False) |
| 278 | |
| 279 | def __init__(self, *args, **kwargs): |
| 280 | super(NetworkMultipointConnection, self).__init__(*args, **kwargs) |
| 281 | |
| 282 | class NetworkInterLink(PlCoreBase): |
| 283 | |
| 284 | class Meta: |
| 285 | app_label = SERVICE_NAME |
| 286 | |
| 287 | DISCOVERY = ( |
| 288 | ('auto', 'Automatic Discovery'), |
| 289 | ('manual', 'Manual Discovery'), |
| 290 | ) |
| 291 | |
| 292 | STATE = ( |
| 293 | ('active', 'Active'), |
| 294 | ('inactive', 'Inactive') |
| 295 | ) |
| 296 | |
| 297 | src = models.ForeignKey(NetworkPort, |
| 298 | related_name='InterLinkSrc', |
| 299 | verbose_name="Source", |
| 300 | editable=False, |
| 301 | on_delete=models.CASCADE) |
| 302 | dest = models.ForeignKey(NetworkPort, |
| 303 | related_name='InterLinkDst', |
| 304 | verbose_name="Destination", |
| 305 | editable=False, |
| 306 | on_delete=models.CASCADE) |
| 307 | state = models.CharField(choices=STATE, verbose_name="State", max_length=256, editable=False) |
| 308 | discovery = models.CharField(choices=STATE, verbose_name="State", max_length=256, editable=False) |
| 309 | |
| 310 | def __init__(self, *args, **kwargs): |
| 311 | super(NetworkInterLink, self).__init__(*args, **kwargs) |