Scott Baker | a6c687c | 2018-07-16 15:08:49 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 16 | |
Scott Baker | 63afcc1 | 2019-02-01 15:41:46 -0800 | [diff] [blame] | 17 | from xossynchronizer.modelaccessor import FabricCrossconnectServiceInstance, ServiceInstance, model_accessor |
| 18 | from xossynchronizer.model_policies.policy import Policy |
Scott Baker | a6c687c | 2018-07-16 15:08:49 -0700 | [diff] [blame] | 19 | |
| 20 | from xosconfig import Config |
| 21 | from multistructlog import create_logger |
| 22 | |
| 23 | log = create_logger(Config().get('logging')) |
| 24 | |
Scott Baker | e7b55e4 | 2019-04-01 17:18:03 -0700 | [diff] [blame] | 25 | |
Scott Baker | a6c687c | 2018-07-16 15:08:49 -0700 | [diff] [blame] | 26 | class FabricCrossconnectServiceInstancePolicy(Policy): |
| 27 | model_name = "FabricCrossconnectServiceInstance" |
| 28 | |
| 29 | def handle_create(self, service_instance): |
| 30 | return self.handle_update(service_instance) |
| 31 | |
| 32 | def handle_update(self, service_instance): |
| 33 | log.info("Handle_update Fabric Crossconnect Service Instance", service_instance=service_instance) |
| 34 | |
| 35 | if (service_instance.link_deleted_count > 0) and (not service_instance.provided_links.exists()): |
| 36 | # If this instance has no links pointing to it, delete |
| 37 | self.handle_delete(service_instance) |
| 38 | if FabricCrossconnectServiceInstance.objects.filter(id=service_instance.id).exists(): |
| 39 | service_instance.delete() |
| 40 | return |
| 41 | |
Scott Baker | a6c687c | 2018-07-16 15:08:49 -0700 | [diff] [blame] | 42 | def handle_delete(self, service_instance): |
| 43 | log.info("Handle_delete Fabric-Crossconnect Service Instance", service_instance=service_instance) |