summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-07-15 20:58:28 +0200
committerChristian Poessinger <christian@poessinger.com>2020-07-15 20:58:28 +0200
commitc24cecc325defc87973b28d288b23eca8368927d (patch)
tree051a18b72a40bc9405235c8487157493e3b83fbb
parent2dd1392cfe28518658604c88e606c7aec03936a7 (diff)
parent63052b8906871dc314945922e7f27ef24e114a45 (diff)
downloadvyos-1x-c24cecc325defc87973b28d288b23eca8368927d.tar.gz
vyos-1x-c24cecc325defc87973b28d288b23eca8368927d.zip
Merge branch 'curlrc' of github.com:c-po/vyos-1x into current
* 'curlrc' of github.com:c-po/vyos-1x: http-client: T2651: support specifying source-interface/address for curl xml: T2651: provide general source-interface include file
-rw-r--r--data/templates/system/curlrc.tmpl8
-rw-r--r--interface-definitions/include/source-address-ipv4-ipv6.xml.i17
-rw-r--r--interface-definitions/include/source-interface.xml.i12
-rw-r--r--interface-definitions/interfaces-vxlan.xml.in13
-rw-r--r--interface-definitions/system-options.xml.in11
-rwxr-xr-xsrc/conf_mode/system-options.py75
6 files changed, 83 insertions, 53 deletions
diff --git a/data/templates/system/curlrc.tmpl b/data/templates/system/curlrc.tmpl
new file mode 100644
index 000000000..675e35a0c
--- /dev/null
+++ b/data/templates/system/curlrc.tmpl
@@ -0,0 +1,8 @@
+{% if http_client is defined %}
+{% if http_client.source_interface is defined %}
+--interface "{{ http_client.source_interface }}"
+{% endif %}
+{% if http_client.source_address is defined %}
+--interface "{{ http_client.source_address }}"
+{% endif %}
+{% endif %}
diff --git a/interface-definitions/include/source-address-ipv4-ipv6.xml.i b/interface-definitions/include/source-address-ipv4-ipv6.xml.i
new file mode 100644
index 000000000..6d2d77c95
--- /dev/null
+++ b/interface-definitions/include/source-address-ipv4-ipv6.xml.i
@@ -0,0 +1,17 @@
+<leafNode name="source-address">
+ <properties>
+ <help>IPv4/IPv6 source address</help>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>IPv4 source-address</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ipv6</format>
+ <description>IPv6 source-address</description>
+ </valueHelp>
+ <constraint>
+ <validator name="ipv4-address"/>
+ <validator name="ipv6-address"/>
+ </constraint>
+ </properties>
+</leafNode>
diff --git a/interface-definitions/include/source-interface.xml.i b/interface-definitions/include/source-interface.xml.i
new file mode 100644
index 000000000..ae579c2a6
--- /dev/null
+++ b/interface-definitions/include/source-interface.xml.i
@@ -0,0 +1,12 @@
+<leafNode name="source-interface">
+ <properties>
+ <help>Physical interface used for connection</help>
+ <valueHelp>
+ <format>interface</format>
+ <description>Physical interface used for connection</description>
+ </valueHelp>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ </properties>
+</leafNode>
diff --git a/interface-definitions/interfaces-vxlan.xml.in b/interface-definitions/interfaces-vxlan.xml.in
index fdde57525..bd3ab4022 100644
--- a/interface-definitions/interfaces-vxlan.xml.in
+++ b/interface-definitions/interfaces-vxlan.xml.in
@@ -64,18 +64,7 @@
</constraint>
</properties>
</leafNode>
- <leafNode name="source-interface">
- <properties>
- <help>Physical Interface used for this connection</help>
- <valueHelp>
- <format>interface</format>
- <description>Interface used for VXLAN underlay</description>
- </valueHelp>
- <completionHelp>
- <script>${vyos_completion_dir}/list_interfaces.py</script>
- </completionHelp>
- </properties>
- </leafNode>
+ #include <include/source-interface.xml.i>
#include <include/interface-mtu-1200-9000.xml.i>
<leafNode name="remote">
<properties>
diff --git a/interface-definitions/system-options.xml.in b/interface-definitions/system-options.xml.in
index 48bc353ab..194773329 100644
--- a/interface-definitions/system-options.xml.in
+++ b/interface-definitions/system-options.xml.in
@@ -33,7 +33,7 @@
<description>Poweroff VyOS</description>
</valueHelp>
<constraint>
- <regex>(ignore|reboot|poweroff)</regex>
+ <regex>^(ignore|reboot|poweroff)$</regex>
</constraint>
<constraintErrorMessage>Must be ignore, reboot, or poweroff</constraintErrorMessage>
</properties>
@@ -44,6 +44,15 @@
<valueless/>
</properties>
</leafNode>
+ <node name="http-client">
+ <properties>
+ <help>Global options used for HTTP based commands</help>
+ </properties>
+ <children>
+ #include <include/source-interface.xml.i>
+ #include <include/source-address-ipv4-ipv6.xml.i>
+ </children>
+ </node>
</children>
</node>
</children>
diff --git a/src/conf_mode/system-options.py b/src/conf_mode/system-options.py
index 8de3b6fa2..d7c5c0443 100755
--- a/src/conf_mode/system-options.py
+++ b/src/conf_mode/system-options.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2019 VyOS maintainers and contributors
+# Copyright (C) 2019-2020 VyOS maintainers and contributors
#
# 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
@@ -16,67 +16,62 @@
import os
+from netifaces import interfaces
from sys import exit
-from copy import deepcopy
+
from vyos.config import Config
+from vyos.template import render
+from vyos.util import call
from vyos import ConfigError
-from vyos.util import run
-
from vyos import airbag
airbag.enable()
-systemd_ctrl_alt_del = '/lib/systemd/system/ctrl-alt-del.target'
-
-default_config_data = {
- 'beep_if_fully_booted': False,
- 'ctrl_alt_del': 'ignore',
- 'reboot_on_panic': True
-}
+config_file = r'/etc/curlrc'
+systemd_action_file = '/lib/systemd/system/ctrl-alt-del.target'
def get_config():
- opt = deepcopy(default_config_data)
conf = Config()
- conf.set_level('system options')
- if conf.exists(''):
- if conf.exists('ctrl-alt-del-action'):
- opt['ctrl_alt_del'] = conf.return_value('ctrl-alt-del-action')
+ base = ['system', 'options']
+ options = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)
+ return options
- opt['beep_if_fully_booted'] = conf.exists('beep-if-fully-booted')
- opt['reboot_on_panic'] = conf.exists('reboot-on-panic')
+def verify(options):
+ if 'http_client' in options.keys():
+ config = options['http_client']
+ if 'source_interface' in config.keys():
+ if not config['source_interface'] in interfaces():
+ raise ConfigError(f'Source interface {source_interface} does not '
+ f'exist'.format(**config))
- return opt
+ if {'source_address', 'source_interface'} <= set(config):
+ raise ConfigError('Can not define both HTTP source-interface and source-address')
-def verify(opt):
- pass
+ return None
-def generate(opt):
- pass
+def generate(options):
+ render(config_file, 'system/curlrc.tmpl', options, trim_blocks=True)
+ return None
-def apply(opt):
+def apply(options):
# Beep action
- if opt['beep_if_fully_booted']:
- run('systemctl enable vyos-beep.service')
+ if 'beep_if_fully_booted' in options.keys():
+ call('systemctl enable vyos-beep.service')
else:
- run('systemctl disable vyos-beep.service')
+ call('systemctl disable vyos-beep.service')
# Ctrl-Alt-Delete action
- if opt['ctrl_alt_del'] == 'ignore':
- if os.path.exists(systemd_ctrl_alt_del):
- os.unlink('/lib/systemd/system/ctrl-alt-del.target')
-
- elif opt['ctrl_alt_del'] == 'reboot':
- if os.path.exists(systemd_ctrl_alt_del):
- os.unlink(systemd_ctrl_alt_del)
- os.symlink('/lib/systemd/system/reboot.target', systemd_ctrl_alt_del)
+ if os.path.exists(systemd_action_file):
+ os.unlink(systemd_action_file)
- elif opt['ctrl_alt_del'] == 'poweroff':
- if os.path.exists(systemd_ctrl_alt_del):
- os.unlink(systemd_ctrl_alt_del)
- os.symlink('/lib/systemd/system/poweroff.target', systemd_ctrl_alt_del)
+ if 'ctrl_alt_del_action' in options.keys():
+ if options['ctrl_alt_del_action'] == 'reboot':
+ os.symlink('/lib/systemd/system/reboot.target', systemd_action_file)
+ elif options['ctrl_alt_del_action'] == 'poweroff':
+ os.symlink('/lib/systemd/system/poweroff.target', systemd_action_file)
# Reboot system on kernel panic
with open('/proc/sys/kernel/panic', 'w') as f:
- if opt['reboot_on_panic']:
+ if 'reboot_on_panic' in options.keys():
f.write('60')
else:
f.write('0')