summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-08-13 18:31:08 +0200
committerChristian Poessinger <christian@poessinger.com>2020-08-15 15:02:00 +0000
commitb082a6fb211ef19d75c4c81414be9aa1b9248b45 (patch)
tree85ee394234198a669c4be22cc97f1e2f3ab5050b /src
parent8efb8ba1efa9d51ec376bac0bfcb48cf200447a9 (diff)
downloadvyos-1x-b082a6fb211ef19d75c4c81414be9aa1b9248b45.tar.gz
vyos-1x-b082a6fb211ef19d75c4c81414be9aa1b9248b45.zip
lcd: T2564: flatten CLI interface
* set system lcd device <device> * set system lcd model <modeml> Both device and model have completion helpers for supported interfaces and LCD displays.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-wirelessmodem.py12
-rwxr-xr-xsrc/conf_mode/system-display.py98
-rwxr-xr-xsrc/conf_mode/system_lcd.py84
-rw-r--r--src/etc/systemd/system/LCDd.service.d/override.conf8
-rw-r--r--src/etc/systemd/system/hostapd@.service.d/override.conf7
-rw-r--r--src/systemd/LCDd@.service10
-rw-r--r--src/systemd/lcdproc.service13
-rw-r--r--src/systemd/lcdproc@.service10
8 files changed, 109 insertions, 133 deletions
diff --git a/src/conf_mode/interfaces-wirelessmodem.py b/src/conf_mode/interfaces-wirelessmodem.py
index 4081be3c9..6d168d918 100755
--- a/src/conf_mode/interfaces-wirelessmodem.py
+++ b/src/conf_mode/interfaces-wirelessmodem.py
@@ -16,7 +16,6 @@
import os
-from fnmatch import fnmatch
from sys import exit
from vyos.config import Config
@@ -25,22 +24,13 @@ from vyos.configverify import verify_vrf
from vyos.template import render
from vyos.util import call
from vyos.util import check_kmod
+from vyos.util import find_device_file
from vyos import ConfigError
from vyos import airbag
airbag.enable()
k_mod = ['option', 'usb_wwan', 'usbserial']
-def find_device_file(device):
- """ Recurively search /dev for the given device file and return its full path.
- If no device file was found 'None' is returned """
- for root, dirs, files in os.walk('/dev'):
- for basename in files:
- if fnmatch(basename, device):
- return os.path.join(root, basename)
-
- return None
-
def get_config():
"""
Retrive CLI config as dictionary. Dictionary can never be empty, as at least the
diff --git a/src/conf_mode/system-display.py b/src/conf_mode/system-display.py
deleted file mode 100755
index 3eafc30c0..000000000
--- a/src/conf_mode/system-display.py
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/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/conf_mode/system_lcd.py b/src/conf_mode/system_lcd.py
new file mode 100755
index 000000000..0ad1318f0
--- /dev/null
+++ b/src/conf_mode/system_lcd.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+#
+# Copyright 2020 VyOS maintainers and contributors <maintainers@vyos.io>
+#
+# 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.util import call
+from vyos.util import find_device_file
+from vyos.template import render
+from vyos import ConfigError
+from vyos import airbag
+airbag.enable()
+
+lcdd_conf = '/run/LCDd/LCDd.conf'
+lcdproc_conf = '/run/lcdproc/lcdproc.conf'
+
+def get_config():
+ conf = Config()
+ base = ['system', 'lcd']
+ lcd = conf.get_config_dict(base, key_mangling=('-', '_'),
+ get_first_key=True)
+ # Return (possibly empty) dictionary
+ return lcd
+
+def verify(lcd):
+ if not lcd:
+ return None
+
+ if not {'device', 'model'} <= set(lcd):
+ raise ConfigError('Both device and driver must be set!')
+
+ return None
+
+def generate(lcd):
+ if not lcd:
+ return None
+
+ if 'device' in lcd:
+ lcd['device'] = find_device_file(lcd['device'])
+
+ # Render config file for daemon LCDd
+ render(lcdd_conf, 'lcd/LCDd.conf.tmpl', lcd, trim_blocks=True)
+ # Render config file for client lcdproc
+ render(lcdproc_conf, 'lcd/lcdproc.conf.tmpl', lcd, trim_blocks=True)
+
+ return None
+
+def apply(lcd):
+ if not lcd:
+ call('systemctl stop lcdproc.service LCDd.service')
+
+ for file in [lcdd_conf, lcdproc_conf]:
+ if os.path.exists(file):
+ os.remove(file)
+ else:
+ # Restart server
+ call('systemctl restart LCDd.service lcdproc.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/etc/systemd/system/LCDd.service.d/override.conf b/src/etc/systemd/system/LCDd.service.d/override.conf
new file mode 100644
index 000000000..5f3f0dc95
--- /dev/null
+++ b/src/etc/systemd/system/LCDd.service.d/override.conf
@@ -0,0 +1,8 @@
+[Unit]
+After=
+After=vyos-router.service
+
+[Service]
+ExecStart=
+ExecStart=/usr/sbin/LCDd -c /run/LCDd/LCDd.conf
+
diff --git a/src/etc/systemd/system/hostapd@.service.d/override.conf b/src/etc/systemd/system/hostapd@.service.d/override.conf
index bb8e81d7a..b03dbc299 100644
--- a/src/etc/systemd/system/hostapd@.service.d/override.conf
+++ b/src/etc/systemd/system/hostapd@.service.d/override.conf
@@ -3,8 +3,7 @@ After=
After=vyos-router.service
[Service]
-WorkingDirectory=/run/hostapd
-EnvironmentFile=
+WorkingDirectory=/run/LCDd
ExecStart=
-ExecStart=/usr/sbin/hostapd -B -P /run/hostapd/%i.pid /run/hostapd/%i.conf
-PIDFile=/run/hostapd/%i.pid
+ExecStart=/usr/sbin/LCDd -s 1 -f -c /run/LCDd/LCDd.conf
+
diff --git a/src/systemd/LCDd@.service b/src/systemd/LCDd@.service
deleted file mode 100644
index a4604cf21..000000000
--- a/src/systemd/LCDd@.service
+++ /dev/null
@@ -1,10 +0,0 @@
-[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..5aa99ec78
--- /dev/null
+++ b/src/systemd/lcdproc.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=LCDproc system status information viewer on %I
+Documentation=man:lcdproc(8) http://www.lcdproc.org/
+After=vyos-router.service
+After=LCDd.service
+
+[Service]
+User=root
+ExecStart=/usr/bin/lcdproc -f -c /run/lcdproc/lcdproc.conf
+PIDFile=/run/lcdproc/lcdproc.pid
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/systemd/lcdproc@.service b/src/systemd/lcdproc@.service
deleted file mode 100644
index 9a1723dba..000000000
--- a/src/systemd/lcdproc@.service
+++ /dev/null
@@ -1,10 +0,0 @@
-[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