The steps for the following recipe are as follows:
- Import the necessary standard library modules that we're going to use. In this case, we just need access to basic system functionality, the subprocess module (for managing child processes), and the XML parsing library:
#!/usr/bin/env python import sys import subprocess import xml.etree.ElementTree as ET
- Create a Python object class to represent the NETCONF client, making use of the subprocess module in the Python standard library in order to call the underlying operating system's SSH client. Define an appropriate constructor and destructor function as shown:
class NETCONFClient(object): DELIMITER = ']]>]]>\n' def __init__(self, hostname): self.ssh = subprocess.Popen([ ...