Himanshu Bhandari | 32738e8 | 2020-06-10 21:08:49 +0530 | [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 __future__ import absolute_import |
| 16 | from xosconfig import Config |
| 17 | from multistructlog import create_logger |
| 18 | |
| 19 | log = create_logger(Config().get('logging')) |
| 20 | |
| 21 | class Helpers(): |
| 22 | |
| 23 | @staticmethod |
| 24 | def format_url(url): |
| 25 | if 'http' in url: |
| 26 | return url |
| 27 | else: |
| 28 | return 'http://%s' % url |
| 29 | |
| 30 | @staticmethod |
| 31 | def get_fabric_onos_info(model_accessor, service): |
| 32 | fabric_onos = [s.leaf_model for s in service.provider_services if "onos" in s.name.lower()] |
| 33 | if len(fabric_onos) == 0: |
| 34 | raise Exception('Cannot find ONOS service in provider_services of Fabric-Crossconnect') |
| 35 | |
| 36 | fabric_onos = fabric_onos[0] |
| 37 | return { |
| 38 | 'url': Helpers.format_url( |
| 39 | "%s:%s" % |
| 40 | (fabric_onos.rest_hostname, |
| 41 | fabric_onos.rest_port)), |
| 42 | 'user': fabric_onos.rest_username, |
| 43 | 'pass': fabric_onos.rest_password} |
| 44 | |
| 45 | @staticmethod |
| 46 | def range_matches(value, pattern): |
| 47 | value = int(value) |
| 48 | for this_range in pattern.split(","): |
| 49 | this_range = this_range.strip() |
| 50 | if "-" in this_range: |
| 51 | (first, last) = this_range.split("-") |
| 52 | first = int(first.strip()) |
| 53 | last = int(last.strip()) |
| 54 | if (value >= first) and (value <= last): |
| 55 | return True |
| 56 | elif this_range.lower() == "any": |
| 57 | return False |