Andy Bavier | eddb6b6 | 2017-10-26 08:39:27 -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 | |
| 17 | import os |
| 18 | import sys |
| 19 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 20 | from synchronizers.new_base.modelaccessor import * |
| 21 | from xos.logger import Logger, logging |
| 22 | |
| 23 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 24 | sys.path.insert(0, parentdir) |
| 25 | |
| 26 | logger = Logger(level=logging.INFO) |
| 27 | |
| 28 | class SyncTemplateServiceInstance(SyncInstanceUsingAnsible): |
| 29 | |
| 30 | provides = [TemplateServiceInstance] |
| 31 | |
| 32 | observes = TemplateServiceInstance |
| 33 | |
| 34 | requested_interval = 0 |
| 35 | |
| 36 | template_name = "serviceinstance_playbook.yaml" |
| 37 | |
| 38 | service_key_name = "/opt/xos/synchronizers/templateservice/service_private_key" |
| 39 | |
| 40 | def __init__(self, *args, **kwargs): |
| 41 | super(SyncTemplateServiceInstance, self).__init__(*args, **kwargs) |
| 42 | |
| 43 | def get_service(self, o): |
| 44 | if not o.owner: |
| 45 | return None |
| 46 | |
| 47 | service = TemplateService.objects.filter(id=o.owner.id) |
| 48 | |
| 49 | if not service: |
| 50 | return None |
| 51 | |
| 52 | return service[0] |
| 53 | |
| 54 | # Gets the attributes that are used by the Ansible template but are not |
| 55 | # part of the set of default attributes. |
| 56 | def get_extra_attributes(self, o): |
| 57 | fields = {} |
Andy Bavier | eddb6b6 | 2017-10-26 08:39:27 -0700 | [diff] [blame] | 58 | return fields |