Andy Bavier | 0c564b3 | 2017-10-12 13:04:11 -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 SyncInternetEmulatorServiceInstance(SyncInstanceUsingAnsible): |
| 29 | |
Andy Bavier | 0c564b3 | 2017-10-12 13:04:11 -0700 | [diff] [blame] | 30 | observes = InternetEmulatorServiceInstance |
Andy Bavier | 0c7904f | 2017-10-19 10:36:26 -0700 | [diff] [blame] | 31 | template_name = "internetemulatorserviceinstance_playbook.yaml" |
Andy Bavier | 0c564b3 | 2017-10-12 13:04:11 -0700 | [diff] [blame] | 32 | service_key_name = "/opt/xos/synchronizers/internetemulator/internetemulator_private_key" |
| 33 | |
Andy Bavier | 0c564b3 | 2017-10-12 13:04:11 -0700 | [diff] [blame] | 34 | def __init__(self, *args, **kwargs): |
Andy Bavier | 1f25be5 | 2017-10-12 15:23:04 -0700 | [diff] [blame] | 35 | super(SyncInternetEmulatorServiceInstance, self).__init__(*args, **kwargs) |
Andy Bavier | 0c564b3 | 2017-10-12 13:04:11 -0700 | [diff] [blame] | 36 | |
| 37 | def get_internetemulator(self, o): |
| 38 | if not o.owner: |
| 39 | return None |
| 40 | |
| 41 | internetemulator = InternetEmulatorService.objects.filter(id=o.owner.id) |
| 42 | |
| 43 | if not internetemulator: |
| 44 | return None |
| 45 | |
| 46 | return internetemulator[0] |
| 47 | |
| 48 | # Gets the attributes that are used by the Ansible template but are not |
| 49 | # part of the set of default attributes. |
| 50 | def get_extra_attributes(self, o): |
| 51 | fields = {} |
Andy Bavier | 1f25be5 | 2017-10-12 15:23:04 -0700 | [diff] [blame] | 52 | return fields |