blob: 8d659743e3acc50a4c42c9e20fcdb682355f6ace [file] [log] [blame]
Matteo Scandolo0a207b52018-01-29 13:39:43 -08001
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
17import os
18import sys
19from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
20from synchronizers.new_base.ansible_helper import run_template
21from synchronizers.new_base.modelaccessor import ENodeB
22
23from xosconfig import Config
24from multistructlog import create_logger
25import json
26
27from helpers import ProgranHelpers
28
29log = create_logger(Config().get('logging'))
30
31parentdir = os.path.join(os.path.dirname(__file__), "..")
32sys.path.insert(0, parentdir)
33
34class SyncProgranEnodeB(SyncInstanceUsingAnsible):
35 provides = [ENodeB]
36
37 observes = ENodeB
38
39 def skip_ansible_fields(self, o):
40 # FIXME This model does not have an instance, this is a workaroung to make it work,
41 # but it need to be cleaned up creating a general SyncUsingAnsible base class
42 return True
43
44 def get_progran_enodeb_field(self, o):
45
46 enodeb = {
47 "eNBId": o.enbId,
48 "Description": o.description,
49 "IpAddr": o.ipAddr
50 }
51 enodeb = json.dumps(enodeb)
52 return enodeb
53
54 def get_extra_attributes(self, o):
55 onos = ProgranHelpers.get_progran_onos_info()
56 fields = {
57 'onos_url': onos['url'],
58 'onos_username': onos['username'],
59 'onos_password': onos['password'],
60 'onos_port': onos['port'],
61 'endpoint': 'enodeb',
62 'profile': self.get_progran_enodeb_field(o),
63 'method': 'POST'
64 }
65
66 return fields
67
68 # FIXME we need to override this as the default expect to ssh into a VM
69 def run_playbook(self, o, fields):
70 run_template("progran_curl.yaml", fields, object=o)
71
72 def delete_record(self, o):
73 log.info("deleting object", object=str(o), **o.tologdict())
74 onos = ProgranHelpers.get_progran_onos_info()
75 fields = {
76 'onos_url': onos['url'],
77 'onos_username': onos['username'],
78 'onos_password': onos['password'],
79 'onos_port': onos['port'],
80 'endpoint': 'enodeb/%s' % o.enbId,
81 'profile': '',
82 'method': 'DELETE'
83 }
84 res = self.run_playbook(o, fields)