From f3b6e279de93b5c03950c192d6aa6044e4c8d2c7 Mon Sep 17 00:00:00 2001 From: Abdul Haleem Date: Thu, 24 Aug 2023 23:37:17 +0530 Subject: [PATCH] host.py: method to get all the mac addresses Gets you a list of all hardware addresses for the given host (local and remote) Signed-off-by: Abdul Haleem --- avocado/utils/network/hosts.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/avocado/utils/network/hosts.py b/avocado/utils/network/hosts.py index 7d61ad6401..ff4d36eee7 100644 --- a/avocado/utils/network/hosts.py +++ b/avocado/utils/network/hosts.py @@ -77,6 +77,19 @@ def get_interface_by_hwaddr(self, mac): if mac in interface.get_hwaddr(): return interface + def get_all_hwaddr(self): + """Get a list of all mac address in the host + + :return: list of mac addresses + """ + cmd = "ip -j address" + output = run_command(cmd, self) + try: + result = json.loads(output) + return [str(item["address"]) for item in result] + except Exception as ex: + raise NWException(f"could not get mac addresses:" f" {ex}") + def validate_mac_addr(self, mac_id): """Check if mac address is valid. This method checks if the mac address is 12 digit hexadecimal number.