Courseiva

CCNA Python And PyEZ Questions

59 questions · Python And PyEZ · All types, answers revealed

1
MCQmedium

In a Jinja2 template designed for Junos configuration, how do you correctly output the value of a variable named 'hostname'?

A.${hostname}
B.{% hostname %}
C.<< hostname >>
D.{{ hostname }}
AnswerD

Correct. Double curly braces output the evaluated value of a variable.

Why this answer

Jinja2 uses double curly braces to print or evaluate variables.

2
MCQeasy

Which PyEZ utility module should you import if you need to upgrade the Junos operating system on a remote device via a Python script?

A.from jnpr.junos.utils.upgrade import Upgrade
B.from jnpr.junos.utils.config import Config
C.from jnpr.junos.device import OS_Update
D.from jnpr.junos.utils.sw import SW
AnswerD

Correct. SW is the PyEZ software utility module.

Why this answer

The SW utility module from jnpr.junos.utils.sw is used for software installation and upgrades.

3
Multi-Selectmedium

Which TWO statements are true regarding PyEZ Table and View definitions? (Choose two)

Select 2 answers
A.Tables can only be used to modify device configurations, not read operational state.
B.Tables require Jinja2 templates to parse raw XML output.
C.A View defines how individual fields within the returned XML elements are mapped to Python dictionary keys.
D.Tables are typically defined using YAML configuration files.
E.Views replace the need to instantiate a Device object.
AnswersC, D

Correct. Views specify field mappings.

Why this answer

Tables map to RPCs and Views map to item fields using YAML.

4
MCQhard

You are building a custom PyEZ application and need to catch exceptions specific to configuration parsing failures returned by Junos. Which exception class should your script import?

A.from jnpr.junos.exception import ConfigError
B.from jnpr.junos.device import ConfigurationFailed
C.from jnpr.junos.utils.config import ConfigError
D.from jnpr.junos.exception import ParseError
AnswerA

Correct. ConfigError handles configuration-related exceptions in PyEZ.

Why this answer

ConfigError is raised by PyEZ when configuration loading or committing fails.

5
Multi-Selecthard

Which THREE advanced features or methods are available on a PyEZ Device instance for session management and inspection? (Choose three)

Select 3 answers
A.dev.timeout property to get or set NETCONF RPC timeout values
B.dev.connected property to check if the session is active
C.dev.capabilities list showing NETCONF server capability URIs
D.dev.reload_session() for refreshing device facts
E.dev.commit_timeout for software installation timing
AnswersA, B, C

Correct. dev.timeout manages command timeouts.

Why this answer

PyEZ Device instances provide methods to check connection status, manage timeout values, and inspect capabilities.

6
MCQhard

When using PyEZ to push a configuration, you want to log out all NETCONF XML traffic exchanged between the script and the Junos device for debugging purposes. How do you enable this logging in Python?

A.import jnpr.junos.debug; jnpr.junos.debug.enable()
B.dev.rpc.trace(enabled=True)
C.Configuring Python logging for the 'jnpr.junos' logger with DEBUG level
D.dev.debug = True
AnswerC

Correct. PyEZ uses the standard logging module; setting 'jnpr.junos' to DEBUG logs all XML traffic.

Why this answer

Python's standard logging module configured for the jnpr.junos logger enables debug output.

7
MCQeasy

What is JSNAPy primarily used for in Junos network automation?

A.Taking operational state snapshots and verifying device health
B.Compiling Junos CLI operational commands into Python bytecode
C.Performing automated firmware upgrades across clusters
D.Generating static configuration templates
AnswerA

Correct. JSNAPy automates capturing and comparing operational states.

Why this answer

JSNAPy (Junos Snapshot Administrator) is used to capture operational state snapshots of Junos devices and compare them to detect changes or anomalies.

8
MCQeasy

What Jinja2 feature allows you to include the contents of another template file into your main configuration template?

