blob: 11b0ad9775bffd22a1996445157684db5b6bf2f1 [file] [log] [blame]
Matteo Scandolo62a83f02018-03-01 15:59:18 -08001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16from xos.exceptions import *
17from models_decl import *
18from core.models import Service
19
20class CordSubscriberRoot(CordSubscriberRoot_decl):
21 class Meta:
22 proxy = True
23
24 def invalidate_related_objects(self):
25 # Dirty all vSGs related to this subscriber, so the vSG synchronizer
26 # will run.
27
28 # FIXME: This should be reimplemented when multiple-objects-per-synchronizer is implemented.
29
30 for link in self.subscribed_links.all():
31 outer_service_instance = link.provider_service_instance
32 # TODO: We may need to invalide the vOLT too...
33 for link in outer_service_instance.subscribed_links.all():
34 inner_service_instance = link.provider_service_instance
35 inner_service_instance.save(update_fields=["updated"])
36
37 def save(self, *args, **kwargs):
38 self.validate_unique_service_specific_id(none_okay=True)
39
40 # NOTE setting owner_id
41 try:
42 rcord_service = Service.objects.filter(name="rcord")[0]
43 self.owner_id = rcord_service.id
44 except IndexError:
45 raise XOSValidationError("Service RCORD cannot be found, please make sure that the model exists.")
46
47 if (not hasattr(self, 'caller') or not self.caller.is_admin):
48 if (self.has_field_changed("service_specific_id")):
49 raise XOSPermissionDenied("You do not have permission to change service_specific_id")
50
51 super(CordSubscriberRoot, self).save(*args, **kwargs)
52 self.invalidate_related_objects()
53 return