Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | from xos.exceptions import XOSValidationError |
| 16 | |
| 17 | from models_decl import FabricCrossconnectService_decl, FabricCrossconnectServiceInstance_decl, BNGPortMapping_decl |
| 18 | |
| 19 | class FabricCrossconnectService(FabricCrossconnectService_decl): |
| 20 | class Meta: |
| 21 | proxy = True |
| 22 | |
| 23 | class FabricCrossconnectServiceInstance(FabricCrossconnectServiceInstance_decl): |
| 24 | class Meta: |
| 25 | proxy = True |
| 26 | |
| 27 | class BNGPortMapping(BNGPortMapping_decl): |
| 28 | class Meta: |
| 29 | proxy = True |
| 30 | |
| 31 | def validate_range(self, pattern): |
| 32 | for this_range in pattern.split(","): |
| 33 | this_range = this_range.strip() |
| 34 | if "-" in this_range: |
| 35 | (first, last) = this_range.split("-") |
| 36 | try: |
| 37 | int(first.strip()) |
| 38 | int(last.strip()) |
| 39 | except ValueError: |
| 40 | raise XOSValidationError("Malformed range %s" % pattern) |
| 41 | elif this_range.lower()=="any": |
| 42 | pass |
| 43 | else: |
| 44 | try: |
| 45 | int(this_range) |
| 46 | except ValueError: |
| 47 | raise XOSValidationError("Malformed range %s" % pattern) |
| 48 | |
| 49 | def save(self, *args, **kwargs): |
| 50 | self.validate_range(self.s_tag) |
Scott Baker | 8256547 | 2018-08-20 11:40:03 -0700 | [diff] [blame] | 51 | |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 52 | super(BNGPortMapping, self).save(*args, **kwargs) |
| 53 | |