summaryrefslogtreecommitdiff
path: root/ncserver/module/system.py
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-09-04 15:27:18 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-09-04 15:27:18 -0500
commit3517209d63d5a8e3eda2b56250edaef3e74a382e (patch)
treee2ce695b81f5678f7ababaf1287a20dc0d24c1d6 /ncserver/module/system.py
parent3c288e1d07b646c36b4f8769ff3ff153d5287b03 (diff)
downloadnetconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.gz
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.bz2
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.xz
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.zip
Implement state portion of ietf-system module
Diffstat (limited to 'ncserver/module/system.py')
-rw-r--r--ncserver/module/system.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/ncserver/module/system.py b/ncserver/module/system.py
new file mode 100644
index 0000000..285b272
--- /dev/null
+++ b/ncserver/module/system.py
@@ -0,0 +1,86 @@
+"""
+NETCONF for APK Distributions server:
+ ietf-system module
+
+Copyright © 2020 Adélie Software in the Public Benefit, Inc.
+
+Released under the terms of the NCSA license. See the LICENSE file included
+with this source distribution for more information.
+
+SPDX-License-Identifier: NCSA
+"""
+
+import platform
+import subprocess
+import time
+
+from datetime import datetime
+from math import floor
+from netconf import util
+
+
+M_ABI_VERSION = 1
+"""The ABI version of this NETCONF module."""
+
+
+M_PREFIX = "sys"
+"""The XML tag prefix for this module's tags."""
+
+
+M_NS = "urn:ietf:params:xml:ns:yang:ietf-system"
+"""The XML namespace for this module."""
+
+
+M_NAME = "ietf-system"
+"""The YANG model name for this module."""
+
+
+M_REVISION = "2014-08-06"
+"""The YANG revision date for this module."""
+
+
+M_IMPORTS = {
+ 'ietf-yang-types@2013-07-15': {
+ 'ns': "urn:ietf:params:xml:ns:yang:ietf-yang-types", 'prefix': "yang"
+ },
+ 'ietf-inet-types@2013-07-15': {
+ 'ns': "urn:ietf:params:xml:ns:yang:ietf-inet-types", 'prefix': "inet"
+ },
+ 'ietf-netconf-acm@2018-02-14': {
+ 'ns': "urn:ietf:params:xml:ns:yang:ietf-netconf-acm", 'prefix': "nacm"
+ },
+ 'iana-crypt-hash@2014-08-06': {
+ 'ns': "urn:ietf:params:xml:ns:yang:iana-crypt-hash", 'prefix': "ianach"
+ }
+}
+"""The imported YANG modules for this module."""
+
+
+def running(node):
+ """Retrieve the running configuration for this system."""
+
+
+def operational(node):
+ """Retrieve the operational configuration for this system."""
+ state = util.subelm(node, 'sys:system-state')
+
+ plat = util.subelm(state, 'sys:platform')
+ plat.append(util.leaf_elm('sys:os-name', platform.system()))
+ plat.append(util.leaf_elm('sys:os-release', platform.release()))
+ osv = subprocess.run(['/bin/sh', '-c',
+ '( . /etc/os-release && echo -n $PRETTY_NAME )'],
+ stdout=subprocess.PIPE)
+ plat.append(util.leaf_elm('sys:os-version', osv.stdout.decode('utf-8')))
+ plat.append(util.leaf_elm('sys:machine', platform.machine()))
+
+ clock = util.subelm(state, 'sys:clock')
+ clock.append(util.leaf_elm(
+ 'sys:current-datetime',
+ datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')
+ ))
+
+ with open('/proc/uptime', 'r') as upfile:
+ raw = upfile.read().split(' ')[0]
+ boot = floor(time.time() - float(raw))
+ fmted = datetime.fromtimestamp(boot).strftime('%Y-%m-%dT%H:%M:%S.%f')
+ clock.append(util.leaf_elm('sys:boot-datetime', fmted))