blob: 1a7088474d723ac1dc3039c7c71cd9ddbc5dc603 [file] [log] [blame]
Scott Bakerbba67b62019-01-28 17:38:21 -08001# 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
16import os
Scott Bakerc2fddaa2019-01-30 15:45:03 -080017from xossynchronizer.steps import ansiblesyncstep
Scott Bakerbba67b62019-01-28 17:38:21 -080018
19
20def escape(s):
21 s = s.replace("\n", r"\n").replace('"', r"\"")
22 return s
23
24
Scott Bakerc2fddaa2019-01-30 15:45:03 -080025class SyncInstances(ansiblesyncstep.AnsibleSyncStep):
Scott Bakerbba67b62019-01-28 17:38:21 -080026 requested_interval = 0
Scott Bakerc2fddaa2019-01-30 15:45:03 -080027 # This observes is intentionally a list of one string, to test steps where observes is a list of strings.
28 observes = ["Instance"]
Scott Bakerbba67b62019-01-28 17:38:21 -080029 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