← cproj

ncclient

e47205582e99add0e5a6544d9faa978fc6e7384d · ovidiucs · Oct 8, 2019 06:35

+30 · 1 file changed

  • graph/python/pytest.py +30 −0
diff --git a/graph/python/pytest.py b/graph/python/pytest.py
new file mode 100644
index 0000000..863185b
--- /dev/null
+++ b/graph/python/pytest.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+import logging
+import sys
+
+from ncclient import manager
+
+
+def connect(host, port, user, password):
+    conn = manager.connect(host=host,
+                           port=port,
+                           username=user,
+                           password=password,
+                           timeout=60,
+                           device_params={'name': 'junos'},
+                           hostkey_verify=False)
+
+    logging.info('show system users')
+    logging.info('*' * 30)
+    result = conn.command(command='show system users', format='text')
+    logging.info(result)
+
+    logging.info('show version')
+    logging.info('*' * 30)
+    result = conn.command('show version', format='text')
+    logging.info(result.xpath('output')[0].text)
+
+if __name__ == '__main__':
+    LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s'
+    logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT)
+