Matteo Scandolo | f5e1033 | 2017-08-08 13:05:25 -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 | |
Andy Bavier | 89a9542 | 2016-11-02 14:38:39 -0400 | [diff] [blame] | 17 | def handle(controller_slice): |
| 18 | from core.models import ControllerSlice, Slice |
| 19 | |
| 20 | try: |
| 21 | my_status_code = int(controller_slice.backend_status[0]) |
| 22 | try: |
| 23 | his_status_code = int(controller_slice.slice.backend_status[0]) |
| 24 | except: |
| 25 | his_status_code = 0 |
| 26 | |
| 27 | fields = [] |
| 28 | if (my_status_code not in [0,his_status_code]): |
| 29 | controller_slice.slice.backend_status = controller_slice.backend_status |
| 30 | fields+=['backend_status'] |
| 31 | |
| 32 | if (controller_slice.backend_register != controller_slice.slice.backend_register): |
| 33 | controller_slice.slice.backend_register = controller_slice.backend_register |
| 34 | fields+=['backend_register'] |
| 35 | |
| 36 | controller_slice.slice.save(update_fields = fields) |
| 37 | |
| 38 | |
| 39 | except Exception,e: |
| 40 | print str(e) |
| 41 | pass |