summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-11-14 07:15:23 +0100
committerChristian Poessinger <christian@poessinger.com>2020-11-14 07:54:55 +0100
commitba483643bd7340960d72dc424e7d57876d99b0cd (patch)
tree8942872515ce2625b1866e8f08e4b923927b556d
parent0d921d0494edc40dd82cf4073300bfe466cc0fdc (diff)
downloadvyos-1x-ba483643bd7340960d72dc424e7d57876d99b0cd.tar.gz
vyos-1x-ba483643bd7340960d72dc424e7d57876d99b0cd.zip
options: keyboard: T3038: use proper XML <defaultValue> over hardcoded Python value
We should not use hardcoded Python values whenever possible. vyos.xml provides an abstraction of the XML CLI definitions providing default values from the CLI specified via the <defaultValue> node. This increases consistency among all XML/Python wrappers. Additional small fixes in this commit (besides the bad practice incorporating unrelated changes into the same commit) contain: - Keyboard layout shout be explicitly set for /dev/console - Added missing Debian dependency on console-data - When looking for a key in a dict, we do not need to specify dict.keys()
-rw-r--r--debian/control1
-rw-r--r--interface-definitions/system-options.xml.in1
-rwxr-xr-xsrc/conf_mode/system-options.py24
3 files changed, 16 insertions, 10 deletions
diff --git a/debian/control b/debian/control
index c5dda7883..a290952a3 100644
--- a/debian/control
+++ b/debian/control
@@ -28,6 +28,7 @@ Depends:
conntrack,
conserver-client,
conserver-server,
+ console-data,
crda,
cron,
dbus,
diff --git a/interface-definitions/system-options.xml.in b/interface-definitions/system-options.xml.in
index fab0c0169..12e4044af 100644
--- a/interface-definitions/system-options.xml.in
+++ b/interface-definitions/system-options.xml.in
@@ -111,6 +111,7 @@
<description>Denmark</description>
</valueHelp>
</properties>
+ <defaultValue>us</defaultValue>
</leafNode>
</children>
</node>
diff --git a/src/conf_mode/system-options.py b/src/conf_mode/system-options.py
index bf0bd56ec..92d60df1b 100755
--- a/src/conf_mode/system-options.py
+++ b/src/conf_mode/system-options.py
@@ -20,9 +20,11 @@ from netifaces import interfaces
from sys import exit
from vyos.config import Config
+from vyos.configdict import dict_merge
from vyos.template import render
from vyos.util import cmd
from vyos.validate import is_addr_assigned
+from vyos.xml import defaults
from vyos import ConfigError
from vyos import airbag
airbag.enable()
@@ -38,6 +40,12 @@ def get_config(config=None):
conf = Config()
base = ['system', 'options']
options = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
+
+ # We have gathered the dict representation of the CLI, but there are default
+ # options which we need to update into the dictionary retrived.
+ default_values = defaults(base)
+ options = dict_merge(default_values, options)
+
return options
def verify(options):
@@ -70,7 +78,7 @@ def generate(options):
def apply(options):
# Beep action
- if 'beep_if_fully_booted' in options.keys():
+ if 'beep_if_fully_booted' in options:
cmd('systemctl enable vyos-beep.service')
else:
cmd('systemctl disable vyos-beep.service')
@@ -95,7 +103,7 @@ def apply(options):
# Reboot system on kernel panic
with open('/proc/sys/kernel/panic', 'w') as f:
- if 'reboot_on_panic' in options.keys():
+ if 'reboot_on_panic' in options:
f.write('60')
else:
f.write('0')
@@ -107,14 +115,10 @@ def apply(options):
else:
cmd('systemctl disable tuned.service')
- # Keyboard layout
- if 'keyboard_layout' in options.keys():
- try:
- cmd('loadkeys {}'.format(options['keyboard_layout']))
- except OSError:
- raise ConfigError('Dos not possible to set {} as keyboard layout'.format(options['keyboard_layout']))
- else:
- cmd('loadkeys us')
+ # Keyboard layout - there will be always the default key inside the dict
+ # but we check for key existence anyway
+ if 'keyboard_layout' in options:
+ cmd('loadkeys -C /dev/console {keyboard_layout}'.format(**options))
if __name__ == '__main__':
try: