summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-08-12 23:04:06 +0200
committerChristian Poessinger <christian@poessinger.com>2020-08-12 23:04:06 +0200
commit8efb8ba1efa9d51ec376bac0bfcb48cf200447a9 (patch)
treec2cc9abcddee7bf5bdf829329d2c05f8a18e8b23 /src
parent21bc98f16110d0fa2d7d93409252da73f58878ed (diff)
parentb5e0a1796cc7887245ae79c759f709e1705f5e93 (diff)
downloadvyos-1x-8efb8ba1efa9d51ec376bac0bfcb48cf200447a9.tar.gz
vyos-1x-8efb8ba1efa9d51ec376bac0bfcb48cf200447a9.zip
Merge branch 'system-display' of https://github.com/fmertz/vyos-1x into t2564-lcd
* 'system-display' of https://github.com/fmertz/vyos-1x: system display: T2564: Added test model system display: T2564: Dictionary code update system display: T2564: Conf files to /run system display: T2564: Changed "duration" to "time" system display: T2564: py code cleanup system display: T2564: Replace "config (enabled|disabled)" with "display disabled" system display: T2564: Lowercase model names system display: T2564 Extend VyOS to support appliance LCDs
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/system-display.py98
-rw-r--r--src/systemd/LCDd@.service10
-rw-r--r--src/systemd/lcdproc@.service10
3 files changed, 118 insertions, 0 deletions
diff --git a/src/conf_mode/system-display.py b/src/conf_mode/system-display.py
new file mode 100755
index 000000000..3eafc30c0
--- /dev/null
+++ b/src/conf_mode/system-display.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2020 Francois Mertz fireboxled at gmail.com
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+from sys import exit
+
+from vyos.config import Config
+from vyos import ConfigError
+from vyos.util import run
+from vyos.template import render
+
+from vyos import airbag
+airbag.enable()
+
+def get_config():
+ conf = Config()
+ base = ['system', 'display']
+ display = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
+ # Return a (possibly empty) configuration dictionary
+ return display
+
+def verify(config_dict):
+ if not config_dict:
+ return None
+
+ if 'model' not in config_dict:
+ raise ConfigError('Display model is [REQUIRED]')
+
+ if ( 'show' not in config_dict
+ or ( 'clock' not in config_dict['show']
+ and 'network' not in config_dict['show']
+ and 'host' not in config_dict['show']
+ )
+ ):
+ raise ConfigError('Display show must have a clock, host or network')
+
+ if ( 'network' in config_dict['show']
+ and 'interface' not in config_dict['show']['network']
+ ):
+ raise ConfigError('Display show network must have an interface')
+
+ if ( 'network' in config_dict['show']
+ and 'interface' in config_dict['show']['network']
+ and len(config_dict['show']['network']['interface']) > 3
+ ):
+ raise ConfigError('Display show network cannot have > 3 interfaces')
+
+ return None
+
+def generate(config_dict):
+ if not config_dict:
+ return None
+ # Render config file for daemon LCDd
+ render('/run/LCDd/LCDd.lo.conf', 'system-display/LCDd.conf.tmpl', config_dict)
+ # Render config file for client lcdproc
+ render('/run/lcdproc/lcdproc.lo.conf', 'system-display/lcdproc.conf.tmpl', config_dict)
+
+ return None
+
+def apply(config_dict):
+ # Stop client
+ run('systemctl stop lcdproc@lo.service')
+
+ if not config_dict or 'disabled' in config_dict:
+ # Stop server
+ run('systemctl stop LCDd@lo.service')
+ return None
+
+ # Restart server
+ run('systemctl restart LCDd@lo.service')
+ # Start client
+ run('systemctl start lcdproc@lo.service')
+
+ return None
+
+if __name__ == '__main__':
+ try:
+ config_dict = get_config()
+ verify(config_dict)
+ generate(config_dict)
+ apply(config_dict)
+ except ConfigError as e:
+ print(e)
+ exit(1)
diff --git a/src/systemd/LCDd@.service b/src/systemd/LCDd@.service
new file mode 100644
index 000000000..a4604cf21
--- /dev/null
+++ b/src/systemd/LCDd@.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=LCD display daemon on %I
+Documentation=man:LCDd(8) http://www.lcdproc.org/
+
+[Service]
+User=root
+ExecStart=/usr/sbin/LCDd -s 1 -f -c /run/LCDd/LCDd.%I.conf
+
+[Install]
+WantedBy=multi-user.target \ No newline at end of file
diff --git a/src/systemd/lcdproc@.service b/src/systemd/lcdproc@.service
new file mode 100644
index 000000000..9a1723dba
--- /dev/null
+++ b/src/systemd/lcdproc@.service
@@ -0,0 +1,10 @@
+[Unit]
+Description=LCDproc system status information viewer on %I
+Documentation=man:lcdproc(8) http://www.lcdproc.org/
+
+[Service]
+User=root
+ExecStart=/usr/bin/lcdproc -f -c /run/lcdproc/lcdproc.%I.conf
+
+[Install]
+WantedBy=multi-user.target \ No newline at end of file