Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame^] | 15 | from header import * |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 16 | |
Max Chu | 2de11f8 | 2017-09-06 08:49:21 -0700 | [diff] [blame^] | 17 | from core.models import Tenant, XOSBase |
Andrea Campanella | 420e4b4 | 2017-09-01 16:51:03 +0200 | [diff] [blame] | 18 | |
| 19 | |
| 20 | class EnterpriseLocation(Tenant): |
| 21 | |
| 22 | KIND = "vnaas" |
| 23 | |
| 24 | class Meta: |
| 25 | app_label = "vnaas" |
| 26 | name = "vnaas" |
| 27 | verbose_name = "Enterprise Location" |
| 28 | |
| 29 | # Primitive Fields (Not Relations) |
| 30 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 31 | cord_site_ip = CharField( help_text = "IP of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 32 | cord_site_port = IntegerField( help_text = "Port of the local site", max_length = 256, null = False, db_index = False, blank = False ) |
| 33 | cord_site_username = CharField( help_text = "Username of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 34 | cord_site_password = CharField( help_text = "Password of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 35 | cord_site_type = CharField( default = "xos", choices = "(('onos', 'ONOS'), ('xos', 'XOS')", max_length = 64, blank = False, null = False, db_index = False ) |
| 36 | |
| 37 | |
| 38 | # Relations |
| 39 | |
| 40 | pass |
| 41 | |
| 42 | |
| 43 | class OnosModel(XOSBase): |
| 44 | |
| 45 | KIND = "vnaas" |
| 46 | |
| 47 | class Meta: |
| 48 | app_label = "vnaas" |
| 49 | name = "vnaas" |
| 50 | verbose_name = "Open Network Operating System" |
| 51 | |
| 52 | # Primitive Fields (Not Relations) |
| 53 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 54 | onos_ip = CharField( help_text = "IP of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 55 | onos_port = IntegerField( help_text = "Port of the transport manager", max_length = 256, null = False, db_index = False, blank = False ) |
| 56 | onos_username = CharField( help_text = "Username of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 57 | onos_password = CharField( help_text = "Password of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 58 | onos_type = CharField( default = "local", choices = "(('local', 'Local'), ('global', 'Global')", max_length = 64, blank = False, null = False, db_index = False ) |
| 59 | |
| 60 | |
| 61 | # Relations |
| 62 | |
| 63 | |
| 64 | pass |
| 65 | |
| 66 | |
| 67 | class UserNetworkInterface(XOSBase): |
| 68 | |
| 69 | KIND = "vnaas" |
| 70 | |
| 71 | class Meta: |
| 72 | app_label = "vnaas" |
| 73 | name = "vnaas" |
| 74 | verbose_name = "User Network Interface" |
| 75 | |
| 76 | # Primitive Fields (Not Relations) |
| 77 | tenant = CharField( help_text = "Tenant name", max_length = 256, null = False, db_index = False, blank = False ) |
| 78 | cpe_id = CharField( blank = False, max_length = 1024, null = False, db_index = False ) |
| 79 | latlng = CharField( help_text = "Location, i.e. [37.773972, -122.431297]", max_length = 256, null = False, db_index = False, blank = False ) |
| 80 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 81 | |
| 82 | |
| 83 | # Relations |
| 84 | |
| 85 | |
| 86 | def __unicode__(self): return u'%s' % (self.name) |
| 87 | |
| 88 | def save(self, *args, **kwargs): |
| 89 | |
| 90 | if self.latlng: |
| 91 | try: |
| 92 | latlng_value = getattr(self, 'latlng').strip() |
| 93 | if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0): |
| 94 | lat = latlng_value[1: latlng_value.index(',')].strip() |
| 95 | lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip() |
| 96 | |
| 97 | # If lat and lng are not floats, the code below should result in an error. |
| 98 | lat_validation = float(lat) |
| 99 | lng_validation = float(lng) |
| 100 | else: |
| 101 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 102 | except: |
| 103 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 104 | |
| 105 | super(UserNetworkInterface, self).save(*args, **kwargs) |
| 106 | pass |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | class BandwidthProfile(XOSBase): |
| 112 | |
| 113 | KIND = "vnaas" |
| 114 | |
| 115 | class Meta: |
| 116 | app_label = "vnaas" |
| 117 | name = "vnaas" |
| 118 | verbose_name = "Bandwidth Profile" |
| 119 | |
| 120 | # Primitive Fields (Not Relations) |
| 121 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 122 | cbs = IntegerField( help_text = "Committed burst size", null = False, blank = False, db_index = False ) |
| 123 | ebs = IntegerField( help_text = "Expected burst size", null = False, blank = False, db_index = False ) |
| 124 | cir = IntegerField( help_text = "Committed information rate", null = False, blank = False, db_index = False ) |
| 125 | eir = IntegerField( help_text = "Expected information rate", null = False, blank = False, db_index = False ) |
| 126 | |
| 127 | |
| 128 | # Relations |
| 129 | |
| 130 | |
| 131 | def __unicode__(self): return u'%s' % (self.name) |
| 132 | pass |
| 133 | |
| 134 | |
| 135 | |
| 136 | class ELine(XOSBase): |
| 137 | |
| 138 | KIND = "vnaas" |
| 139 | |
| 140 | class Meta: |
| 141 | app_label = "vnaas" |
| 142 | name = "vnaas" |
| 143 | verbose_name = "Ethernet Virtual Private Line" |
| 144 | |
| 145 | # Primitive Fields (Not Relations) |
| 146 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 147 | connect_point_1_id = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 148 | connect_point_2_id = CharField( blank = False, max_length = 64, null = False, db_index = False ) |
| 149 | vlanids = TextField( help_text = "comma separated list of vlanIds", null = False, blank = False, db_index = False ) |
| 150 | cord_site_username = CharField( blank = False, max_length = 64, null = False, db_index = False ) |
| 151 | bwp = CharField( help_text = "bandwidth profile name", max_length = 256, null = False, db_index = False, blank = False ) |
| 152 | |
| 153 | |
| 154 | # Relations |
| 155 | |
| 156 | |
| 157 | def __unicode__(self): return u'%s' % (self.name) |
| 158 | pass |
| 159 | |