Statistics
| Branch: | Tag: | Revision:

root / examples / nc02.py @ 6772b445

History | View | Annotate | Download (576 Bytes)

1 91c5e202 Shikhar Bhushan
#! /usr/bin/env python2.6 
2 91c5e202 Shikhar Bhushan
#
3 91c5e202 Shikhar Bhushan
# Retrieve the running config from the NETCONF server passed on the
4 91c5e202 Shikhar Bhushan
# command line using get-config and write the XML configs to files.
5 91c5e202 Shikhar Bhushan
#
6 91c5e202 Shikhar Bhushan
# $ ./nc02.py broccoli
7 91c5e202 Shikhar Bhushan
8 91c5e202 Shikhar Bhushan
import sys, os, warnings
9 91c5e202 Shikhar Bhushan
warnings.simplefilter("ignore", DeprecationWarning)
10 91c5e202 Shikhar Bhushan
from ncclient import manager
11 91c5e202 Shikhar Bhushan
12 91c5e202 Shikhar Bhushan
def demo(host, user):
13 91c5e202 Shikhar Bhushan
    with manager.connect(host=host, port=22, username=user) as m:
14 91c5e202 Shikhar Bhushan
        c = m.get_config(source='running').data_xml
15 91c5e202 Shikhar Bhushan
        with open("%s.xml" % host, 'w') as f:
16 91c5e202 Shikhar Bhushan
            f.write(c)
17 91c5e202 Shikhar Bhushan
18 91c5e202 Shikhar Bhushan
if __name__ == '__main__':
19 91c5e202 Shikhar Bhushan
    demo(sys.argv[1], os.getenv("USER"))