Skip to content

Conversation

joaomariolago
Copy link
Collaborator

@joaomariolago joaomariolago commented Aug 20, 2025

Depends on #3479

Summary by Sourcery

Refactor and simplify the get_interfaces workflow by extracting address processing, DHCP marker handling, priority resolution, and network interface construction into dedicated helper methods, and add support for an optional include_dhcp_markers flag across relevant methods.

Enhancements:

  • Extract address parsing and mode determination into _process_interface_addresses and _determine_address_mode helper methods
  • Introduce _add_dhcp_markers_if_needed to optionally preserve DHCP client markers
  • Centralize interface priority lookup in _get_interface_priority_value and network interface assembly in _build_network_interface
  • Add include_dhcp_markers parameter to get_interface_by_name, get_interfaces, and get_ethernet_interfaces

* Make sure that when `_execute_route` is called it keeps the DHCP
  requisition IP marker `0.0.0.0` `Mode.Client` alive
* Split `get_interfaces` method to reduce code complexity
Copy link

sourcery-ai bot commented Aug 20, 2025

Reviewer's Guide

Refactors get_interfaces and related methods by extracting address processing and interface building into private helpers, adds an include_dhcp_markers option across interface retrieval methods, and updates calls to utilize the new parameters.

Sequence diagram for interface retrieval with DHCP marker option

sequenceDiagram
    participant Caller
    participant Manager
    participant NetworkInterface
    Caller->>Manager: get_ethernet_interfaces(include_dhcp_markers=True)
    Manager->>Manager: get_interfaces(filter_wifi=True, include_dhcp_markers=True)
    Manager->>Manager: _process_interface_addresses(...)
    Manager->>Manager: _add_dhcp_markers_if_needed(..., include_dhcp_markers=True)
    Manager->>Manager: _build_network_interface(...)
    Manager-->>Caller: List[NetworkInterface] (with DHCP marker if needed)
Loading

Class diagram for refactored interface retrieval methods

classDiagram
    class Manager {
        +get_interfaces(filter_wifi: bool = False, include_dhcp_markers: bool = False) List[NetworkInterface]
        +get_ethernet_interfaces(include_dhcp_markers: bool = False) List[NetworkInterface]
        +get_interface_by_name(name: str, include_dhcp_markers: bool = False) NetworkInterface
        -_process_interface_addresses(interface: str, addresses: List[Any]) List[InterfaceAddress]
        -_add_dhcp_markers_if_needed(interface: str, valid_addresses: List[InterfaceAddress], include_dhcp_markers: bool) List[InterfaceAddress]
        -_determine_address_mode(interface: str, ip: str, is_static_ip: bool, valid_ip: bool) AddressMode
        -_get_interface_priority_value(interface: str) Optional[int]
        -_build_network_interface(interface: str, valid_addresses: List[InterfaceAddress], filter_wifi: bool) Optional[NetworkInterface]
    }
    class NetworkInterface {
        +name: str
        +addresses: List[InterfaceAddress]
        +info: Any
        +priority: Optional[int]
        +routes: List[Route]
    }
    class InterfaceAddress {
        +ip: str
        +mode: AddressMode
    }
    class AddressMode {
        <<enum>>
        Server
        BackupServer
        Unmanaged
        Client
    }
    Manager --> NetworkInterface
    NetworkInterface --> InterfaceAddress
    InterfaceAddress --> AddressMode
Loading

File-Level Changes

Change Details Files
Extracted and encapsulated address and interface building logic into private helper methods
  • Added _determine_address_mode to centralize address mode decision
  • Introduced _process_interface_addresses to filter and wrap IPv4 addresses
  • Created _add_dhcp_markers_if_needed to append DHCP markers when requested
  • Implemented _get_interface_priority_value to unify priority retrieval
  • Built _build_network_interface to assemble and validate interface objects
core/services/cable_guy/api/manager.py
Added include_dhcp_markers flag to interface retrieval methods
  • Extended get_interface_by_name signature with include_dhcp_markers
  • Added include_dhcp_markers parameter and docstring to get_interfaces
  • Propagated include_dhcp_markers into get_ethernet_interfaces
core/services/cable_guy/api/manager.py
Refactored get_interfaces to leverage helper methods and reduce complexity
  • Replaced inline address loop with calls to _process_interface_addresses and _add_dhcp_markers_if_needed
  • Replaced inline priority logic with _get_interface_priority_value
  • Swapped manual NetworkInterface construction with _build_network_interface
core/services/cable_guy/api/manager.py
Updated route execution to use new interface retrieval signature
  • Modified _execute_route to call get_interface_by_name with include_dhcp_markers=True
core/services/cable_guy/api/manager.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant