blob: 7e72bef96c23a8552c9a8b7334f792547a4fadbb [file] [log] [blame]
Zack Williams41513bf2018-07-07 20:08:35 -07001# 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.
Nathan Knuth418fdc82016-09-16 22:51:15 -070014"""
15Common utility functions
16"""
17
18from loxi.pp import PrettyPrinter
19
20
21def pp(obj):
22 pp = PrettyPrinter(maxwidth=80)
23 pp.pp(obj)
24 return str(pp)
25
26def mac_str_to_tuple(mac):
27 """
28 Convert 'xx:xx:xx:xx:xx:xx' MAC address string to a tuple of integers.
29 Example: mac_str_to_tuple('00:01:02:03:04:05') == (0, 1, 2, 3, 4, 5)
30 """
31 return tuple(int(d, 16) for d in mac.split(':'))