summaryrefslogtreecommitdiff
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
parent3c288e1d07b646c36b4f8769ff3ff153d5287b03 (diff)
downloadnetconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.gz
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.bz2
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.tar.xz
netconfapk-3517209d63d5a8e3eda2b56250edaef3e74a382e.zip
Implement state portion of ietf-system module
-rw-r--r--doc/roadmap.rst48
-rw-r--r--ncserver/module/__init__.py0
-rw-r--r--ncserver/module/system.py86
3 files changed, 117 insertions, 17 deletions
diff --git a/doc/roadmap.rst b/doc/roadmap.rst
index 19a1b2f..03f7d81 100644
--- a/doc/roadmap.rst
+++ b/doc/roadmap.rst
@@ -88,13 +88,13 @@ This feature will require in-depth discussion.
* [ ] SSH key administration (``$HOME/.ssh/authorized_keys``).
-* [ ] State nodes
+* [X] State nodes
- * [ ] Platform information.
+ * [X] Platform information.
- * [ ] Current date and time.
+ * [X] Current date and time.
- * [ ] Boot date and time.
+ * [X] Boot date and time.
* [ ] RPCs
@@ -110,24 +110,14 @@ The system module allows basic administration of system configuration.
Outstanding TBDs
````````````````
-* Where do we store the ``contact`` and ``location`` node information?
-
-* When the admin tries to set ``timezone-utf-offset``, do we make a custom
+* When the admin tries to set ``timezone-utc-offset``, do we make a custom
zoneinfo file or do we try to match?
* How do we support ``name`` of DNS resolvers? It is mandatory.
-* Can musl be configured for DNS timeout seconds and resolution attempts?
- Would Rich be open to adding this?
-
-* Do we support password-based authentication?
-
-* If we support password-based authentication, do we have a custom database or
- do we use ``/etc/shadow``? Should there be a group for NETCONF-allowed
- users? Do we support RADIUS?
+* Should there be a group for NETCONF-allowed users?
-* Do we calculate boot date/time naively (current time - uptime) or do we try
- to ascertain the actual boot date/time from something like ctime of ``/run``?
+* Do we support RADIUS?
Resolved TBDs
`````````````
@@ -138,6 +128,30 @@ Resolved TBDs
``ntpsec``. It has been packaged and tested for Adélie/ppc64, so it appears
portable.
+* Where do we store the ``contact`` and ``location`` node information?
+
+ **Resolution**: Flat files on the disk.
+
+* Can musl be configured for DNS timeout seconds and resolution attempts?
+ Would Rich be open to adding this?
+
+ **Resolution**: Yes, musl supports these options in ``/etc/resolv.conf``.
+
+* Do we calculate boot date/time naively (current time - uptime) or do we try
+ to ascertain the actual boot date/time from something like ctime of ``/run``?
+
+ **Resolution**: Naive calculation works well. ctime is not always
+ available and may be unreliable (systems that boot with time set to 1970).
+
+* Do we support password-based authentication?
+
+ **Resolution**: No, only key-based authentication.
+
+* If we support password-based authentication, do we have a custom database or
+ do we use ``/etc/shadow``?
+
+ **Resolution**: Not applicable; we do not support password-based
+ authentication.
diff --git a/ncserver/module/__init__.py b/ncserver/module/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ncserver/module/__init__.py
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))