blob: 13b56ed550205eab687fd5273d177e7fed570258 [file] [log] [blame]
Scott Bakerd443ea72018-08-07 13:50:06 -07001# 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
15from xos.exceptions import XOSValidationError
16
17from models_decl import FabricCrossconnectService_decl, FabricCrossconnectServiceInstance_decl, BNGPortMapping_decl
18
Scott Bakere7b55e42019-04-01 17:18:03 -070019
Scott Bakerd443ea72018-08-07 13:50:06 -070020class FabricCrossconnectService(FabricCrossconnectService_decl):
21 class Meta:
22 proxy = True
23
Scott Bakere7b55e42019-04-01 17:18:03 -070024
Scott Bakerd443ea72018-08-07 13:50:06 -070025class FabricCrossconnectServiceInstance(FabricCrossconnectServiceInstance_decl):
Scott Bakere7b55e42019-04-01 17:18:03 -070026 class Meta:
Scott Bakerd443ea72018-08-07 13:50:06 -070027 proxy = True
28
Scott Bakere7b55e42019-04-01 17:18:03 -070029
Scott Bakerd443ea72018-08-07 13:50:06 -070030class 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 Bakere7b55e42019-04-01 17:18:03 -070044 elif this_range.lower() == "any":
Scott Bakerd443ea72018-08-07 13:50:06 -070045 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 Baker82565472018-08-20 11:40:03 -070054
Scott Bakerd443ea72018-08-07 13:50:06 -070055 super(BNGPortMapping, self).save(*args, **kwargs)