blob: 9b1f0fbf1a1c625e4912bc2ed768e3fa286ba393 [file] [log] [blame]
Pingping Lin4730a3f2018-04-19 16:06:08 -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
Matteo Scandoloc48a0fc2018-01-31 11:38:11 -080015from xos.exceptions import XOSValidationError
16
17from models_decl import MCordSubscriberService_decl
18from models_decl import MCordSubscriberInstance_decl
19
20
21
22
23class MCordSubscriberService(MCordSubscriberService_decl):
24 class Meta:
25 proxy = True
26
27
28class MCordSubscriberInstance(MCordSubscriberInstance_decl):
29 class Meta:
30 proxy = True
31
32 def save(self, *args, **kwargs):
Matteo Scandolo95f585e2018-02-14 15:21:29 -080033 # if we don't have a name, use the IMSI number has a name
34 if not self.name:
35 self.name = self.imsi_number
36
Matteo Scandoloffdd0832018-02-01 15:52:37 -080037 # prevent IMSI duplicate
38 try:
39 instance_with_same_imsi = MCordSubscriberInstance.objects.get(imsi_number=self.imsi_number)
40
41 if (not self.pk and instance_with_same_imsi) or (self.pk and self.pk != instance_with_same_imsi.pk):
42 raise XOSValidationError("An MCORDSubscriber with imsi_number '%s' already exists" % self.imsi_number)
43 except self.DoesNotExist:
44 pass
45
Matteo Scandolo8fdf4092018-02-05 13:15:54 -080046 if self.is_new and not self.created_by:
47 # NOTE if created_by is null it has been created by XOS
48 self.created_by = "XOS"
49
Matteo Scandolo95f585e2018-02-14 15:21:29 -080050 self.backend_code = 0
51 self.backend_status = "In Progress"
52
Matteo Scandoloc48a0fc2018-01-31 11:38:11 -080053 super(MCordSubscriberInstance, self).save(*args, **kwargs)