blob: ad2da327d514b6e7a366a8db537400e8c99400f9 [file] [log] [blame]
Matteo Scandolof0441032017-08-08 13:05:26 -07001
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
Scott Bakerc808c672019-02-04 11:38:20 -080017from xosconfig import Config
18from multistructlog import create_logger
19
20log = create_logger(Config().get('logging'))
Scott Bakerb63ea792016-08-11 10:24:48 -070021
Matteo Scandoloceccb1f2017-06-05 10:35:44 -070022
Scott Bakerb63ea792016-08-11 10:24:48 -070023class ErrorMapper:
Matteo Scandoloceccb1f2017-06-05 10:35:44 -070024 def __init__(self, error_map_file):
25 self.error_map = {}
26 try:
27 error_map_lines = open(error_map_file).read().splitlines()
28 for l in error_map_lines:
29 if (not l.startswith('#')):
30 splits = l.split('->')
31 k, v = map(lambda i: i.rstrip(), splits)
32 self.error_map[k] = v
33 except:
Scott Bakerc808c672019-02-04 11:38:20 -080034 log.info('Could not read error map')
Scott Bakerb63ea792016-08-11 10:24:48 -070035
Matteo Scandoloceccb1f2017-06-05 10:35:44 -070036 def map(self, error):
37 return self.error_map[error]