ON THIS PAGE
Examples: SSH Keys
You can add SSH public keys to a Test Agent via the NETCONF & YANG API. Using the corresponding private key you can then log in to the Test Agent via SSH.
The full list of available operations on SSH keys is as follows:
- Add an SSH key
- Modify an SSH key
- Inspect an SSH key
- List SSH keys
- Delete an SSH key.
Below, the add and delete operations are exemplified.
Adding an SSH Key
Here is how to create a new SSH key.
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: xml = """ <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <test-agents> <test-agent> <name>{test_agent}</name> <ssh-keys> <ssh-key> <name>{key_name}</name> <ssh-key-value>{key_value}</ssh-key-value> </ssh-key> </ssh-key> </test-agent> </test-agents> </account> </accounts> </config>""".format(account=args.netrounds_account, key_name=args.key_name, key_value=args.key_value, test_agent=args.test_agent) monitor = m.edit_config(target='running', config=xml, default_operation='merge') print "ok" if monitor.ok else monitor.errors
Deleting an SSH Key
If you want to delete an SSH key, use the following command:
with manager.connect(host=args.host, port=args.port, username=args.username, password=args.password, hostkey_verify=False) as m: xml = """ <config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"> <accounts xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="http://ncc.netrounds.com"> <account> <name>{account}</name> <test-agents> <test-agent> <name>{test_agent}</name> <ssh-keys> <ssh-key nc:operation="delete"> <name>{key_name}</name> </ssh-key> </ssh-key> </test-agent> </test-agents> </account> </accounts> </config>""".format(account=args.netrounds_account, key_name=args.key_name, test_agent=args.test_agent) monitor = m.edit_config(target='running', config=xml, default_operation='merge') print "ok" if monitor.ok else monitor.errors