Matteo Scandolo | ad7f3b4 | 2018-01-30 16:41:19 -0800 | [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.ansible_helper import run_template |
| 21 | from synchronizers.new_base.modelaccessor import MCordSubscriberInstance, ServiceInstanceLink |
| 22 | |
| 23 | from xosconfig import Config |
| 24 | from multistructlog import create_logger |
| 25 | import json |
| 26 | |
| 27 | |
| 28 | log = create_logger(Config().get('logging')) |
| 29 | |
| 30 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 31 | sys.path.insert(0, parentdir) |
| 32 | sys.path.insert(0, os.path.dirname(__file__)) |
| 33 | from helpers import ProgranHelpers |
| 34 | |
| 35 | class SyncProgranIMSILink(SyncInstanceUsingAnsible): |
| 36 | provides = [ServiceInstanceLink] |
| 37 | |
| 38 | observes = ServiceInstanceLink |
| 39 | |
| 40 | def skip_ansible_fields(self, o): |
| 41 | # FIXME This model does not have an instance, this is a workaroung to make it work, |
| 42 | # but it need to be cleaned up creating a general SyncUsingAnsible base class |
| 43 | return True |
| 44 | |
| 45 | def get_progran_imsi_field(self, o): |
| 46 | |
| 47 | imsi = { |
| 48 | "IMSIRuleArray": [ |
| 49 | '123' # TODO retrieve it service_instance_link.subscriber_service_instance.imsi_number |
| 50 | ] |
| 51 | } |
| 52 | imsi = json.dumps(imsi) |
| 53 | return imsi |
| 54 | |
| 55 | def get_extra_attributes(self, o): |
| 56 | |
| 57 | |
| 58 | return fields |
| 59 | |
| 60 | def sync_record(self, o): |
| 61 | log.info("sync'ing profile", object=str(o), **o.tologdict()) |
| 62 | # onos = ProgranHelpers.get_progran_onos_info() |
| 63 | # profile_name = 'foo' # TODO retrieve it service_instance_link.subscriber_service_instance.imsi_number |
| 64 | # |
| 65 | # fields = { |
| 66 | # 'onos_url': onos['url'], |
| 67 | # 'onos_username': onos['username'], |
| 68 | # 'onos_password': onos['password'], |
| 69 | # 'onos_port': onos['port'], |
| 70 | # 'endpoint': 'profile/%s/imsi' % profile_name, |
| 71 | # 'body': self.get_progran_imsi_field(o), |
| 72 | # 'method': 'POST' |
| 73 | # } |
| 74 | # fields = {} |
| 75 | # self.run_playbook(o, fields) |
| 76 | # o.save() |
| 77 | print o |
| 78 | |
| 79 | # FIXME we need to override this as the default expect to ssh into a VM |
| 80 | def run_playbook(self, o, fields): |
| 81 | run_template("progran_curl.yaml", fields, object=o) |
| 82 | |
| 83 | def delete_record(self, o): |
| 84 | log.info("deleting object", object=str(o), **o.tologdict()) |
| 85 | # onos = ProgranHelpers.get_progran_onos_info() |
| 86 | # profile_name = 'foo' |
| 87 | # imsi_number = 'bar' |
| 88 | # fields = { |
| 89 | # 'onos_url': onos['url'], |
| 90 | # 'onos_username': onos['username'], |
| 91 | # 'onos_password': onos['password'], |
| 92 | # 'onos_port': onos['port'], |
| 93 | # 'endpoint': 'profile/{profile_name}/{imsi}' % (profile_name, imsi_number), |
| 94 | # 'body': '', |
| 95 | # 'method': 'DELETE' |
| 96 | # } |
| 97 | # self.run_playbook(o, fields) |