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 | |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 19 | |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 20 | class FabricCrossconnectService(FabricCrossconnectService_decl): |
| 21 | class Meta: |
| 22 | proxy = True |
| 23 | |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 24 | |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 25 | class FabricCrossconnectServiceInstance(FabricCrossconnectServiceInstance_decl): |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 26 | class Meta: |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 27 | proxy = True |
| 28 | |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 29 | |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 30 | class BNGPortMapping(BNGPortMapping_decl): |
| 31 | class Meta: |
| 32 | proxy = True |
| 33 | |
| 34 | def validate_range(self, pattern): |
| 35 | for this_range in pattern.split(","): |
| 36 | this_range = this_range.strip() |
| 37 | if "-" in this_range: |
| 38 | (first, last) = this_range.split("-") |
| 39 | try: |
| 40 | int(first.strip()) |
| 41 | int(last.strip()) |
| 42 | except ValueError: |
| 43 | raise XOSValidationError("Malformed range %s" % pattern) |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 44 | elif this_range.lower() == "any": |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 45 | pass |
| 46 | else: |
| 47 | try: |
| 48 | int(this_range) |
| 49 | except ValueError: |
| 50 | raise XOSValidationError("Malformed range %s" % pattern) |
| 51 | |
| 52 | def save(self, *args, **kwargs): |
| 53 | self.validate_range(self.s_tag) |
Scott Baker | 8256547 | 2018-08-20 11:40:03 -0700 | [diff] [blame] | 54 | |
Scott Baker | d443ea7 | 2018-08-07 13:50:06 -0700 | [diff] [blame] | 55 | super(BNGPortMapping, self).save(*args, **kwargs) |