blob: 479b87dbf7610b78a915aff51818706ad908b832 [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
17import base64
18import socket
19from xossynchronizer.steps import syncstep
20from xossynchronizer.mock_modelaccessor import *
21
22RESTAPI_HOSTNAME = socket.gethostname()
23RESTAPI_PORT = "8000"
24
25
26def escape(s):
27 s = s.replace("\n", r"\n").replace('"', r"\"")
28 return s
29
30
31class SyncInstances(syncstep.SyncStep):
32 provides = [Instance]
33 requested_interval = 0
34 observes = Instance
35 playbook = "sync_instances.yaml"
36
37 def fetch_pending(self, deletion=False):
38 objs = super(SyncInstances, self).fetch_pending(deletion)
39 objs = [x for x in objs if x.isolation == "vm"]
40 return objs
41
42 def map_sync_inputs(self, instance):
43 inputs = {}
44 metadata_update = {}
45
46 fields = {"name": instance.name, "delete": False}
47 return fields
48
49 def map_sync_outputs(self, instance, res):
50 instance.save()
51
52 def map_delete_inputs(self, instance):
53 input = {
54 "endpoint": "endpoint",
55 "admin_user": "admin_user",
56 "admin_password": "admin_password",
57 "project_name": "project_name",
58 "tenant": "tenant",
59 "tenant_description": "tenant_description",
60 "name": instance.name,
61 "ansible_tag": "ansible_tag",
62 "delete": True,
63 }
64
65 return input