Zack Williams | 41513bf | 2018-07-07 20:08:35 -0700 | [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. |
Nathan Knuth | 418fdc8 | 2016-09-16 22:51:15 -0700 | [diff] [blame] | 14 | """ |
| 15 | Common utility functions |
| 16 | """ |
| 17 | |
| 18 | from loxi.pp import PrettyPrinter |
| 19 | |
| 20 | |
| 21 | def pp(obj): |
| 22 | pp = PrettyPrinter(maxwidth=80) |
| 23 | pp.pp(obj) |
| 24 | return str(pp) |
| 25 | |
| 26 | def 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(':')) |