root / examples / nc07.py @ 91c5e202
History | View | Annotate | Download (980 Bytes)
1 |
#! /usr/bin/env python2.6
|
---|---|
2 |
#
|
3 |
# Delete a list of existing users from the running configuration using
|
4 |
# edit-config and the candidate datastore protected by a lock.
|
5 |
#
|
6 |
# $ ./nc07.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 |
assert(":candidate" in m.server_capabilities) |
20 |
with m.locked(target='candidate'): |
21 |
m.discard_changes() |
22 |
for n in names: |
23 |
m.edit_config(target='candidate', config=template % n)
|
24 |
m.commit() |
25 |
|
26 |
if __name__ == '__main__': |
27 |
demo(sys.argv[1], os.getenv("USER"), sys.argv[2:]) |