A.{% insert 'filename.j2' %}
B.{% import 'filename.j2' %}
C.{{ load_template('filename.j2') }}
D.{% include 'filename.j2' %}
AnswerD

Correct. The include statement embeds another template.

Why this answer

The {% include %} tag allows inserting another template's content.

9
MCQmedium

An automation script needs to compare pre- and post-change states on a Junos device using JSNAPy (Junos Snapshot Administrator). Which configuration file format is used by JSNAPy to define snapshot checks and test assertions?

A.YAML
B.XML
C.JSON
D.INI
AnswerA

JSNAPy test files and check definitions are written in YAML format.

Why this answer

JSNAPy uses YAML configuration files to define which RPC commands to run and what expected values or expressions should be evaluated against the resulting snapshots.

10
MCQeasy

Which Jinja2 construct is used to define reusable blocks of template code that can be called with arguments like a function?

A.{% def %} ... {% enddef %}
B.{% block %} ... {% endblock %}
C.{% macro %} ... {% endmacro %}
D.{% function %} ... {% endfunction %}
AnswerC

Correct. Macros allow creating reusable template functions.

Why this answer

Macros in Jinja2 act like functions for templates.

11
MCQhard

You are writing a script that uses PyEZ to load a Junos configuration file, but you want to replace an entire hierarchy level (e.g., protocols bgp) rather than merging the changes. Which parameter should you pass to the load method?

A.overwrite=True
B.merge=False
C.action='replace'
D.mode='override'
AnswerC

Correct. Setting action='replace' loads the configuration with the replace directive.

Why this answer

The action='replace' parameter tells PyEZ to replace the specified hierarchy level in the candidate configuration.

12
MCQhard

You are rendering a Jinja2 template in Python that includes a loop over a list of VLANs. Which Jinja2 block syntax correctly iterates over a list named 'vlan_list'?

A.{{ for vlan in vlan_list }} ... {{ endfor }}
B.[for vlan in vlan_list] ... [endfor]
C.{% for vlan in vlan_list %} ... {% endfor %}
D.<% for vlan in vlan_list %> ... <% endif %>
AnswerC

Correct. The percent-brace syntax defines control structures like loops.

Why this answer

Jinja2 uses {% for item in list %} ... {% endfor %} syntax for iteration.

13
Multi-Selecthard

When writing Jinja2 templates for Junos configurations, which THREE control flow or filtering constructs are valid? (Choose three)

