A script polls 40 IOS XE switches and repeats the same request-and-retry block, error list included, in six places. Access-layer switches wait 5 seconds between retries while WAN edges wait 20, and a second scheduled script must import the same logic as-is instead of wrapping it in an object. Which Python structure should hold this shared network automation logic?
Select an answer to reveal the explanation.
Short Explanation
You only need one home for that logic, and a plain function gives it to you. The delay becomes an argument, so each call site picks its own wait and the second script just imports the module; it's the lightest change you can make. A module-level function keeps exactly one copy of the polling logic for both jobs.
Full Explanation
A module-level function is the natural home for logic that several call sites share, because the body exists once and every caller supplies its own arguments. Making retry_delay a parameter is what lets the access-layer loops wait five seconds while the WAN edges wait twenty without copying anything, and because the function keeps no per-switch state, the second scheduled script simply imports the module and calls it. A client class also removes duplication, but forcing that script to instantiate an object first introduces lifecycle and state management the scenario rules out. A decorator can wrap the six blocks, yet one hardcoded delay cannot serve two different wait times, and a lookup dictionary of delays only centralises a value while leaving six copies of the request and retry body behind. Exam caveat: these questions reward the smallest construct that satisfies every stated constraint rather than the most object-oriented design. Practical check: search the script for the duplicated block and confirm it now appears exactly once.