Netmiko send_config_set vs send_command Purpose
Short answer
A Send_config_set handles configuration mode commands with automatic entry/exit, while send_command is used for exec/show commands.
Question
Key Takeaways
In Netmiko, send_config_set is specifically designed for configuration mode commands, automatically handling entry and exit from config mode. send_command is intended for exec-level show and diagnostic commands, executing them in the current context. This distinction ensures proper session management and prevents syntax errors during automation.
Expert Analysis
The distinction between send_command and send_config_set in Netmiko is fundamental to writing reliable network automation scripts, as each method targets a specific operational mode of the device CLI. The deciding condition for this scenario lies in how Netmiko handles prompt detection and session state management: one function expects interactive exec-mode prompts (like > or #) and returns raw output, while the other automatically enters configuration mode (config terminal), sends lines sequentially, exits configuration mode, and returns the configuration diff or confirmation messages. This behavioral difference ensures that show commands are executed correctly without accidentally triggering configuration context errors, and configuration changes are applied with proper exit handling. Understanding this split prevents common pitfalls such as leaving a session in config mode after a show command or failing to apply configs because the script did not enter config mode first.
Option A accurately reflects the functional separation of concerns in Netmiko's API design
Option A correctly identifies that send_config_set is intended for configuration mode commands, while send_command is designed for exec-level show or diagnostic commands. When you use send_config_set, Netmiko automatically enters global configuration mode if it is not already there, sends each line in the provided list, waits for prompts, and then exits configuration mode back to the privileged exec level. This ensures that the session remains stable and predictable. Conversely, send_command sends a single string or a list of commands but does not change the mode; it simply executes them against the current prompt. If you try to send configuration commands via send_command without manually entering config mode first, the device will likely reject them with syntax errors. Similarly, using send_config_set for show commands is inefficient and potentially dangerous, as it forces an unnecessary entry into and exit from config mode, which can cause timing issues or log clutter. Therefore, Option A is the only choice that aligns with the documented behavior of these two core methods.
Other options fail due to incorrect assumptions about method equivalence or scope
Options B, C, and D all propose that the methods are interchangeable or serve identical purposes, which is factually incorrect and dangerous in production automation. Option B suggests they are the same thing, ignoring the critical difference in mode handling and return types. Option C claims both are for configuration, which ignores the primary use case of send_command for retrieving data like interface status, routing tables, or system uptime. Using send_config_set for every task would break workflows that rely on reading device state before making changes. Option D claims both are for show commands, which completely misunderstands the purpose of send_config_set. If you attempted to configure a VLAN or update an ACL using send_command, the commands would likely fail because they are not being sent in the correct configuration context. These options represent common misconceptions among beginners who assume that any CLI interaction can be handled by a single generic function, but Netmiko’s design explicitly separates these concerns to enforce best practices in session management.
The decisive mechanism is automatic mode transition versus static execution
The key technical detail that makes Option A correct is the automatic entry and exit from configuration mode performed by send_config_set. When you call send_config_set(net_connect, cmds), Netmiko internally calls config_mode if needed, iterates through the commands, checks for prompts, and finally calls exit_config_mode. This sequence guarantees that even if a command fails or times out, the session attempts to return to the exec mode, reducing the risk of orphaned sessions stuck in config mode. In contrast, send_command performs no such transitions; it assumes the user has already navigated to the desired mode. This design allows developers to write cleaner code where show operations are isolated from config operations, improving readability and maintainability. It also enables better error handling, as failures in config mode can be caught and logged separately from read-only operations. This separation of concerns is a hallmark of robust network automation frameworks, ensuring that side effects are minimized and session integrity is maintained.
Candidates should always match the command type to the appropriate Netmiko method
To succeed in similar exam questions or real-world scenarios, candidates must internalize the rule: use send_command for read-only or exec-mode tasks (show, ping, traceroute) and send_config_set for write operations that require configuration mode (interface config, routing protocol updates, ACL modifications). Never assume interchangeability, as doing so leads to runtime errors or unexpected device states. Always verify the current mode before sending commands if you deviate from these standard methods, but prefer sticking to the built-in helpers for reliability. This pattern applies not just to Netmiko but to many Python-based network libraries that abstract SSH interactions, reinforcing the importance of understanding the underlying device CLI modes when automating infrastructure.
Exam Strategy
When writing Netmiko scripts, always pair send_command with show/diagnostic tasks and send_config_set with configuration changes. Do not mix them, as send_config_set includes overhead for mode transition that can cause timeouts on simple reads, while send_command lacks the safety net of exiting config mode, risking orphaned sessions if used incorrectly for writes.
Related Analysis
Practice All 300-435 Questions
Access 150 questions with complete answers and detailed explanations.
View Full 300-435 Practice Test →