Select 3 answers
A.[# foreach item in list #] ... [# endfor #]
B.<< if interface_active >> ... << endif >>
C.{% for vlan in vlans %} ... {% endfor %}
D.{% if ospf_enabled %} ... {% endif %}
E.{{ interface_list | map(attribute='name') | list }}
AnswersC, D, E

Correct. Loops use for/endfor.

Why this answer

Jinja2 supports filters, loops, and conditional statements.

14
Multi-Selectmedium

Which TWO commands or tools are associated with running JSNAPy snapshot verifications from a CLI environment? (Choose two)

Select 2 answers
A.pyez-snap --run
B.jsnapy --snap
C.junos-snapshot --verify
D.juniper-snapshot-admin --test
E.jsnapy --check
AnswersB, E

Correct. The snap command captures snapshots.

Why this answer

JSNAPy execution is invoked via command line tool 'jsnapy'.

15
MCQhard

You are writing a script that performs multiple configuration changes inside a single PyEZ Config context. How can you verify that the candidate configuration has syntax errors before committing it?

A.cu.validate()
B.cu.test_syntax()
C.cu.verify()
D.cu.check()
AnswerA

Correct. cu.validate() runs a check equivalent to 'commit check' in Junos CLI.

Why this answer

The .validate() method checks the candidate configuration for syntax and semantic errors without committing.

16
MCQmedium

When configuring a JSNAPy test file, which section defines the specific RPCs or CLI commands that should be executed to gather operational data?

A.action:
B.command: or rpc:
C.device_credentials:
D.template:
AnswerB

Correct. JSNAPy configuration files use command or rpc fields to specify what data to retrieve.

Why this answer

The snapcheck or check configuration structure uses test definitions pointing to specific commands.

17
MCQeasy

When managing configuration changes via PyEZ Config utility, which context manager ensures that changes are automatically rolled back if an exception occurs within the block?

A.with Config(dev, mode='private') as cu:
B.try: cu.lock() except: cu.rollback()
C.with Config(dev) as cu:
D.cu.commit(rollback_on_error=True)
AnswerC

Correct. Using the Config utility as a Python context manager guarantees rollback if an unhandled exception disrupts the block.

Why this answer

The 'with Config(dev) as cu:' context manager automatically handles locking, loading, committing, and rolling back on failure.

18
Multi-Selectmedium

Which TWO actions can be performed using the JSNAPy command-line interface (CLI) tool during network verification workflows?

Select 2 answers
A.Capturing operational state snapshots of devices defined in configuration files
B.Provisioning zero-touch deployment (ZTP) DHCP server scopes on core switches
C.Comparing pre- and post-change snapshots to verify test assertions
D.Directly compiling Junos Source routing daemon binaries
E.Translating PyEZ Python scripts into native Junos SLAX op scripts
AnswersA, C

The snapshot action saves operational data for later comparison.

Why this answer

JSNAPy CLI commands include taking snapshots (jsnapy --snap) and comparing snapshots against defined checks (jsnapy --check). Options A and C are correct.

19
MCQeasy

An automation engineer is writing a Python script using Junos PyEZ to connect to a device. Which module and class must be imported to instantiate a device object representing the Junos target?

A.from jnpr.junos.rpcs import RPC
B.from jnpr.junos.facts import Facts
C.from jnpr.junos.device import Device
D.from jnpr.junos.utils.sw import SW
AnswerC

Correct. The Device class is imported directly from jnpr.junos.device to create the connection handle.

Why this answer

The Device class from the jnpr.junos module is the foundational class used in PyEZ to manage connections and sessions with Junos devices.

20
MCQhard

When executing a PyEZ RPC call that returns a large dataset (e.g., massive routing table), how can you handle the output efficiently without exhausting local memory?

A.etree.iterparse() directly on the raw socket stream
B.Using parser generators or iterator arguments supported by specific RPC wrappers
C.dev.rpc.get_route_information(normalize=True)
D.dev.stream_rpc()
AnswerB

Correct. PyEZ allows using iterators or chunked parsing options for large operational datasets.

Why this answer

Using generators or streaming options in RPC handling prevents loading massive XML trees entirely into memory.

21
MCQeasy

Which Python library does PyEZ depend on under the hood for managing secure SSH connections and NETCONF framing?

A.ncclient
B.paramiko
C.fabric
D.netmiko
AnswerA

Correct. PyEZ is built on top of the ncclient library for NETCONF operations.

Why this answer

PyEZ relies on ncclient for NETCONF over SSH transport.

22
MCQmedium

You have captured a baseline snapshot using JSNAPy and want to compare a newly taken snapshot against that baseline. Which JSNAPy command-line action executes this comparison?

A.jsnapy --test
B.jsnapy --check
C.jsnapy --verify
D.jsnapy --compare
AnswerB

Correct. The check command compares snapshots.

Why this answer

The check action compares current operational state against a snapshot baseline.

23
MCQeasy

What is the primary templating engine used alongside Python for generating structured Junos configuration text in network automation workflows?

A.Ansible Engine
B.Mako
C.ERB
D.Jinja2
AnswerD

Correct. Jinja2 is widely used with Python to generate dynamic configuration files.

Why this answer

Jinja2 is the standard Python templating engine used for rendering configuration templates.

24
MCQmedium

An engineer is applying a candidate configuration using PyEZ and needs to load it from an external text file named 'interfaces.conf'. Which Config method should be used?

A.cu.load(path='interfaces.conf', format='text')
B.dev.load_configuration(file='interfaces.conf')
C.cu.load_file('interfaces.conf')
D.cu.read_config('interfaces.conf')
AnswerA

Correct. The path parameter specifies the file location and format specifies its syntax.

Why this answer

The load method with path and format parameters is used to load configuration text from a file.

25
Multi-Selectmedium

Which TWO methods are valid for loading configuration data into the PyEZ Config utility from different sources? (Choose two)

Select 2 answers
A.cu.load(text='set system hostname router1', format='set')
B.cu.load(template_file='config.j2', engine='jinja2')
C.cu.load(database='active')
D.cu.load(action='commit')
E.cu.load(path='/path/to/config.xml', format='xml')
AnswersA, E

Correct. Loading raw text strings with specified format is supported.

Why this answer

Config.load supports string data, file paths, and template rendering results.

26
Multi-Selecthard

Which THREE exceptions can be raised by PyEZ during script execution when interacting with a Junos device? (Choose three)

Select 3 answers
A.RpcError
B.DatabaseLockedError
C.ConfigError
D.ConnectError
E.TemplateRenderError
AnswersA, C, D

Correct. Raised when an RPC execution returns an error from the device.

Why this answer

PyEZ defines specific exceptions in jnpr.junos.exception for connection, configuration, and RPC errors.

27
Multi-Selecthard

When implementing Jinja2 templates for Junos configuration generation, which THREE features or syntax constructs are natively supported by the Jinja2 engine?

Select 3 answers
A.Automatic translation of Jinja2 syntax into NETCONF XML filters without evaluation
B.Direct execution of arbitrary host-level Bash shell scripts inside template bodies
C.Variable substitution using double curly braces (e.g., {{ interface_name }})
D.Control structures such as loops and conditional blocks (e.g., {% for item in list %})
E.Template inheritance and block overriding (e.g., {% block content %})
AnswersC, D, E

Double curly braces are the standard syntax for outputting variable values in Jinja2.

Why this answer

Jinja2 natively supports variable interpolation using double curly braces, control structures like for-loops using {% for %}, and template inheritance via {% extends %}. Options A, C, and D are correct.

28
Multi-Selecthard

When configuring JSNAPy, which THREE components or sections are typically required within a YAML check/snapshot file? (Choose three)

Select 3 answers
A.command: or rpc: specifying the operational commands to run
B.dev: or device: specifying target device connection details
C.jinja_template: defining external configuration templates
D.candidate_database: defining NETCONF lock parameters
E.action: defining test parameters or actions like snap or check
AnswersA, B, E

Correct. Commands or RPCs define what data to snapshot.

Why this answer

JSNAPy configuration files require device definitions, action parameters, and command/rpc test definitions.

29
MCQmedium

You need to retrieve operational data from a Junos device using a PyEZ RPC call that equates to the CLI command 'show system information'. Which Python statement correctly invokes this RPC?

A.dev.execute("show system information")
B.dev.get_config(cli="show system information")
C.dev.rpc.show_system_information()
D.dev.rpc.get_system_information()
AnswerD

This translates the XML RPC tag <get-system-information> into a Python method.

Why this answer

In PyEZ, CLI commands can be translated to RPC methods by converting dashes to underscores. 'show system information' becomes dev.rpc.get_system_information().

30
Multi-Selectmedium

Which TWO characteristics describe JSNAPy snapshot operations? (Choose two)

Select 2 answers
A.It compiles Jinja2 configuration templates directly into Junos CLI commands.
B.It replaces PyEZ as the primary library for executing NETCONF RPC calls.
C.It saves captured operational data into snapshot files for later comparison.
D.It modifies the active configuration database automatically upon finding errors.
E.It can compare a post-change snapshot against a baseline pre-change snapshot.
AnswersC, E

Correct. JSNAPy stores operational data snapshots.

Why this answer

JSNAPy captures snapshots to XML/YAML files and compares them over time.

31
Multi-Selecthard

When working with the PyEZ Config utility, which THREE actions can be performed using the configuration context manager or its methods? (Choose three)

Select 3 answers
A.cu.gather_facts()
B.cu.validate()
C.cu.load(path='config.conf', format='text')
D.cu.rollback()
E.cu.upgrade_os()
AnswersB, C, D

Correct. Validating the candidate configuration checks for syntax errors.

Why this answer

The Config utility supports locking, loading configurations from various sources, validating, and rolling back.

32
Multi-Selecthard

Which TWO of the following methods or attributes are valid ways to handle rollback operations or commit errors when using the PyEZ Config utility (cu)?

Select 2 answers
A.cu.force_commit()
B.cu.rollback(id=1)
C.cu.undo()
D.cu.commit(comment="Automated deployment", timeout=30)
E.cu.revert(rollback=0)
AnswersB, D

cu.rollback() rolls back the candidate configuration to the specified rollback index.

Why this answer

cu.rollback() reverts the candidate configuration to a previous rollback index, and cu.commit(comment=...) allows committing changes with specific options. Options B and D are correct.

33
MCQmedium

When using Jinja2 templates in Python to generate configurations, how can you load a template file from disk prior to rendering it with variables?

A.Template(open('template.j2').read())
B.template.open('template.j2')
C.import_template('template.j2')
D.jinja2.load_file('template.j2')
AnswerA

Correct. Initializing Jinja2 Template with the read string of a file is a standard loading approach.

Why this answer

Environment and FileSystemLoader are used to load templates from a directory path.

34
MCQhard

When modifying a Junos device configuration using the PyEZ Config table-driven or Context manager (with Config(dev) as cu:), what is the default behavior regarding locking the candidate configuration?

A.It locks the global database and forces all other users into maintenance mode.
B.It requires an explicit cu.lock() call before any load operation can take place.
C.It automatically locks the candidate configuration upon entry and unlocks it upon exit.
D.It locks the running configuration and restarts the mgd daemon.
AnswerC

Automatic locking is a core feature of the PyEZ Config context manager to ensure transactional safety.

Why this answer

When entering the Config context manager in PyEZ, it automatically locks the candidate configuration database to prevent concurrent edits and unlocks it upon exiting the context.

35
MCQmedium

You are utilizing PyEZ Table and View abstractions to parse interface statistics. Which base class must your custom Table class inherit from to map to Junos XML output?

A.jnpr.junos.rpchandler.RPC
B.jnpr.junos.device.Device
C.jnpr.junos.factory.Table
D.jnpr.junos.utils.config.Config
AnswerC

Table is the primary base class for structured operational data parsing in PyEZ.

Why this answer

To leverage PyEZ Table/View mapping for operational commands, your custom table class must inherit from 'jnpr.junos.factory.Table'.

36
MCQhard

You want to run a JSNAPy verification test via Python code. Which Python class should you import and instantiate to execute the snapshot comparison programmatically?

A.from jnpr.jsnapy.verify import VerifyEngine
B.from jnpr.junos.utils.jsnapy import JSNAPy
C.from jnpr.jsnapy.runner import JSNAPyRunner
D.from jnpr.jsnapy import SnapAdmin
AnswerD

Correct. SnapAdmin is the core Python class for JSNAPy operations.

Why this answer

The JSNAPy class is imported from jnpr.jsnapy to execute snapshot checks programmatically.

37
MCQhard

When loading configuration changes via PyEZ using cu.load(format='xml', action='update'), what is the precise impact of the 'update' action compared to 'merge' or 'override'?

A.It overwrites the entire candidate configuration, discarding all prior uncommitted changes.
B.It completely replaces the running configuration with the provided payload.
C.It merges configuration changes with the existing candidate configuration, modifying or adding specified nodes while preserving unreferenced nodes.
D.It deletes the matching hierarchy nodes entirely before inserting new ones.
AnswerC

The update action applies incremental updates matched by identifiers.

Why this answer

The 'update' action merges configuration elements based on matching keys or identifiers, allowing precise modification of existing hierarchical statements without replacing entire blocks.

38
MCQeasy

In JSNAPy, what file format is used to define test cases and expected operational states?

A.INI
B.YAML
C.XML
D.JSON
AnswerB

Correct. JSNAPy configuration and test files are written in YAML format.

Why this answer

JSNAPy uses YAML configuration files for defining tests and expected values.

39
MCQhard

You are writing a script that uses PyEZ to load a partial configuration merge. By default, what configuration database mode does the Config utility lock and load into?

A.The rescue configuration database
B.The candidate configuration database
C.A private configuration database instance
D.The global active configuration database
AnswerB

Correct. The standard target for PyEZ configuration loads is the candidate database.

Why this answer

By default, PyEZ loads configuration changes into the candidate configuration database.

40
MCQmedium

When writing a Python script that connects to multiple Junos devices concurrently using PyEZ, which Python module is commonly used to manage thread pooling and parallel execution?

A.jnpr.junos.parallel
B.multiprocessing.device
C.asyncio.netconf
D.concurrent.futures
AnswerD

Correct. concurrent.futures provides high-level APIs for executing tasks asynchronously using threads or processes.

Why this answer

Concurrent futures or threading modules handle parallel execution in Python.

41
MCQeasy

An automation engineer is writing a Python script using Juniper PyEZ to connect to a Junos device. Which context manager approach is best practice to ensure the Device session is properly closed even if an exception occurs?

A.dev = Device(host="192.168.1.1"); dev.start_session()
B.with Device(host="192.168.1.1", user="admin", passwd="secret") as dev:
C.dev = Device(host="192.168.1.1"); dev.open(autoclose=True)
D.dev = Device(host="192.168.1.1").connect()
AnswerB

The context manager automatically opens the connection upon entry and safely closes it upon exit.

Why this answer

Using the 'with Device(host=...) as dev:' context manager guarantees that the open() and close() methods are handled automatically, even if runtime errors occur inside the block.

42
MCQhard

When writing a Python script using PyEZ, how should you handle connection timeout exceptions when attempting to connect to an unreachable Junos device?

A.except NetconfConnectionError:
B.except ConnectError:
C.except DeviceOpenError:
D.except socket.timeout:
AnswerB

Correct. ConnectError is raised by jnpr.junos.exception when a connection cannot be established.

Why this answer

PyEZ raises ConnectError when it fails to establish a NETCONF session with the target device.

43
MCQmedium

When using Jinja2 inheritance, which tag is placed in a base template to indicate where child templates can insert their custom content?

A.{% block block_name %} ... {% endblock %}
B.{{ super() }}
C.{% insert block_name %}
D.{% child_content %}
AnswerA

Correct. The block tag defines override points in Jinja2 template inheritance.

Why this answer

The block tag defines regions that child templates can override.

44
Multi-Selectmedium

Which TWO tasks are typically automated using Python and PyEZ in a network DevOps pipeline? (Choose two)

Select 2 answers
A.Direct packet capture inspection at Layer 1 physical media levels
B.Writing device firmware assembly code
C.Automated pushing of validated Jinja2-generated configurations to candidate databases
D.Automated pre-check and post-check operational verification during maintenance windows
E.Compiling Junos kernel device drivers in C++
AnswersC, D

Correct. Pushing generated configs via PyEZ Config is standard practice.

Why this answer

PyEZ automates configuration deployments and operational data gathering.

45
MCQeasy

You are writing a script that uses Jinja2 to dynamically render a Junos interface configuration. Which Python module and function are required to load a template from the local filesystem and render it with a dictionary of variables?

A.from jnpr.junos.cfg import ConfigTemplate
B.from jinja2 import Environment, FileSystemLoader
C.from jnpr.junos.template import TemplateRenderer
D.import jnpr.junos.utils.jinja as jinja
AnswerB

FileSystemLoader and Environment are the standard classes used to load and render templates from files.

Why this answer

Jinja2 utilizes a FileSystemLoader to find templates on disk and an Environment to manage them, allowing you to get_template() and render() with context variables.

46
MCQmedium

You are using the PyEZ SW utility to install a new Junos image on a device. Which method parameter allows the script to automatically reboot the device after a successful installation?

A.auto_reboot=1
B.reboot=True
C.reload_after_install=True
D.action='reboot'
AnswerB

Correct. Passing reboot=True to the sw.upgrade() method triggers a device reload upon completion.

Why this answer

The val parameter or reboot=True flag is typically used depending on the specific SW.upgrade() call signature. Specifically, reboot=True forces the reload.

47
Multi-Selectmedium

Which TWO methods or attributes are valid when using the PyEZ SW utility to manage Junos software? (Choose two)

Select 2 answers
A.sw.install(remote_path='/var/tmp/image.tgz')
B.sw.upgrade(package='junos-install-srx-x86-64-20.4R1.3.tgz', reboot=True)
C.sw.rollback_software()
D.sw.get_os_facts()
E.sw.commit_os()
AnswersA, B

Correct. install is a valid SW method.

Why this answer

SW utility methods include install, upgrade, and checking device readiness.

48
MCQmedium

You need to write a Python script that extracts interface status from a Junos device using PyEZ and converts the XML output directly into a Python dictionary. Which utility or function can assist with this conversion?

A.Using PyEZ Table and View abstractions
B.dev.rpc.convert_to_dict()
C.json.loads(dev.rpc.get_interface_information())
D.etree.to_dict()
AnswerA

Correct. PyEZ Table/View mapping structures automatically parse XML output into clean Python dictionaries and lists.

Why this answer

The XMLtoPy function from jnpr.junos.factory or standard table/view mappings helps convert XML to Python data structures.

49
Multi-Selectmedium

Which TWO of the following are valid ways to instantiate a PyEZ Device object in Python, providing connection parameters? (Choose two)

Select 2 answers
A.dev = Device(host='192.168.1.1', user='admin', password='secret')
B.dev = Device.connect('192.168.1.1')
C.dev = Device.from_cli('192.168.1.1')
D.dev = Device(database='candidate')
E.dev = Device('192.168.1.1', user='admin', ssh_private_key='/path/to/key')
AnswersA, E

Correct. Explicit keyword arguments are standard for initializing a Device.

Why this answer

PyEZ Device can take explicit keyword arguments or read from configuration files/environment variables.

50
MCQeasy

In a Python script utilizing PyEZ, what method must be called on the Device instance after all configuration and operational tasks are complete to properly terminate the NETCONF session?

A.dev.close()
B.dev.terminate()
C.dev.end_session()
D.dev.disconnect()
AnswerA

Correct. dev.close() cleanly shuts down the NETCONF session.

Why this answer

The .close() method terminates the NETCONF session cleanly.

51
MCQeasy

What is the primary benefit of using PyEZ Table and View abstractions over raw RPC XML parsing in Python scripts?

A.They eliminate the need to establish a Device connection object
B.They automatically convert XML into structured Python data structures like dictionaries and lists
C.They allow direct execution of Junos CLI operational commands without NETCONF
D.They automatically commit configurations to the active database
AnswerB

Correct. Tables and Views abstract XML parsing into clean Python objects.

Why this answer

Tables and Views abstract complex XML trees into clean Python dictionaries and lists.

52
MCQhard

You need to execute a custom remote procedure call (RPC) in PyEZ to retrieve the Ethernet switching table. The tag in Junos XML API is get-ethernet-switching-table-information. How should you write this method call in Python?

A.dev.rpc.get-ethernet-switching-table-information()
B.dev.get_ethernet_switching_table_information()
C.dev.execute_rpc('get-ethernet-switching-table-information')
D.dev.rpc.get_ethernet_switching_table_information()
AnswerD

Correct. PyEZ converts hyphens in RPC names to underscores for Python method calls.

Why this answer

PyEZ maps XML RPC hyphens to Python underscores, allowing you to call rpc methods directly as attributes on dev.rpc.

53
Multi-Selectmedium

Which TWO benefits are gained by using Python virtual environments when developing PyEZ and Jinja2 automation scripts? (Choose two)

Select 2 answers
A.They automatically compile Python scripts into binary executable files for Junos.
B.They allow installing specific versions of PyEZ, lxml, and Jinja2 independently of system Python.
C.They remove the need to install SSH clients on the local machine.
D.They enable direct root-level execution of Junos CLI commands on physical routers.
E.They isolate Python package dependencies for specific projects, preventing version conflicts.
AnswersB, E

Correct. Local package management gives version control.

Why this answer

Virtual environments isolate project dependencies and prevent version conflicts.

54
Multi-Selecthard

When developing Python scripts that utilize PyEZ and Jinja2, which THREE best practices ensure robust and maintainable automation code? (Choose three)

Select 3 answers
A.Using the PyEZ Config context manager to ensure locks are released and rollbacks occur on error
B.Hardcoding administrative passwords inside template files for easy rendering
C.Using try-except blocks to catch specific PyEZ exceptions like ConnectError and ConfigError
D.Avoiding device.close() calls to keep network sessions open permanently
E.Separating Jinja2 template files from core Python execution scripts
AnswersA, C, E

Correct. Context managers handle resource cleanup safely.

Why this answer

Best practices include proper exception handling, using context managers, and separating templates from logic.

55
MCQeasy

When executing an RPC call in PyEZ, what format is typically returned by default if you do not parse it into another structure?

A.A JSON dictionary
B.An XML Element (lxml.etree)
C.A raw plain text string
D.A Python list of strings
AnswerB

Correct. PyEZ returns response data as an lxml Element object.

Why this answer

PyEZ RPC calls return an ElementTree object (XML Element) representing the response from the Junos device.

56
MCQhard

When designing a custom PyEZ Table and View mapping in Python, what configuration parameter in the YAML definition file specifies the RPC or CLI command executed to gather the raw data?

A.get-rpc:
B.exec:
C.rpc:
D.command_string:
AnswerC

Correct. The rpc key in a Table YAML definition specifies the XML RPC tag name.

Why this answer

The 'rpc' or 'command' keyword in a PyEZ Table YAML definition specifies the underlying command to run.

57
MCQmedium

When writing a Python script to interact with Junos devices, you want to ensure that password credentials are not hardcoded in the source code. What is a recommended best practice supported by PyEZ?

A.Disabling authentication in the script
B.Storing credentials in plaintext in a public GitHub repository
C.Hardcoding credentials in base64 encoding
D.Using SSH key-based authentication or environment variables/config files (.junodes)
AnswerD

Correct. PyEZ supports SSH keys and standard credential management practices.

Why this answer

PyEZ natively supports configuration files like ~/.junodes or passing parameters dynamically, but also respects environment variables or SSH keys.

58
MCQmedium

You are writing a Python script to gather operational state information from a Junos device using PyEZ. Which method should you call on an open Device instance to retrieve standard hardware and OS inventory facts into a dictionary?

A.dev.facts
B.dev.rpc.get_system_inventory()
C.dev.gather_facts()
D.dev.get_facts()
AnswerA

Correct. dev.facts is a property dictionary that returns the gathered facts of the device.

Why this answer

The .facts method populates a dictionary with system inventory details such as model, serial number, and version.

59
MCQmedium

An automation script needs to check if a Junos device supports a specific feature before executing an RPC. Which PyEZ property can be checked to inspect the software version loaded on the device?

A.dev.get_version()
B.dev.version
C.dev.os_version
D.dev.facts['version']
AnswerD

Correct. dev.facts contains system details including the software version string.

Why this answer

dev.facts['version'] holds the Junos OS version string.

Ready to test yourself?

Try a timed practice session using only Python And PyEZ questions.