Skip to content

Add nd_interface_ethernet_trunk_host module#264

Closed
allenrobel wants to merge 2 commits intond_interface_ethernet_accessfrom
nd_interface_ethernet_trunk
Closed

Add nd_interface_ethernet_trunk_host module#264
allenrobel wants to merge 2 commits intond_interface_ethernet_accessfrom
nd_interface_ethernet_trunk

Conversation

@allenrobel
Copy link
Copy Markdown
Collaborator

Related Issue(s)

Stacks on top of #222 (access module).

Proposed Changes

Adds the nd_interface_ethernet_trunk_host module for managing Cisco Nexus Dashboard 4.2 ethernet interfaces with the trunkHost policy type. Parallels nd_interface_ethernet_access: composite (switch_ip, interface_name) identifier, bulk create / bulk normalize-as-delete, per-interface deploy queueing, and the full merged / replaced / overridden / deleted state lifecycle.

  • New EthernetTrunkHostInterfaceModel with trunk-specific fields — allowed_vlans (regex-validated, accepts none, all, or comma-separated IDs/ranges), native_vlan, vlan_mapping, and nested vlan_mapping_entries with customer_vlan_id as List[str] to match the ND API.
  • TrunkHostPolicyTypeEnum added to shared interface enums.
  • EthernetTrunkHostInterfaceOrchestrator filters query_all to exclude interfaces matching the unconfigured int_trunk_host default signature, so state: overridden is idempotent on the second run. Normalizing a trunkHost interface produces another trunkHost interface, so without this filter every fabric-default interface would appear in before and be re-queued for normalization on every run.
  • InterfaceDefaultPolicyModel gains description: "" and nativeVlan: 1 so interfaceActions/normalize actually clears user-set descriptions and native VLANs on deleted / overridden interfaces instead of leaving them behind. This affects all ethernet modules that delete via normalize, which is the desired behavior.
  • allowed_vlans validator coerces bare-integer ND responses (e.g. a single VLAN returned as 999) to string before regex validation.
  • Integration tests cover all four states. selectattr('interface_name', ...) lookups are scoped by switch_ip so assertions hold on multi-switch fabrics. The VLAN-mapping test block is gated on a supports_vlan_mapping extra-var because Nexus 9000v virtual switches reject switchport vlan mapping ... dot1q-tunnel ... at the NX-OS layer.

Test Notes

  • Full integration suite passes against an ND 4.2 testbed with two Nexus 9000v switches in the target fabric: ansible-test network-integration nd_interface_ethernet_trunk_host -v.
  • Merged, replaced, overridden (including idempotent re-run), and deleted states all pass.
  • VLAN-mapping block is skipped by default; to exercise it on a hardware testbed add --extra-vars supports_vlan_mapping=true.
  • Unit tests are deferred for v1, matching the access module (per the same decision in nd_interface_ethernet_access module #222).

Cisco Nexus Dashboard Version

4.2

Related ND API Resource Category

  • analyze
  • infra
  • manage
  • onemanage
  • other

Checklist

  • Latest commit is rebased from develop with merge conflicts resolved
  • New or updates to documentation has been made accordingly
  • Assigned the proper reviewers

allenrobel and others added 2 commits April 21, 2026 15:55
Adds a new Ansible module for CRUD operations on host-facing ethernet
trunk interfaces in Nexus Dashboard 4.2. Follows the same composite-
identifier, bulk-CRUD, and deploy-lifecycle pattern as the access
module, filtering on policyType=trunkHost.

- TrunkHostPolicyTypeEnum added to shared interface enums.
- EthernetTrunkHostInterfaceModel defines trunk-specific policy fields
  (allowed_vlans with regex validator, native_vlan, vlan_mapping,
  vlan_mapping_entries) and reuses shared enums for the rest.
- EthernetTrunkHostInterfaceOrchestrator inherits the shared ethernet
  base; only _managed_policy_types() is type-specific.
- Integration test target covers merged/replaced/overridden/deleted.
  Unit tests deferred to match nd_interface_ethernet_access.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Resolves issues surfaced by the full trunk-host integration run:

- `EthernetTrunkHostVlanMappingEntryModel.customer_vlan_id` is now
  `List[str]`, matching the ND API which expects `customerVlanId` as an
  array of VLAN tokens rather than a single string.
- `EthernetTrunkHostPolicyModel.validate_allowed_vlans` now coerces
  integer input to string before regex validation, so ND responses that
  return a single-VLAN `allowedVlans` as a bare integer (e.g. `999`) no
  longer raise a Pydantic `ValueError`.
- `InterfaceDefaultPolicyModel` now includes `description: ""` and
  `nativeVlan: 1`, so `interfaceActions/normalize` fully resets user-set
  descriptions and native VLANs on deleted / overridden interfaces
  instead of leaving them behind.
- `EthernetTrunkHostInterfaceOrchestrator.query_all` filters out
  interfaces matching the unconfigured `int_trunk_host` default
  signature. Normalizing a trunkHost interface produces another
  trunkHost interface, so without this filter `state: overridden` could
  not be idempotent (every fabric-default interface appeared in `before`
  and was re-queued for normalization on every run).
- Integration tests scope `selectattr('interface_name', ...)` lookups
  by `switch_ip` so assertions work on multi-switch fabrics, and the
  VLAN-mapping block is gated on a new `supports_vlan_mapping` extra-var
  because Nexus 9000v virtual switches reject
  `switchport vlan mapping ... dot1q-tunnel ...`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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