350-401 Python for Network Automation • Complete Question Bank
Complete 350-401 Python for Network Automation question bank — all 0 questions with answers and detailed explanations.
A network engineer writes the following Python script using Netmiko to configure a Cisco IOS-XE device:
```python
from netmiko import ConnectHandler
device = { 'device_type': 'cisco_ios', 'ip': '192.168.1.1', 'username': 'admin', 'password': 'cisco123',
}
connection = ConnectHandler(**device) output = connection.send_command('show ip interface brief')
print(output)
connection.disconnect() ```
What is the primary issue with this script?
A network engineer uses NAPALM to retrieve the ARP table from a Cisco IOS-XE device:
```python
from napalm import get_network_driver
driver = get_network_driver('ios') device = driver('192.168.1.1', 'admin', 'cisco123') device.open() arp_table = device.get_arp_table()
print(arp_table)
device.close() ```
What is the expected data type of arp_table?
A network engineer writes an Ansible playbook to configure a VLAN on a Cisco Nexus switch:
```yaml --- - name: Configure VLAN hosts: nxos_switches gather_facts: no tasks: - name: Create VLAN 100 cisco.nxos.nxos_vlan: vlan_id: 100 name: test_vlan state: present ```
What is a potential issue with this playbook?
A network engineer uses the Requests library to query a Cisco IOS-XE device via RESTCONF for interface statistics:
```python
import requests from requests.auth import HTTPBasicAuth
url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces/interface=GigabitEthernet1/statistics' headers = {'Accept': 'application/yang-data+json'} auth = HTTPBasicAuth('admin', 'cisco123') response = requests.get(url, headers=headers, auth=auth, verify=False)
print(response.json())
```
What is the most likely issue with this code?
A network engineer uses the Cisco DNA Center REST API to retrieve the list of devices. The API returns the following JSON:
```json
{
"response": [
{
"id": "12345678-1234-1234-1234-123456789abc",
"managementIpAddress": "192.168.1.1",
"hostname": "Router1",
"platformId": "ISR4331",
"role": "ACCESS",
"series": "ISR4300 Series"
}
],
"version": "1.0"
}```
The engineer writes the following Python code to extract the hostname of the first device:
```python
import requests
url = 'https://dna-center.local/dna/intent/api/v1/network-device' headers = {'X-Auth-Token': 'valid_token', 'Accept': 'application/json'} response = requests.get(url, headers=headers, verify=False) data = response.json()
hostname = data['response'][0]['hostname'] print(hostname)
```
What is a potential issue with this code?
A network engineer configures model-driven telemetry on a Cisco IOS-XE device using gRPC dial-out. The subscription configuration snippet is:
``` telemetry ietf subscription 100 encoding encode-kvgpb filter xpath /interfaces/interface/statistics stream yang-push update-policy periodic 500 receiver ip address 10.1.1.1 50001 protocol grpc-tcp ```
What is the primary issue with this configuration?
A network engineer writes a Python script using Paramiko to execute a command on a Cisco IOS device:
```python
import paramiko
ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect('192.168.1.1', username='admin', password='cisco123') stdin, stdout, stderr = ssh.exec_command('show version') output = stdout.read().decode()
print(output)
ssh.close() ```
What is a potential issue with this approach?
A network engineer uses the Requests library to send a RESTCONF PATCH request to modify the hostname of a Cisco IOS-XE device:
```python
import requests from requests.auth import HTTPBasicAuth
url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/hostname' headers = {'Content-Type': 'application/yang-data+json'} auth = HTTPBasicAuth('admin', 'cisco123') payload = { 'Cisco-IOS-XE-native:hostname': 'NewRouter'
}
response = requests.patch(url, json=payload, headers=headers, auth=auth, verify=False)
print(response.status_code)
```
What is the expected HTTP status code if the request is successful?
A network engineer writes an Ansible playbook to gather facts from a Cisco IOS device using the ios_facts module:
```yaml --- - name: Gather IOS Facts hosts: ios_devices gather_facts: no tasks: - name: Collect facts cisco.ios.ios_facts: gather_subset: - hardware register: device_facts
- name: Show serial number debug: msg: "Serial number is {{ device_facts['ansible_facts']['ansible_net_serialnum'] }}" ```
What is a potential issue with this playbook?
Examine the following Python script snippet that uses netmiko to configure a Cisco IOS-XE device:
```python
from netmiko import ConnectHandler
device = { 'device_type': 'cisco_ios', 'ip': '192.168.1.1', 'username': 'admin', 'password': 'cisco',
}
connection = ConnectHandler(**device) output = connection.send_command('show ip interface brief')
print(output)
connection.disconnect() ```
What is the primary purpose of this script?
Consider the following Python script using the requests library to interact with a Cisco IOS-XE device via RESTCONF:
```python
import requests from requests.auth import HTTPBasicAuth
url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1/0/1' headers = { 'Accept': 'application/yang-data+json', 'Content-Type': 'application/yang-data+json'
}
auth = HTTPBasicAuth('admin', 'cisco')
response = requests.get(url, headers=headers, auth=auth, verify=False)
print(response.json())
```
What is the script attempting to do?
Examine this Python script that uses the napalm library to manage a Cisco IOS-XE device:
```python
from napalm import get_network_driver
driver = get_network_driver('ios') device = driver('192.168.1.1', 'admin', 'cisco') device.open()
print(device.get_facts())
device.close() ```
What is the output of this script?
Review the following Python script that uses the Cisco IOS-XE RESTCONF API to modify an interface:
```python
import requests from requests.auth import HTTPBasicAuth
url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/interface/GigabitEthernet=1/0/1' headers = { 'Accept': 'application/yang-data+json', 'Content-Type': 'application/yang-data+json'
}
auth = HTTPBasicAuth('admin', 'cisco')
payload = { 'Cisco-IOS-XE-native:GigabitEthernet': { 'name': '1/0/1', 'description': 'Configured via RESTCONF'
} }
response = requests.put(url, headers=headers, auth=auth, json=payload, verify=False)
print(response.status_code)
```
What is the expected result if the script runs successfully?
Examine the following Python script that uses the netmiko library to send configuration commands to a Cisco IOS-XE device:
```python
from netmiko import ConnectHandler
device = { 'device_type': 'cisco_ios', 'ip': '192.168.1.1', 'username': 'admin', 'password': 'cisco',
}
connection = ConnectHandler(**device) config_commands = [ 'interface GigabitEthernet1/0/1', 'description Link to Core', 'ip address 10.1.1.1 255.255.255.0', 'no shutdown'
]
output = connection.send_config_set(config_commands)
print(output)
connection.disconnect() ```
What is the purpose of this script?
Consider the following Python script that uses the requests library to delete a VLAN via RESTCONF on a Cisco IOS-XE device:
```python
import requests from requests.auth import HTTPBasicAuth
url = 'https://192.168.1.1/restconf/data/Cisco-IOS-XE-native:native/vlan=10' headers = { 'Accept': 'application/yang-data+json', 'Content-Type': 'application/yang-data+json'
}
auth = HTTPBasicAuth('admin', 'cisco')
response = requests.delete(url, headers=headers, auth=auth, verify=False)
print(response.status_code)
```
What is the expected outcome if the VLAN 10 exists?