blob: 6a0d84ce20d771ff08e23d550765926892aa17b7 [file] [log] [blame]
Matteo Scandolo1c049b02018-01-18 11:32:46 -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 ProgranService, ProgranServiceInstance
22
23from xosconfig import Config
24from multistructlog import create_logger
25import json
26
27log = create_logger(Config().get('logging'))
28
29parentdir = os.path.join(os.path.dirname(__file__), "..")
30sys.path.insert(0, parentdir)
31
32class SyncProgranServiceInstance(SyncInstanceUsingAnsible):
33 provides = [ProgranServiceInstance]
34
35 observes = ProgranServiceInstance
36
37 def get_onos_info(self, si):
38
39 progran_service = si.owner.leaf_model
40
41 return {
42 'url': progran_service.onos_address,
43 'port': progran_service.onos_port,
44 'username': progran_service.onos_username,
45 'password': progran_service.onos_password,
46 }
47
48 def skip_ansible_fields(self, o):
49 # FIXME This model does not have an instance, this is a workaroung to make it work,
50 # but it need to be cleaned up creating a general SyncUsingAnsible base class
51 return True
52
53 def get_handover_for_profile(self, o):
54 return {
55 "A3Hysteresis": o.handover.HysteresisA3,
56 "A3TriggerQuantity": o.handover.A3TriggerQuantity,
57 "A3offset": o.handover.A3offset,
58 "A5Hysteresis": o.handover.HysteresisA5,
59 "A5Thresh1Rsrp": o.handover.A5Thresh1Rsrp,
60 "A5Thresh1Rsrq": o.handover.A5Thresh1Rsrq,
61 "A5Thresh2Rsrp": o.handover.A5Thresh2Rsrp,
62 "A5Thresh2Rsrq": o.handover.A5Thresh2Rsrq,
63 "A5TriggerQuantity": o.handover.A5TriggerQuantity,
64 }
65
66 def get_progran_profile_field(self, o):
67
68 # basic information that we have in the service instance itself
69 profile = {
70 'AdmControl': o.AdmControl,
71 "DlSchedType": o.DlSchedType,
72 "Start": o.start,
73 "UlSchedType": o.UlSchedType,
74 "End": o.end,
75 "CellIndividualOffset": o.CellIndividualOffset,
76 "DlAllocRBRate": o.DlAllocRBRate,
77 "Name": o.name,
78 "UlAllocRBRate": o.UlAllocRBRate,
79 "Handover": self.get_handover_for_profile(o),
80 }
81 profile = json.dumps(profile)
82 return profile
83
84 def get_extra_attributes(self, o):
85 onos = self.get_onos_info(o)
86 fields = {
87 'onos_url': onos['url'],
88 'onos_username': onos['username'],
89 'onos_password': onos['password'],
90 'onos_port': onos['port'],
91 'endpoint': 'profile',
92 'profile': self.get_progran_profile_field(o),
93 'method': 'POST'
94 }
95
96 return fields
97
98 # FIXME we need to override this as the default expect to ssh into a VM
99 def run_playbook(self, o, fields):
100 run_template("progran_curl.yaml", fields, object=o)
101
102 def delete_record(self, o):
103 log.info("deleting object", object=str(o), **o.tologdict())
104 onos = self.get_onos_info(o)
105 fields = {
106 'onos_url': onos['url'],
107 'onos_username': onos['username'],
108 'onos_password': onos['password'],
109 'onos_port': onos['port'],
110 'endpoint': 'profile/%s' % o.name,
111 'profile': '',
112 'method': 'DELETE'
113 }
114 res = self.run_playbook(o, fields)