root / examples / nc04.py @ 91c5e202
History | View | Annotate | Download (1 kB)
1 |
#! /usr/bin/env python2.6
|
---|---|
2 |
#
|
3 |
# Create a new user to the running configuration using edit-config
|
4 |
# and the test-option provided by the :validate capability.
|
5 |
#
|
6 |
# $ ./nc04.py broccoli bob 42 42
|
7 |
|
8 |
import sys, os, warnings |
9 |
warnings.simplefilter("ignore", DeprecationWarning) |
10 |
from ncclient import manager |
11 |
|
12 |
def demo(host, user, name, uid, gid): |
13 |
snippet = """<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
|
14 |
<aaa xmlns="http://tail-f.com/ns/aaa/1.1">
|
15 |
<authentication> <users> <user xc:operation="create">
|
16 |
<name>%s</name> <uid>%s</uid> <gid>%s</gid>
|
17 |
<password>*</password> <ssh_keydir/> <homedir/>
|
18 |
</user></users></authentication></aaa></config>""" % (name, uid, gid)
|
19 |
|
20 |
with manager.connect(host=host, port=22, username=user) as m: |
21 |
assert(":validate" in m.server_capabilities) |
22 |
m.edit_config(target='running', config=snippet,
|
23 |
test_option='test-then-set')
|
24 |
|
25 |
if __name__ == '__main__': |
26 |
demo(sys.argv[1], os.getenv("USER"), sys.argv[2], sys.argv[3], sys.argv[4]) |