root / examples / nc06.py @ 91c5e202
History | View | Annotate | Download (857 Bytes)
1 |
#! /usr/bin/env python2.6
|
---|---|
2 |
#
|
3 |
# Delete a list of existing users from the running configuration using
|
4 |
# edit-config; protect the transaction using a lock.
|
5 |
#
|
6 |
# $ ./nc06.py broccoli bob alice
|
7 |
|
8 |
import sys, os, warnings |
9 |
warnings.simplefilter("ignore", DeprecationWarning) |
10 |
from ncclient import manager |
11 |
|
12 |
template = """<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
|
13 |
<aaa xmlns="http://tail-f.com/ns/aaa/1.1">
|
14 |
<authentication> <users> <user xc:operation="delete">
|
15 |
<name>%s</name> </user></users></authentication></aaa></config>"""
|
16 |
|
17 |
def demo(host, user, names): |
18 |
with manager.connect(host=host, port=22, username=user) as m: |
19 |
with m.locked(target='running'): |
20 |
for n in names: |
21 |
m.edit_config(target='running', config=template % n)
|
22 |
|
23 |
if __name__ == '__main__': |
24 |
demo(sys.argv[1], os.getenv("USER"), sys.argv[2:]) |