Skip to content

Ansible ND 4.X | WIP | ND Manage Policies Module + Pydantic Models + Smart Endpoints #216

Open
nikhilsrikrishna wants to merge 61 commits intoCiscoDevNet:developfrom
nikhilsrikrishna:nd42_nsk_rebase
Open

Ansible ND 4.X | WIP | ND Manage Policies Module + Pydantic Models + Smart Endpoints #216
nikhilsrikrishna wants to merge 61 commits intoCiscoDevNet:developfrom
nikhilsrikrishna:nd42_nsk_rebase

Conversation

@nikhilsrikrishna
Copy link
Copy Markdown
Collaborator

@nikhilsrikrishna nikhilsrikrishna commented Apr 1, 2026

This PR adds the nd_policy module for switch policy management in the cisco.nd collection, including the core resource handler, endpoint wrappers, and Pydantic models.

What's Included

  • Policy resource handlernd_policy_resources.py supports gathered, merged, and deleted states. Uses bulk create, bulk delete with 207 response handling, the mark-delete → push-config → remove pipeline, and deploy through switch actions.

  • Endpoint definitions — Three endpoint classes: manage_fabrics_policies.py, manage_fabrics_policy_actions.py, manage_fabrics_switch_actions.py.

  • Pydantic model layer — Model classes: config_models.py, gathered_models.py, policy_actions.py, policy_base.py, policy_crud.py. These cover input validation, API response parsing, and gathered output formatting.

  • Input aliasingswitch_id is aliased as switch_ip in the argument spec, allowing users to specify either name interchangeably. Pydantic validators normalize both to the field expected by the API.

  • Template inputs validation — User-provided template_inputs are validated at runtime against the template's parameter schema fetched from the controller, checking for unknown keys, missing required parameters, and basic type correctness. System-injected keys are stripped from gathered output so only user-defined variables are returned.

  • Unit tests — Endpoint-level tests covering all three endpoint classes.

Notes

  • Delete workflow — Delete follows a 3-step flow: markDelete → pushConfig → remove. PYTHON content-type templates (e.g., switch_freeform, Ext_VRF_Lite_SVI) fail on markDelete with "Content type is PYTHON, cannot mark for deletion". Instead of maintaining a hardcoded list of these template names, the module inspects the 207 response — any policy that fails with this specific message is automatically retried via direct DELETE /policies/{policyId}, then deployed via switchActions/deploy to push the config removal to the switch.

  • Gathered state and policy_id — The gathered output includes a policy_id field (e.g., POLICY-28440) alongside the template name. When this output is fed back into state=merged, the policy_id can be directly used to identify the exact policy.

Work In Progress

  • ND output format structure
  • Integration tests

allenrobel and others added 30 commits March 9, 2026 09:45
…nherited from future class models. Modify class models for local_user.
…e.py based on comments. Add a get method and get_identifier_value function to NDBaseModel.
…tion of core design adding new methods which will be used in NDConfigCollection and NDNetworkResourceModule classes as well as basic error handling and simple docstrings.
…ign changing existing methods and adding new ones which will be used in NDNetworkResourceModule class as well as basic error handling and simple docstrings.
…of core design changing existing methods and adding new ones which will be used in future as a based for ND network resource modules as well as basic error handling and simple docstrings.
…s for orchestrating crud api operations with model instances and endpoints.
… built-in functionalities. Slightly modify models/base.py to enforce identifiers definitions in NDBaseModel subclasses. Added multiple notes to assert next steps.
…rt endpoints and Pydantic models modification (works for merge and replace states). Add comments for next steps.
…nts and changes to models/local_user.py and api_endpoints/base.py
…ons methods that work for single_identifier strategy (meant to be overridden if needed).
…or NDNestedModel. Add types.file. Various Renaming and small Modifications across the repo. WIP.
…i_endpoints. Adapt api_endpoints, models, orchestrators accordingly. Integration Tests passing for nd_local_user module. Still WIP.
…teration of (Mock Pydantic objects/methods) to pass sanity checks for Pydantic importation.
…NDStateMachineand add custom Exception for it in common/exceptions dir. Set json mode for to_diff_dict method in NDBaseModel.
@mikewiebe
Copy link
Copy Markdown
Collaborator

mikewiebe commented Apr 6, 2026

I see sanity test and formatting failures. Make sure to run the following commands locally and fix any issues

ansible-test sanity --docker -v --color --truncate 0

black --color -l 159 .

@mtarking mtarking deleted the branch CiscoDevNet:develop April 9, 2026 15:41
@mtarking mtarking closed this Apr 9, 2026
@mtarking mtarking reopened this Apr 9, 2026
@mtarking mtarking changed the base branch from nd42_integration to develop April 9, 2026 15:43
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.

6 participants