1111
1212from mfd_common_libs import log_levels , add_logging_level
1313from mfd_const import SPEED_IDS , DEVICE_IDS , 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
@@ -371,6 +371,7 @@ def get_interfaces(
371371 interface_names : Optional [List [str ]] = None ,
372372 random_interface : Optional [bool ] = None ,
373373 all_interfaces : Optional [bool ] = None ,
374+ mac_address : MACAddress | None = None ,
374375 ) -> List ["NetworkInterface" ]:
375376 """
376377 Get Network Interface objects.
@@ -383,6 +384,7 @@ def get_interfaces(
383384 3) (`pci_device`|`family`|`speed`|`family`+`speed`) + (`random_interface`|`all_interfaces`)
384385 4) (`random_interface`|`all_interfaces`)
385386 5) `interface_names`
387+ 6) `mac_address`
386388
387389 :param pci_address: PCI address
388390 :param pci_device: PCI device
@@ -392,6 +394,7 @@ def get_interfaces(
392394 :param interface_names: Names of the interfaces
393395 :param random_interface: Flag - random interface
394396 :param all_interfaces: Flag - all interfaces
397+ :param mac_address: MAC Address of the interface
395398 :return: List of Network Interface objects depending on passed args
396399 """
397400 all_interfaces_info : List [InterfaceInfoType ] = self ._get_all_interfaces_info ()
@@ -405,6 +408,7 @@ def get_interfaces(
405408 interface_names = interface_names ,
406409 random_interface = random_interface ,
407410 all_interfaces = all_interfaces ,
411+ mac_address = mac_address ,
408412 )
409413
410414 if not filtered_info :
@@ -422,6 +426,7 @@ def get_interface(
422426 interface_index : Optional [int ] = None ,
423427 interface_name : Optional [str ] = None ,
424428 namespace : Optional [str ] = None ,
429+ mac_address : MACAddress | None = None ,
425430 ) -> "NetworkInterface" :
426431 """
427432 Get single interface of network adapter.
@@ -430,6 +435,7 @@ def get_interface(
430435 1) interface_name
431436 2) pci_address
432437 3) pci_device / family / speed + interface_index
438+ 4) mac_address
433439
434440 :param pci_address: PCI address
435441 :param pci_device: PCI device
@@ -438,6 +444,7 @@ def get_interface(
438444 :param interface_index: Index of interface, like 0 - first interface of adapter
439445 :param interface_name: Name of the interface
440446 :param namespace: Linux namespace, in which cmd will be executed
447+ :param mac_address: MAC Address of the interface
441448 :return: Network Interface
442449 """
443450 all_interfaces_info : List [InterfaceInfoType ] = self ._get_all_interfaces_info ()
@@ -450,6 +457,7 @@ def get_interface(
450457 interface_indexes = [interface_index ] if interface_index is not None else [],
451458 interface_names = [interface_name ] if interface_name is not None else [],
452459 all_interfaces = True ,
460+ mac_address = mac_address ,
453461 )
454462
455463 if len (filtered_info ) > 1 :
@@ -474,6 +482,7 @@ def _filter_interfaces_info(
474482 interface_names : Optional [List [str ]] = None ,
475483 random_interface : Optional [bool ] = None ,
476484 all_interfaces : Optional [bool ] = None ,
485+ mac_address : MACAddress | None = None ,
477486 ) -> List [InterfaceInfoType ]:
478487 """
479488 Filter list based on passed criteria.
@@ -487,6 +496,7 @@ def _filter_interfaces_info(
487496 :param interface_names: Names of the interfaces
488497 :param random_interface: Flag - random interface
489498 :param all_interfaces: Flag - all interfaces
499+ :param mac_address: MAC Address of the interface
490500 :return: Filtered list of InterfaceInfo objects
491501 """
492502 self ._validate_filtering_args (
@@ -501,6 +511,8 @@ def _filter_interfaces_info(
501511 selected = [info for info in all_interfaces_info if info .name in interface_names ]
502512 elif family is not None or speed is not None :
503513 selected = self ._get_info_by_speed_and_family (all_interfaces_info , family = family , speed = speed )
514+ elif mac_address is not None :
515+ selected = [info for info in all_interfaces_info if info .mac_address == mac_address ]
504516 else :
505517 selected = all_interfaces_info
506518
@@ -560,6 +572,7 @@ def _validate_filtering_args(
560572 family : Optional [str ] = None ,
561573 speed : Optional [str ] = None ,
562574 interface_names : Optional [List [str ]] = None ,
575+ mac_address : MACAddress | None = None ,
563576 ) -> None :
564577 """Validate passed args based on expected combinations."""
565578 passed_combinations_amount = sum (
@@ -568,6 +581,7 @@ def _validate_filtering_args(
568581 pci_device is not None ,
569582 interface_names is not None and interface_names != [],
570583 family is not None or speed is not None ,
584+ mac_address is not None ,
571585 ]
572586 )
573587
@@ -581,7 +595,12 @@ def _validate_filtering_args(
581595 return
582596
583597 NetworkAdapterOwner ._log_selection_criteria (
584- pci_address = pci_address , pci_device = pci_device , interface_names = interface_names , family = family , speed = speed
598+ pci_address = pci_address ,
599+ pci_device = pci_device ,
600+ interface_names = interface_names ,
601+ family = family ,
602+ speed = speed ,
603+ mac_address = mac_address ,
585604 )
586605
587606 def _get_all_interfaces_info (self ) -> List [InterfaceInfoType ]:
0 commit comments