Question 1
IntermediateAutomation · PyEZ scripts
You are designing an automation strategy for a Juniper-based data center using PyEZ. Your script needs to connect to a device, retrieve the full configuration in JSON format, and handle any connection errors gracefully. Which Python code snippet correctly implements the connection and retrieval using the Device class?
Answer and explanation
Correct answer: B
The Device class is the primary entry point in PyEZ. After instantiating and opening the connection with dev.open(), the rpc.get_config() method is used to retrieve configuration. Passing options={'format':'json'} (or specific arguments depending on the PyEZ version wrapper) instructs the device to return JSON output. The other options either use incorrect method names like pull_config or incorrect format arguments.
