Skip to content

Add Multi-Tenancy Modules#258

Draft
mtarking wants to merge 3 commits intodevelopfrom
issue-257
Draft

Add Multi-Tenancy Modules#258
mtarking wants to merge 3 commits intodevelopfrom
issue-257

Conversation

@mtarking
Copy link
Copy Markdown
Collaborator

@mtarking mtarking commented Apr 14, 2026

Related Issue(s)

Resolves #257

Proposed Changes

Add two new Ansible modules for managing Nexus Dashboard multi-tenancy resources using the new pydantic-based architecture:

nd_infra_tenant — Manage tenants on Cisco Nexus Dashboard

  • CRUD operations for tenants via the ND Infra API (/api/v1/infra/tenants)
  • Fabric association management via the ND Manage API (/api/v1/manage/tenantFabricAssociations)
  • Multi-API orchestrator that coordinates tenant lifecycle (infra) with fabric association reconciliation (manage) transparently through the state machine
  • Supports merged, replaced, overridden, and deleted states

nd_infra_tenant_domain — Manage tenant domains on Cisco Nexus Dashboard

  • CRUD operations for tenant domains via the ND Infra API (/api/v1/infra/tenantDomains)
  • Groups tenants together by referencing tenant names
  • Supports merged, replaced, overridden, and deleted states

New files:

  • plugins/modules/nd_infra_tenant.py
  • plugins/modules/nd_infra_tenant_domain.py
  • plugins/module_utils/models/infra_tenant/infra_tenant.py
  • plugins/module_utils/models/infra_tenant_domain/infra_tenant_domain.py
  • plugins/module_utils/orchestrators/infra_tenant.py
  • plugins/module_utils/orchestrators/infra_tenant_domain.py
  • plugins/module_utils/endpoints/v1/infra/tenants.py
  • plugins/module_utils/endpoints/v1/infra/tenant_domains.py
  • plugins/module_utils/endpoints/v1/manage/tenant_fabric_associations.py
  • tests/unit/module_utils/endpoints/test_endpoints_api_v1_infra_tenants.py
  • tests/unit/module_utils/endpoints/test_endpoints_api_v1_infra_tenant_domains.py
  • tests/unit/module_utils/endpoints/test_endpoints_api_v1_manage_tenant_fabric_associations.py
  • tests/integration/targets/nd_infra_tenant/tasks/main.yml
  • tests/integration/targets/nd_infra_tenant_domain/tasks/main.yml

Test Notes

  • 347 unit tests pass (pytest tests/unit/ -v), including 38 new endpoint tests covering infra tenants (16), infra tenant domains (16), and manage tenant fabric associations (6)
  • Integration tests cover all four states (merged, replaced, overridden, deleted) with check mode, normal mode, and idempotency assertions for both modules
  • nd_infra_tenant integration tests include fabric association scenarios: create with associations, update associations, replace with associations, override with associations, and delete with association cleanup

Cisco Nexus Dashboard Version

4.2.1

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

@mtarking mtarking self-assigned this Apr 14, 2026
@mtarking mtarking added enhancement New feature or request tests Tests added/updated/modified 2.0.0 Release 2.0.0 labels Apr 14, 2026
"""

fabric_name: str = Field(alias="fabricName")
allowed_vlans: Optional[List[str]] = Field(default=None, alias="allowedVlans")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be aligned with the pattern matching from @allenrobel https://github.com/CiscoDevNet/ansible-nd/pull/270/changes#diff-d2ab524cc8cd4727b8449727f59773a79668d8ac08e5617de6638ef13c4c74a4R58? Is there currently some shared pattern or shared field setup?

wider alignment might abe required also for doc fragments in this case

from ansible_collections.cisco.nd.plugins.module_utils.types import IdentifierKey


class TenantDomainNameMixin(BaseModel):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not part of the mixins.py file?

from ansible_collections.cisco.nd.plugins.module_utils.types import IdentifierKey


class TenantNameMixin(BaseModel):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this not part of the mixins.py file?

from ansible_collections.cisco.nd.plugins.module_utils.models.nested import NDNestedModel


class InfraTenantFabricAssociationModel(NDNestedModel):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this part of infra_tenant folder when the endpoint appears in manage?

of dicts with snake_case keys.
"""

# --- Identifier Configuration ---
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i notice that there are multiple styles maintained across PRs where you introduce these comments, is this a standard that should be enforced throughout the repository?

query_one_endpoint: Type[NDEndpointBaseModel] = EpInfraTenantsGet
query_all_endpoint: Type[NDEndpointBaseModel] = EpInfraTenantsGet

# --- Helpers for fabric associations (manage API) ---
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are all these functions not a isolated orchestrator that is specific for the InfraTenantFabricAssociationModel?

description:
- Manage tenants on Cisco Nexus Dashboard (ND).
- It supports creating, updating, and deleting tenants.
- Optionally manage fabric associations for each tenant, linking tenants to NDFC-managed fabrics
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is NDFC still correct here?

fabric_associations:
description:
- The list of fabric associations for the tenant.
- Each entry associates the tenant with a fabric managed by NDFC and defines the allowed VLANs.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is NDFC still correct here? likely in more locations

description:
description:
- The description of the tenant.
- The description can be up to 128 characters.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not wrong but I notice different modules use different description notation for similar things like max amount of characters allowed. Do we want to align the description sentence for ranges and maximum characters, etc. As example it deviates from: https://github.com/CiscoDevNet/ansible-nd/pull/270/changes#diff-1bc3ea994025d9c3d17dfc41a4b4e62aba250b851cd388081f17ada991dc838bR120.

- fabric_name: my_fabric
allowed_vlans:
- "10-50"
state: replaced
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is more a generic example question, is it on purpose to only show examples for merged, replaced and deleted states? This also deviates from what I have seen for instance in comment made here: https://github.com/CiscoDevNet/ansible-nd/pull/270/changes#r3186791791

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

Labels

2.0.0 Release 2.0.0 enhancement New feature or request tests Tests added/updated/modified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ND 4.2+] Add Multi-Tenancy Support

2 participants