Matteo Scandolo | 0a207b5 | 2018-01-29 13:39:43 -0800 | [diff] [blame] | 1 | # Copyright 2017-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | from xosconfig import Config |
| 16 | from multistructlog import create_logger |
| 17 | from synchronizers.new_base.modelaccessor import ProgranService |
| 18 | |
| 19 | log = create_logger(Config().get('logging')) |
| 20 | |
| 21 | class ProgranHelpers(): |
| 22 | |
| 23 | @staticmethod |
| 24 | def get_onos_info_from_si(service_instance): |
| 25 | progran_service = service_instance.owner.leaf_model |
| 26 | return ProgranHelpers.get_onos_info_from_service(progran_service) |
| 27 | |
| 28 | @staticmethod |
| 29 | def get_progran_onos_info(): |
Matteo Scandolo | 6b607c8 | 2018-01-30 09:12:26 -0800 | [diff] [blame] | 30 | try: |
| 31 | progran_service = ProgranService.objects.all()[0] |
| 32 | except IndexError: |
| 33 | log.error("Cannot find Progran Service, does it exists?") |
Matteo Scandolo | 0a207b5 | 2018-01-29 13:39:43 -0800 | [diff] [blame] | 34 | return ProgranHelpers.get_onos_info_from_service(progran_service) |
| 35 | |
| 36 | @staticmethod |
| 37 | def get_onos_info_from_service(progran_service): |
| 38 | return { |
| 39 | 'url': progran_service.onos_address, |
| 40 | 'port': progran_service.onos_port, |
| 41 | 'username': progran_service.onos_username, |
| 42 | 'password': progran_service.onos_password, |
| 43 | } |