[ND 4.2+] Add verbosity gated results (NDA-20)#262
Open
gmicol wants to merge 4 commits intoCiscoDevNet:developfrom
Open
[ND 4.2+] Add verbosity gated results (NDA-20)#262gmicol wants to merge 4 commits intoCiscoDevNet:developfrom
gmicol wants to merge 4 commits intoCiscoDevNet:developfrom
Conversation
…tils with AnsibleModule private attribute _verbosity.
c34bce7 to
787924e
Compare
6542628 to
1a61136
Compare
1a61136 to
7e44a93
Compare
akinross
reviewed
May 5, 2026
| api_endpoint = self.query_one_endpoint() | ||
| api_endpoint.set_identifiers(model_instance.get_identifier_value()) | ||
| return self._request(path=api_endpoint.path, verb=api_endpoint.verb) | ||
| return self._request(path=api_endpoint.path, verb=api_endpoint.verb, operation_type=OperationType.QUERY) |
Collaborator
There was a problem hiding this comment.
why add the operation_type for the query functions when you define as default in _request?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Verbosity-Gated API Call Results
This PR adds CLI verbosity-gated observability to all modules using the
NDStateMachinepattern. When users increase Ansible CLI verbosity (-vv,-vvv), module output progressively includes API call details (endpoints, payloads, responses) without any new module parameters or Ansible dependencies.Architecture
Resultsis tagged with averbosity_level(2 for write operations, 3 for queries). At output time,format_with_verbosity()filters tasks based on the CLI verbosity level.module._verbosity(standardAnsibleModuleattribute). NoDisplay()import or new Ansible dependency is introduced in the orchestrator or REST layers.Verbosity Tiers
-vchanged,before,after)-vvapi_paths,api_verbsfor write operations (CREATE/UPDATE/DELETE)-vvvapi_response,api_result,api_diff,api_metadata,api_payloadFiles Changed
Core infrastructure (3 files):
plugins/module_utils/orchestrators/base.pyresults: Optional[Results] = Nonefield toNDBaseOrchestrator._register_api_call()method that tags each REST call with action, path, verb, payload, response, result, andverbosity_level(2 for writes, 3 for queries).operation_type: OperationType = OperationType.QUERYparameter to_request().create,update,delete,query_one,query_all) now pass the correctOperationTypeto_request().plugins/module_utils/nd_output.pyformat_with_verbosity(verbosity: int, results: Optional[Results] = None, **kwargs)method toNDOutput.Resultsif not already built, filters tasks byverbosity_level <= verbosity.api_pathsandapi_verbsto output.api_response,api_result,api_diff,api_metadata,api_payload.changed/failedfrom Results (API-level) with NDOutput (config-level).plugins/module_utils/nd_state_machine.pyself.results = Results()withstateandcheck_modeconfigured.results=self.resultsto orchestrator constructor (or sets it on existing instance).self.resultsfor module access at exit.Module files (4 files):
plugins/modules/nd_local_user.pyplugins/modules/nd_manage_fabric_ibgp.pyplugins/modules/nd_manage_fabric_external.pyplugins/modules/nd_manage_fabric_ebgp.pyAll four modules updated identically:
module._verbositywith safe fallback:verbosity = module._verbosity if hasattr(module, "_verbosity") else 0exit_jsoncall fromoutput.format()tooutput.format_with_verbosity(verbosity, nd_state_machine.results).fail_jsoncalls still useoutput.format()(no verbosity filtering on failure — always emit standard output).Documentation (1 file):
plugins/doc_fragments/modules.pyoutput_leveloption description to document the new CLI verbosity behavior:-vvaddsapi_pathsandapi_verbs.-vvvadds full controller detail includingapi_response,api_result,api_diff,api_metadata, andapi_payload.Unit tests (2 files):
tests/unit/module_utils/test_nd_output.py— 29 tests across 7 classes:TestNDOutputInit(3 tests): Constructor defaults.TestNDOutputFormat(7 tests): Existingformat()behavior preserved.TestNDOutputAssign(4 tests):assign()method behavior.TestFormatWithVerbosityLevel0And1(3 tests): No API detail at low verbosity.TestFormatWithVerbosityLevel2(5 tests): Write-only summary at-vv.TestFormatWithVerbosityLevel3(5 tests): Full detail at-vvv.TestFormatWithVerbosityEdgeCases(8 tests): None results, empty tasks, mixed verbosity levels.tests/unit/module_utils/orchestrators/test_base_orchestrator.py— 21 tests across 7 classes:TestRegisterApiCallVerbosityTagging(4 tests): Correct verbosity_level per operation type.TestRegisterApiCallFieldPopulation(7 tests): Path, verb, payload, response, result, action, diff captured.TestRequestWithoutResults(2 tests): Graceful no-op whenresults=None.TestRequestErrorHandlingWithResults(2 tests): Failed calls registered before exception.TestCrudOperationTypes(5 tests): CRUD methods pass correctOperationType.TestMultipleApiCalls(3 tests): Sequential calls accumulate, sequence numbers increment,build_final_resultaggregates.TestRequestDefaultOperationType(1 test): Default isOperationType.QUERY.Uses real
RestSendwith file-basedSender(existing test pattern), concrete stub endpoint and model classes.Subclass orchestrators unchanged
LocalUserOrchestrator,ManageEbgpFabricOrchestrator,ManageExternalFabricOrchestrator, andManageIbgpFabricOrchestratorrequired no changes — they only overridequery_all()which calls_request()without explicitoperation_type, correctly defaulting toOperationType.QUERY(verbosity=3).Test Notes
test_results.py,test_rest_send.py,test_response_handler_nd.py,test_sender_nd.py) should be re-run to confirm no regressions.-vvand-vvvagainst a live Nexus Dashboard to confirm API detail appears in output.Cisco Nexus Dashboard Version
Related ND API Resource Category
Checklist