Skip to content

Openstack get mac external dhcp#16

Merged
dkmstr merged 8 commits into
masterfrom
fix/openstack-mac-external-dhcp
Jun 15, 2026
Merged

Openstack get mac external dhcp#16
dkmstr merged 8 commits into
masterfrom
fix/openstack-mac-external-dhcp

Conversation

@aschumann-virtualcable

Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and refactorings to the OpenStack service integration, focusing on more robust MAC address retrieval, support for external DHCP environments, and modernizing type annotations. The most significant changes include the addition of a new PortInfo type, a get_server_mac method that can retrieve MAC addresses even when Nova's addresses field is empty, and a general migration to Python 3.10+ union type syntax. These changes enhance reliability in diverse OpenStack network configurations and improve code clarity.

OpenStack MAC Address Handling and External DHCP Support:

  • Added a new PortInfo dataclass in openstack/types.py to represent Neutron port information, including MAC addresses and fixed IPs. ([src/uds/services/OpenStack/openstack/types.pyR248-R271](https://github.com/VirtualCable/broker/pull/16/files#diff-fb2f112db2b28da61a16af9b168ee4fa051d5373f453378fb50c3d59413c2133R248-R271))
  • Implemented get_server_mac in OpenStackClient, which attempts to retrieve the MAC address from Nova server info and, if unavailable (e.g., due to external DHCP), queries Neutron ports as a fallback. This prevents errors when the MAC is temporarily unavailable. ([src/uds/services/OpenStack/openstack/client.pyR615-R636](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8R615-R636))
  • Updated service methods (get_mac, get_ip, etc.) in service.py and service_fixed.py to use the new get_server_mac method, improving reliability when dealing with external DHCP setups. ([[1]](https://github.com/VirtualCable/broker/pull/16/files#diff-e4398775b85f8b64749496e908ea090e4eb367d72c1c418e5cfe36d19e994a78L254-R281), [[2]](https://github.com/VirtualCable/broker/pull/16/files#diff-5017c1760c5d340a51243d50042a1c32feb4385c57ea9a4c520765885bb1b980L199-R201), [[3]](https://github.com/VirtualCable/broker/pull/16/files#diff-eb9a50ffe95cc963b15364929e45b332d1ac1bfdb632640d333c27bedb28a3e3L172-R176))

API and Type Annotation Modernization:

  • Refactored type annotations throughout the OpenStack provider, service, and client classes to use the more modern X | Y union syntax instead of typing.Optional and typing.Union. ([[1]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L109-R122), [[2]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L138-R141), [[3]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L292-R292), [[4]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L479-R479), [[5]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L618-R663), [[6]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L836-R882), [[7]](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8L865-R910), [[8]](https://github.com/VirtualCable/broker/pull/16/files#diff-a17350e2ba6601a4ba8b2a333351f4a959f6385c6968e0f8d5533c6e863953a3L205-R205), [[9]](https://github.com/VirtualCable/broker/pull/16/files#diff-a17350e2ba6601a4ba8b2a333351f4a959f6385c6968e0f8d5533c6e863953a3L223-R223), [[10]](https://github.com/VirtualCable/broker/pull/16/files#diff-c11cfa39f16f066ce38b75c9a31cf7cba8c444cbbb82e7f5bf5861fae14bc546L178-R178), [[11]](https://github.com/VirtualCable/broker/pull/16/files#diff-c11cfa39f16f066ce38b75c9a31cf7cba8c444cbbb82e7f5bf5861fae14bc546L190-R192), [[12]](https://github.com/VirtualCable/broker/pull/16/files#diff-e4398775b85f8b64749496e908ea090e4eb367d72c1c418e5cfe36d19e994a78L57-R57), [[13]](https://github.com/VirtualCable/broker/pull/16/files#diff-e4398775b85f8b64749496e908ea090e4eb367d72c1c418e5cfe36d19e994a78L189-R189), [[14]](https://github.com/VirtualCable/broker/pull/16/files#diff-e4398775b85f8b64749496e908ea090e4eb367d72c1c418e5cfe36d19e994a78L321-R320), [[15]](https://github.com/VirtualCable/broker/pull/16/files#diff-5017c1760c5d340a51243d50042a1c32feb4385c57ea9a4c520765885bb1b980L51-R51), [[16]](https://github.com/VirtualCable/broker/pull/16/files#diff-5017c1760c5d340a51243d50042a1c32feb4385c57ea9a4c520765885bb1b980L108-R108), [[17]](https://github.com/VirtualCable/broker/pull/16/files#diff-5017c1760c5d340a51243d50042a1c32feb4385c57ea9a4c520765885bb1b980L167-R167))

Neutron Port Query Support:

  • Added a list_ports method to OpenStackClient to allow querying Neutron for ports by network or device ID, supporting the new MAC address retrieval logic. ([src/uds/services/OpenStack/openstack/client.pyR567-R589](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8R567-R589))

General Code Quality Improvements:

  • Improved error handling in MAC retrieval to avoid crashing state checkers when transient errors or empty results occur, instead returning an empty string to trigger retries. ([src/uds/services/OpenStack/openstack/client.pyR615-R636](https://github.com/VirtualCable/broker/pull/16/files#diff-c0480f8af38b2e89a44f5280fcd1bef82024145e3bae832fc49b37273eff4bd8R615-R636))
  • Cleaned up and clarified method signatures, variable assignments, and docstrings for maintainability and readability. ([[1]](https://github.com/VirtualCable/broker/pull/16/files#diff-a9299b29c8d705ff40152bc547657c14a722ceca19677fc6bafa32e84e78ab4cL51-R51), [[2]](https://github.com/VirtualCable/broker/pull/16/files#diff-e4398775b85f8b64749496e908ea090e4eb367d72c1c418e5cfe36d19e994a78L293-R298))

These changes make the OpenStack integration more robust in real-world network environments and prepare the codebase for future Python enhancements.

janpenitent and others added 6 commits June 5, 2026 16:48
… DHCP

OpenStack assigns the mac at the platform level, so get_mac must read it
from the API. With external DHCP the server 'addresses' field comes back
empty, leaving unique_id blank: cache machines never reached "valid" and
the actor reported "Unmanaged host".

- Fall back to the Neutron port mac (mac_address is always present,
  regardless of DHCP/IP allocation) when 'addresses' is empty.
- Tolerate not-yet-created (404) and policy/transient errors (403/...)
  by degrading to '' so the state checker retries instead of forcing
  the userservice to ERROR.
- Apply the same fix to the fixed service (also fixes an IndexError on
  addresses[0] under external DHCP).
- Add list_ports() + PortInfo to the OpenStack client/types.
- Cover both services with tests (live + fixed).
op_create_checker bypassed the guarded get_mac/get_ip and read
server_info.addresses[0] directly. Under external DHCP, Nova leaves
'addresses' empty, so addresses[0] raised IndexError and pushed the
userservice to ERROR. Reuse the guarded service methods instead: get_mac
resolves the mac via the Neutron port and get_ip returns '' (the real ip
is learned later from the actor).
@dkmstr dkmstr merged commit 4f7571c into master Jun 15, 2026
3 of 4 checks passed
@aschumann-virtualcable aschumann-virtualcable deleted the fix/openstack-mac-external-dhcp branch June 17, 2026 08:59
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.

3 participants