Statistics
| Branch: | Tag: | Revision:

root / examples / nc03.py @ 91c5e202

History | View | Annotate | Download (766 Bytes)

1
#! /usr/bin/env python2.6 
2
#
3
# Retrieve a portion selected by an XPATH expression from the running
4
# config from the NETCONF server passed on the command line using
5
# get-config and write the XML configs to files.
6
#
7
# $ ./nc03.py broccoli "aaa/authentication/users/user[name='schoenw']"
8

    
9
import sys, os, warnings
10
warnings.simplefilter("ignore", DeprecationWarning)
11
from ncclient import manager
12

    
13
def demo(host, user, expr):
14
    with manager.connect(host=host, port=22, username=user) as m:
15
        assert(":xpath" in m.server_capabilities)
16
        c = m.get_config(source='running', filter=('xpath', expr)).data_xml
17
        with open("%s.xml" % host, 'w') as f:
18
            f.write(c)
19

    
20
if __name__ == '__main__':
21
    demo(sys.argv[1], os.getenv("USER"), sys.argv[2])