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. |
| 15 | |
| 16 | from core.models import Tenant |
| 17 | |
| 18 | |
| 19 | class EnterpriseLocation(Tenant): |
| 20 | |
| 21 | KIND = "vnaas" |
| 22 | |
| 23 | class Meta: |
| 24 | app_label = "vnaas" |
| 25 | name = "vnaas" |
| 26 | verbose_name = "Enterprise Location" |
| 27 | |
| 28 | # Primitive Fields (Not Relations) |
| 29 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 30 | cord_site_ip = CharField( help_text = "IP of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 31 | cord_site_port = IntegerField( help_text = "Port of the local site", max_length = 256, null = False, db_index = False, blank = False ) |
| 32 | cord_site_username = CharField( help_text = "Username of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 33 | cord_site_password = CharField( help_text = "Password of the local site", max_length = 64, null = False, db_index = False, blank = False ) |
| 34 | cord_site_type = CharField( default = "xos", choices = "(('onos', 'ONOS'), ('xos', 'XOS')", max_length = 64, blank = False, null = False, db_index = False ) |
| 35 | |
| 36 | |
| 37 | # Relations |
| 38 | |
| 39 | pass |
| 40 | |
| 41 | |
| 42 | class OnosModel(XOSBase): |
| 43 | |
| 44 | KIND = "vnaas" |
| 45 | |
| 46 | class Meta: |
| 47 | app_label = "vnaas" |
| 48 | name = "vnaas" |
| 49 | verbose_name = "Open Network Operating System" |
| 50 | |
| 51 | # Primitive Fields (Not Relations) |
| 52 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 53 | onos_ip = CharField( help_text = "IP of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 54 | onos_port = IntegerField( help_text = "Port of the transport manager", max_length = 256, null = False, db_index = False, blank = False ) |
| 55 | onos_username = CharField( help_text = "Username of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 56 | onos_password = CharField( help_text = "Password of the transport manager", max_length = 64, null = False, db_index = False, blank = False ) |
| 57 | onos_type = CharField( default = "local", choices = "(('local', 'Local'), ('global', 'Global')", max_length = 64, blank = False, null = False, db_index = False ) |
| 58 | |
| 59 | |
| 60 | # Relations |
| 61 | |
| 62 | |
| 63 | pass |
| 64 | |
| 65 | |
| 66 | class UserNetworkInterface(XOSBase): |
| 67 | |
| 68 | KIND = "vnaas" |
| 69 | |
| 70 | class Meta: |
| 71 | app_label = "vnaas" |
| 72 | name = "vnaas" |
| 73 | verbose_name = "User Network Interface" |
| 74 | |
| 75 | # Primitive Fields (Not Relations) |
| 76 | tenant = CharField( help_text = "Tenant name", max_length = 256, null = False, db_index = False, blank = False ) |
| 77 | cpe_id = CharField( blank = False, max_length = 1024, null = False, db_index = False ) |
| 78 | latlng = CharField( help_text = "Location, i.e. [37.773972, -122.431297]", max_length = 256, null = False, db_index = False, blank = False ) |
| 79 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 80 | |
| 81 | |
| 82 | # Relations |
| 83 | |
| 84 | |
| 85 | def __unicode__(self): return u'%s' % (self.name) |
| 86 | |
| 87 | def save(self, *args, **kwargs): |
| 88 | |
| 89 | if self.latlng: |
| 90 | try: |
| 91 | latlng_value = getattr(self, 'latlng').strip() |
| 92 | if (latlng_value.startswith('[') and latlng_value.endswith(']') and latlng_value.index(',') > 0): |
| 93 | lat = latlng_value[1: latlng_value.index(',')].strip() |
| 94 | lng = latlng_value[latlng_value.index(',') + 1: len(latlng_value) - 1].strip() |
| 95 | |
| 96 | # If lat and lng are not floats, the code below should result in an error. |
| 97 | lat_validation = float(lat) |
| 98 | lng_validation = float(lng) |
| 99 | else: |
| 100 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 101 | except: |
| 102 | raise ValueError("The lat/lng value is not formatted correctly.") |
| 103 | |
| 104 | super(UserNetworkInterface, self).save(*args, **kwargs) |
| 105 | pass |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | class BandwidthProfile(XOSBase): |
| 111 | |
| 112 | KIND = "vnaas" |
| 113 | |
| 114 | class Meta: |
| 115 | app_label = "vnaas" |
| 116 | name = "vnaas" |
| 117 | verbose_name = "Bandwidth Profile" |
| 118 | |
| 119 | # Primitive Fields (Not Relations) |
| 120 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 121 | cbs = IntegerField( help_text = "Committed burst size", null = False, blank = False, db_index = False ) |
| 122 | ebs = IntegerField( help_text = "Expected burst size", null = False, blank = False, db_index = False ) |
| 123 | cir = IntegerField( help_text = "Committed information rate", null = False, blank = False, db_index = False ) |
| 124 | eir = IntegerField( help_text = "Expected information rate", null = False, blank = False, db_index = False ) |
| 125 | |
| 126 | |
| 127 | # Relations |
| 128 | |
| 129 | |
| 130 | def __unicode__(self): return u'%s' % (self.name) |
| 131 | pass |
| 132 | |
| 133 | |
| 134 | |
| 135 | class ELine(XOSBase): |
| 136 | |
| 137 | KIND = "vnaas" |
| 138 | |
| 139 | class Meta: |
| 140 | app_label = "vnaas" |
| 141 | name = "vnaas" |
| 142 | verbose_name = "Ethernet Virtual Private Line" |
| 143 | |
| 144 | # Primitive Fields (Not Relations) |
| 145 | name = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 146 | connect_point_1_id = CharField( blank = False, max_length = 256, null = False, db_index = False ) |
| 147 | connect_point_2_id = CharField( blank = False, max_length = 64, null = False, db_index = False ) |
| 148 | vlanids = TextField( help_text = "comma separated list of vlanIds", null = False, blank = False, db_index = False ) |
| 149 | cord_site_username = CharField( blank = False, max_length = 64, null = False, db_index = False ) |
| 150 | bwp = CharField( help_text = "bandwidth profile name", max_length = 256, null = False, db_index = False, blank = False ) |
| 151 | |
| 152 | |
| 153 | # Relations |
| 154 | |
| 155 | |
| 156 | def __unicode__(self): return u'%s' % (self.name) |
| 157 | pass |
| 158 | |