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 |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame] | 17 | from xossynchronizer.steps import ansiblesyncstep |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def escape(s): |
| 21 | s = s.replace("\n", r"\n").replace('"', r"\"") |
| 22 | return s |
| 23 | |
| 24 | |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame] | 25 | class SyncInstances(ansiblesyncstep.AnsibleSyncStep): |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 26 | requested_interval = 0 |
Scott Baker | c2fddaa | 2019-01-30 15:45:03 -0800 | [diff] [blame] | 27 | # This observes is intentionally a list of one string, to test steps where observes is a list of strings. |
| 28 | observes = ["Instance"] |
Scott Baker | bba67b6 | 2019-01-28 17:38:21 -0800 | [diff] [blame] | 29 | playbook = "sync_instances.yaml" |
| 30 | |
| 31 | def fetch_pending(self, deletion=False): |
| 32 | objs = super(SyncInstances, self).fetch_pending(deletion) |
| 33 | objs = [x for x in objs if x.isolation == "vm"] |
| 34 | return objs |
| 35 | |
| 36 | def map_sync_inputs(self, instance): |
| 37 | inputs = {} |
| 38 | metadata_update = {} |
| 39 | |
| 40 | fields = {"name": instance.name, "delete": False} |
| 41 | return fields |
| 42 | |
| 43 | def map_sync_outputs(self, instance, res): |
| 44 | instance.save() |
| 45 | |
| 46 | def map_delete_inputs(self, instance): |
| 47 | input = { |
| 48 | "endpoint": "endpoint", |
| 49 | "admin_user": "admin_user", |
| 50 | "admin_password": "admin_password", |
| 51 | "project_name": "project_name", |
| 52 | "tenant": "tenant", |
| 53 | "tenant_description": "tenant_description", |
| 54 | "name": instance.name, |
| 55 | "ansible_tag": "ansible_tag", |
| 56 | "delete": True, |
| 57 | } |
| 58 | |
| 59 | return input |