Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 1 | # 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 | |
| 15 | |
| 16 | import os |
| 17 | import base64 |
| 18 | import struct |
| 19 | import socket |
| 20 | from netaddr import IPAddress, IPNetwork |
| 21 | from xossynchronizer.steps.syncstep import SyncStep |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 22 | |
| 23 | class SyncControllerNetworks(SyncStep): |
| 24 | requested_interval = 0 |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame^] | 25 | observes = "ControllerNetwork" |
| 26 | external_dependencies = ["User"] |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 27 | playbook = "sync_controller_networks.yaml" |
| 28 | |
| 29 | def fetch_pending(self, deleted): |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame^] | 30 | ci = self.model_accessor.ControllerNetwork() |
| 31 | i = self.model_accessor.Network() |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 32 | i.name = "Lush Loss" |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame^] | 33 | s = self.model_accessor.Slice() |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 34 | s.name = "Ghastly Notebook" |
| 35 | i.owner = s |
| 36 | ci.i = i |
| 37 | return [ci] |
| 38 | |
| 39 | def map_sync_outputs(self, controller_network, res): |
| 40 | network_id = res[0]["network"]["id"] |
| 41 | subnet_id = res[1]["subnet"]["id"] |
| 42 | controller_network.net_id = network_id |
| 43 | controller_network.subnet = self.cidr |
| 44 | controller_network.subnet_id = subnet_id |
| 45 | controller_network.backend_status = "1 - OK" |
| 46 | if not controller_network.segmentation_id: |
| 47 | controller_network.segmentation_id = str( |
| 48 | self.get_segmentation_id(controller_network) |
| 49 | ) |
| 50 | controller_network.save() |
| 51 | |
| 52 | def map_sync_inputs(self, controller_network): |
| 53 | pass |
| 54 | |
| 55 | def map_delete_inputs(self, controller_network): |
| 56 | network_fields = {"endpoint": None, "delete": True} |
| 57 | |
| 58 | return network_fields |