summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/templates/system-display/lcdproc.conf.tmpl12
-rwxr-xr-xsrc/conf_mode/system-display.py75
2 files changed, 43 insertions, 44 deletions
diff --git a/data/templates/system-display/lcdproc.conf.tmpl b/data/templates/system-display/lcdproc.conf.tmpl
index 2fe491e63..92aee8efe 100644
--- a/data/templates/system-display/lcdproc.conf.tmpl
+++ b/data/templates/system-display/lcdproc.conf.tmpl
@@ -37,7 +37,6 @@ ReportToSyslog=true
DisplayName="{%- if show['title'] %}{{ show['title'] }}{%- else %}VyOS{%- endif %}"
{%- if show['host'] %}
-{#%- for s in show['host'] %#}
[CPU]
# Show screen
@@ -77,7 +76,6 @@ Active={%- if 'proc' in show['host'] %}true{%- else %}false{%- endif %}
[Disk]
# Show screen
Active={%- if 'disk' in show['host'] %}true{%- else %}false{%- endif %}
-{#%- endfor %#}
{%- else %} {# if show['host'] #}
{# Turn off sections that default active #}
@@ -90,8 +88,6 @@ Active=false
[Load]
Active=false
-[TimeDate]
-Active=false
{%- endif %} {# if show['host'] #}
[TimeDate]
@@ -118,10 +114,10 @@ TimeFormat="%H:%M"
Active={%- if show['network']['interface'] %}true{%- else %}false{%- endif %}
{%- for i in show['network']['interface'] %}
# Show stats for Interface {{ i }}
-Interface0={{ i }}
+Interface{{ loop.index0 }}={{ i }}
{%- if show['network']['interface'][i]['alias'] %}
# Interface alias name to display [default: <interface name>]
-Alias0={{ show['network']['interface'][i]['alias'] }}
+Alias{{ loop.index0 }}={{ show['network']['interface'][i]['alias'] }}
{%- endif %}
{%- endfor %}
@@ -139,7 +135,7 @@ unit=bit
#transfer=TRUE
{%- endif %} {# if show['network'] #}
-{%- else %} {# if show #}
+{%- else %}{# if show #}
{# Turn off sections that default active #}
[CPU]
@@ -153,7 +149,7 @@ Active=false
[TimeDate]
Active=false
-{%- endif %}
+{%- endif %}{# if show #}
[Battery]
# Show screen
diff --git a/src/conf_mode/system-display.py b/src/conf_mode/system-display.py
index e30d591cc..557b7cf6a 100755
--- a/src/conf_mode/system-display.py
+++ b/src/conf_mode/system-display.py
@@ -15,7 +15,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import re
from sys import exit
@@ -28,53 +27,57 @@ from vyos import airbag
airbag.enable()
def get_config():
- c = Config()
+ # Return a (possibly empty) configuration dictionary
+ return Config().get_config_dict(['system', 'display'])
- if not c.exists('system display'):
- return None
-
- c.set_level('system display')
-
- return c.get_config_dict([])
-
-def generate(c):
- if c == None:
+def generate(config_dict):
+ if not config_dict:
return None
# Render config file for daemon LCDd
- render('/etc/LCDd.conf', 'system-display/LCDd.conf.tmpl', c)
+ render('/etc/LCDd.conf', 'system-display/LCDd.conf.tmpl', config_dict)
# Render config file for client lcdproc
- render('/etc/lcdproc.conf', 'system-display/lcdproc.conf.tmpl', c)
+ render('/etc/lcdproc.conf', 'system-display/lcdproc.conf.tmpl', config_dict)
return None
-def verify(c):
- if c == None:
+def verify(config_dict):
+ if not config_dict:
return None
- if c.get('model') == None:
- raise ConfigError('For system display, a model is [REQUIRED]')
+ if 'model' not in config_dict:
+ raise ConfigError('Display model is [REQUIRED]')
- if c.get('show') == None:
- raise ConfigError('For system display, show cannot be empty')
+ 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 c['show'] and 'interface' not in c['show']['network']:
- raise ConfigError('system display show network must have at least one interface')
+ 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 c['show'] and 'interface' in c['show']['network'] and len(c['show']['network']['interface']) > 3:
- raise ConfigError('system display show network interface cannot have more than 3 entries')
+ 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 apply(c):
- if not c or 'disabled' in c.keys():
- # Stop client first
- run('systemctl stop lcdproc.service')
- # Stop server next
- return run('systemctl stop LCDd.service')
-
- # Stop client first
+def apply(config_dict):
+ # Stop client
run('systemctl stop lcdproc.service')
- # Restart server next
+
+ if not config_dict or 'disabled' in config_dict:
+ # Stop server
+ run('systemctl stop LCDd.service')
+ return None
+
+ # Restart server
run('systemctl restart LCDd.service')
# Start client
run('systemctl start lcdproc.service')
@@ -83,10 +86,10 @@ def apply(c):
if __name__ == '__main__':
try:
- c = get_config()
- verify(c)
- generate(c)
- apply(c)
+ config_dict = get_config()
+ verify(config_dict)
+ generate(config_dict)
+ apply(config_dict)
except ConfigError as e:
print(e)
exit(1)