1111
1212from mfd_common_libs import log_levels , add_logging_level
1313from mfd_const import MANAGEMENT_NETWORK , Family , Speed
14- from mfd_typing import OSName , PCIDevice , PCIAddress , VendorID
14+ from mfd_typing import OSName , PCIDevice , PCIAddress , VendorID , MACAddress
1515from mfd_typing .network_interface import InterfaceInfo , WindowsInterfaceInfo , LinuxInterfaceInfo
1616
1717from .exceptions import NetworkAdapterConnectedOSNotSupported , NetworkAdapterIncorrectData
@@ -376,6 +376,7 @@ def get_interfaces(
376376 interface_names : Optional [List [str ]] = None ,
377377 random_interface : Optional [bool ] = None ,
378378 all_interfaces : Optional [bool ] = None ,
379+ mac_address : MACAddress | None = None ,
379380 ) -> List ["NetworkInterface" ]:
380381 """
381382 Get Network Interface objects.
@@ -388,6 +389,7 @@ def get_interfaces(
388389 3) (`pci_device`|`family`|`speed`|`family`+`speed`) + (`random_interface`|`all_interfaces`)
389390 4) (`random_interface`|`all_interfaces`)
390391 5) `interface_names`
392+ 6) `mac_address`
391393
392394 :param pci_address: PCI address
393395 :param pci_device: PCI device
@@ -397,6 +399,7 @@ def get_interfaces(
397399 :param interface_names: Names of the interfaces
398400 :param random_interface: Flag - random interface
399401 :param all_interfaces: Flag - all interfaces
402+ :param mac_address: MAC Address of the interface
400403 :return: List of Network Interface objects depending on passed args
401404 """
402405 all_interfaces_info : List [InterfaceInfoType ] = self ._get_all_interfaces_info ()
@@ -410,6 +413,7 @@ def get_interfaces(
410413 interface_names = interface_names ,
411414 random_interface = random_interface ,
412415 all_interfaces = all_interfaces ,
416+ mac_address = mac_address ,
413417 )
414418
415419 if not filtered_info :
@@ -427,6 +431,7 @@ def get_interface(
427431 interface_index : Optional [int ] = None ,
428432 interface_name : Optional [str ] = None ,
429433 namespace : Optional [str ] = None ,
434+ mac_address : MACAddress | None = None ,
430435 ) -> "NetworkInterface" :
431436 """
432437 Get single interface of network adapter.
@@ -435,6 +440,7 @@ def get_interface(
435440 1) interface_name
436441 2) pci_address
437442 3) pci_device / family / speed + interface_index
443+ 4) mac_address
438444
439445 :param pci_address: PCI address
440446 :param pci_device: PCI device
@@ -443,6 +449,7 @@ def get_interface(
443449 :param interface_index: Index of interface, like 0 - first interface of adapter
444450 :param interface_name: Name of the interface
445451 :param namespace: Linux namespace, in which cmd will be executed
452+ :param mac_address: MAC Address of the interface
446453 :return: Network Interface
447454 """
448455 all_interfaces_info : List [InterfaceInfoType ] = self ._get_all_interfaces_info ()
@@ -455,6 +462,7 @@ def get_interface(
455462 interface_indexes = [interface_index ] if interface_index is not None else [],
456463 interface_names = [interface_name ] if interface_name is not None else [],
457464 all_interfaces = True ,
465+ mac_address = mac_address ,
458466 )
459467
460468 if len (filtered_info ) > 1 :
@@ -479,6 +487,7 @@ def _filter_interfaces_info(
479487 interface_names : Optional [List [str ]] = None ,
480488 random_interface : Optional [bool ] = None ,
481489 all_interfaces : Optional [bool ] = None ,
490+ mac_address : MACAddress | None = None ,
482491 ) -> List [InterfaceInfoType ]:
483492 """
484493 Filter list based on passed criteria.
@@ -492,6 +501,7 @@ def _filter_interfaces_info(
492501 :param interface_names: Names of the interfaces
493502 :param random_interface: Flag - random interface
494503 :param all_interfaces: Flag - all interfaces
504+ :param mac_address: MAC Address of the interface
495505 :return: Filtered list of InterfaceInfo objects
496506 """
497507 self ._validate_filtering_args (
@@ -506,6 +516,8 @@ def _filter_interfaces_info(
506516 selected = [info for info in all_interfaces_info if info .name in interface_names ]
507517 elif family is not None or speed is not None :
508518 selected = self ._get_info_by_speed_and_family (all_interfaces_info , family = family , speed = speed )
519+ elif mac_address is not None :
520+ selected = [info for info in all_interfaces_info if info .mac_address == mac_address ]
509521 else :
510522 selected = all_interfaces_info
511523
@@ -565,6 +577,7 @@ def _validate_filtering_args(
565577 family : Optional [str ] = None ,
566578 speed : Optional [str ] = None ,
567579 interface_names : Optional [List [str ]] = None ,
580+ mac_address : MACAddress | None = None ,
568581 ) -> None :
569582 """Validate passed args based on expected combinations."""
570583 passed_combinations_amount = sum (
@@ -573,6 +586,7 @@ def _validate_filtering_args(
573586 pci_device is not None ,
574587 interface_names is not None and interface_names != [],
575588 family is not None or speed is not None ,
589+ mac_address is not None ,
576590 ]
577591 )
578592
@@ -586,7 +600,12 @@ def _validate_filtering_args(
586600 return
587601
588602 NetworkAdapterOwner ._log_selection_criteria (
589- pci_address = pci_address , pci_device = pci_device , interface_names = interface_names , family = family , speed = speed
603+ pci_address = pci_address ,
604+ pci_device = pci_device ,
605+ interface_names = interface_names ,
606+ family = family ,
607+ speed = speed ,
608+ mac_address = mac_address ,
590609 )
591610
592611 def _get_all_interfaces_info (self ) -> List [InterfaceInfoType ]:
0 commit comments