blob: 99cdebb31379b691c00ede37558ebec2816734c7 [file] [log] [blame]
Pingping Linfb959ac2018-03-14 15:59:16 -07001#!/usr/bin/python
2
3# Copyright 2017-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Matteo Scandoloc48a0fc2018-01-31 11:38:11 -080017from xos.exceptions import XOSValidationError
18
19from models_decl import MCordSubscriberService_decl
20from models_decl import MCordSubscriberInstance_decl
21
22
23
24
25class MCordSubscriberService(MCordSubscriberService_decl):
26 class Meta:
27 proxy = True
28
29
30class MCordSubscriberInstance(MCordSubscriberInstance_decl):
31 class Meta:
32 proxy = True
33
34 def save(self, *args, **kwargs):
35 # NOTE someone is setting owner_id, so just override it for now
36 try:
37 mcord_service = MCordSubscriberService.objects.all()[0]
38 self.owner_id = mcord_service.id
39 except IndexError:
40 raise XOSValidationError("Service MCORD cannot be found, please make sure that the model exists.")
41
Matteo Scandolo178fca82018-02-14 15:21:29 -080042 # if we don't have a name, use the IMSI number has a name
43 if not self.name:
44 self.name = self.imsi_number
45
Matteo Scandoloffdd0832018-02-01 15:52:37 -080046 # prevent IMSI duplicate
47 try:
48 instance_with_same_imsi = MCordSubscriberInstance.objects.get(imsi_number=self.imsi_number)
49
50 if (not self.pk and instance_with_same_imsi) or (self.pk and self.pk != instance_with_same_imsi.pk):
51 raise XOSValidationError("An MCORDSubscriber with imsi_number '%s' already exists" % self.imsi_number)
52 except self.DoesNotExist:
53 pass
54
Matteo Scandolo56e1f772018-02-05 13:15:54 -080055 if self.is_new and not self.created_by:
56 # NOTE if created_by is null it has been created by XOS
57 self.created_by = "XOS"
58
Matteo Scandolo178fca82018-02-14 15:21:29 -080059 self.backend_code = 0
60 self.backend_status = "In Progress"
61
Matteo Scandoloc48a0fc2018-01-31 11:38:11 -080062 super(MCordSubscriberInstance, self).save(*args, **kwargs)