summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-12-28 16:13:03 +0100
committerChristian Poessinger <christian@poessinger.com>2020-12-28 16:20:51 +0100
commitbbc2a15795bfbe11febe8c00d2a592ba5cf8daf5 (patch)
tree47054ffca1f9c3e3f507356d38f3b3bbc9571340
parent9f459cb1185af7dd7fe3104b2fb047add69938cd (diff)
downloadvyos-1x-bbc2a15795bfbe11febe8c00d2a592ba5cf8daf5.tar.gz
vyos-1x-bbc2a15795bfbe11febe8c00d2a592ba5cf8daf5.zip
xml: completion-help: add helper for all local assigned IP addresses
This replaces the Python script by a bash variant which is much faster as the Python interpreter does not need to be launched on invocation.
-rw-r--r--interface-definitions/dhcp-server.xml.in2
-rw-r--r--interface-definitions/https.xml.in3
-rw-r--r--interface-definitions/include/listen-address-ipv4.xml.i18
-rw-r--r--interface-definitions/include/listen-address.xml.i3
-rw-r--r--interface-definitions/interfaces-tunnel.xml.in2
-rw-r--r--interface-definitions/snmp.xml.in3
-rwxr-xr-xsrc/completion/list_local.py24
-rwxr-xr-xsrc/completion/list_local_ips.sh29
8 files changed, 58 insertions, 26 deletions
diff --git a/interface-definitions/dhcp-server.xml.in b/interface-definitions/dhcp-server.xml.in
index 26b803fcb..2c1609d94 100644
--- a/interface-definitions/dhcp-server.xml.in
+++ b/interface-definitions/dhcp-server.xml.in
@@ -42,7 +42,7 @@
<valueless/>
</properties>
</leafNode>
- #include <include/listen-address.xml.i>
+ #include <include/listen-address-ipv4.xml.i>
<tagNode name="shared-network-name">
<properties>
<help>Name of DHCP shared network</help>
diff --git a/interface-definitions/https.xml.in b/interface-definitions/https.xml.in
index 69fe90dab..b613e30c1 100644
--- a/interface-definitions/https.xml.in
+++ b/interface-definitions/https.xml.in
@@ -22,6 +22,9 @@
<leafNode name="listen-address">
<properties>
<help>Address to listen for HTTPS requests</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_local_ips.sh --both</script>
+ </completionHelp>
<valueHelp>
<format>ipv4</format>
<description>HTTPS IPv4 address</description>
diff --git a/interface-definitions/include/listen-address-ipv4.xml.i b/interface-definitions/include/listen-address-ipv4.xml.i
new file mode 100644
index 000000000..530dbf619
--- /dev/null
+++ b/interface-definitions/include/listen-address-ipv4.xml.i
@@ -0,0 +1,18 @@
+<!-- included start from listen-address-ipv4.xml.i -->
+<leafNode name="listen-address">
+ <properties>
+ <help>Local IPv4 addresses for service to listen on</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_local_ips.sh --ipv4</script>
+ </completionHelp>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>IP address to listen for incoming connections</description>
+ </valueHelp>
+ <multi/>
+ <constraint>
+ <validator name="ipv4-address"/>
+ </constraint>
+ </properties>
+</leafNode>
+<!-- included end -->
diff --git a/interface-definitions/include/listen-address.xml.i b/interface-definitions/include/listen-address.xml.i
index e474344e4..5bfb7eb38 100644
--- a/interface-definitions/include/listen-address.xml.i
+++ b/interface-definitions/include/listen-address.xml.i
@@ -2,6 +2,9 @@
<leafNode name="listen-address">
<properties>
<help>Local IP addresses for service to listen on</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_local_ips.sh --both</script>
+ </completionHelp>
<valueHelp>
<format>ipv4</format>
<description>IP address to listen for incoming connections</description>
diff --git a/interface-definitions/interfaces-tunnel.xml.in b/interface-definitions/interfaces-tunnel.xml.in
index 574a7d0a4..8effa68b2 100644
--- a/interface-definitions/interfaces-tunnel.xml.in
+++ b/interface-definitions/interfaces-tunnel.xml.in
@@ -36,7 +36,7 @@
<description>Local IPv6 address for this tunnel [NOTICE: unavailable for mGRE tunnels]</description>
</valueHelp>
<completionHelp>
- <script>${vyos_completion_dir}/list_local.py</script>
+ <script>${vyos_completion_dir}/list_local_ips.sh</script>
</completionHelp>
<constraint>
<validator name="ip-address"/>
diff --git a/interface-definitions/snmp.xml.in b/interface-definitions/snmp.xml.in
index fb3e82256..0a0a29f4d 100644
--- a/interface-definitions/snmp.xml.in
+++ b/interface-definitions/snmp.xml.in
@@ -88,6 +88,9 @@
<tagNode name="listen-address">
<properties>
<help>IP address to listen for incoming SNMP requests</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_local_ips.sh --both</script>
+ </completionHelp>
<valueHelp>
<format>ipv4</format>
<description>IPv4 address to listen for incoming SNMP requests</description>
diff --git a/src/completion/list_local.py b/src/completion/list_local.py
deleted file mode 100755
index 40cc95f1e..000000000
--- a/src/completion/list_local.py
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env python3
-
-import json
-import argparse
-
-from vyos.util import cmd
-
-# [{"ifindex":1,"ifname":"lo","flags":["LOOPBACK","UP","LOWER_UP"],"mtu":65536,"qdisc":"noqueue","operstate":"UNKNOWN","group":"default","txqlen":1000,"link_type":"loopback","address":"00:00:00:00:00:00","broadcast":"00:00:00:00:00:00","addr_info":[{"family":"inet","local":"127.0.0.1","prefixlen":8,"scope":"host","label":"lo","valid_life_time":4294967295,"preferred_life_time":4294967295},{"family":"inet6","local":"::1","prefixlen":128,"scope":"host","valid_life_time":4294967295,"preferred_life_time":4294967295}]},{"ifindex":2,"ifname":"eth0","flags":["BROADCAST","MULTICAST","UP","LOWER_UP"],"mtu":1500,"qdisc":"pfifo_fast","operstate":"UP","group":"default","txqlen":1000,"link_type":"ether","address":"08:00:27:fa:12:53","broadcast":"ff:ff:ff:ff:ff:ff","addr_info":[{"family":"inet","local":"10.0.2.15","prefixlen":24,"broadcast":"10.0.2.255","scope":"global","label":"eth0","valid_life_time":4294967295,"preferred_life_time":4294967295},{"family":"inet6","local":"fe80::a00:27ff:fefa:1253","prefixlen":64,"scope":"link","valid_life_time":4294967295,"preferred_life_time":4294967295}]},{"ifindex":3,"ifname":"eth1","flags":["BROADCAST","MULTICAST","UP","LOWER_UP"],"mtu":1500,"qdisc":"pfifo_fast","operstate":"UP","group":"default","txqlen":1000,"link_type":"ether","address":"08:00:27:0d:25:dc","broadcast":"ff:ff:ff:ff:ff:ff","addr_info":[{"family":"inet6","local":"fe80::a00:27ff:fe0d:25dc","prefixlen":64,"scope":"link","valid_life_time":4294967295,"preferred_life_time":4294967295}]},{"ifindex":4,"ifname":"eth2","flags":["BROADCAST","MULTICAST","UP","LOWER_UP"],"mtu":1500,"qdisc":"pfifo_fast","operstate":"UP","group":"default","txqlen":1000,"link_type":"ether","address":"08:00:27:68:d0:b1","broadcast":"ff:ff:ff:ff:ff:ff","addr_info":[{"family":"inet6","local":"fe80::a00:27ff:fe68:d0b1","prefixlen":64,"scope":"link","valid_life_time":4294967295,"preferred_life_time":4294967295}]},{"ifindex":5,"ifname":"eth3","flags":["BROADCAST","MULTICAST","UP","LOWER_UP"],"mtu":1500,"qdisc":"pfifo_fast","operstate":"UP","group":"default","txqlen":1000,"link_type":"ether","address":"08:00:27:f0:17:c5","broadcast":"ff:ff:ff:ff:ff:ff","addr_info":[{"family":"inet6","local":"fe80::a00:27ff:fef0:17c5","prefixlen":64,"scope":"link","valid_life_time":4294967295,"preferred_life_time":4294967295}]}]
-
-if __name__ == '__main__':
- parser = argparse.ArgumentParser()
- group = parser.add_mutually_exclusive_group()
-
- out = cmd('ip -j address show')
- data = json.loads(out)
-
-
- interfaces = []
- for interface in data:
- if not 'addr_info' in interface:
- continue
- interfaces.extend(interface['addr_info'])
-
- print(' '.join([interface['local'] for interface in interfaces if 'local' in interface]))
diff --git a/src/completion/list_local_ips.sh b/src/completion/list_local_ips.sh
new file mode 100755
index 000000000..a506ce16e
--- /dev/null
+++ b/src/completion/list_local_ips.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+ipv4=0
+ipv6=0
+
+while [[ "$#" -gt 0 ]]; do
+ case $1 in
+ -4|--ipv4) ipv4=1 ;;
+ -6|--ipv6) ipv6=1 ;;
+ -b|--both) ipv4=1; ipv6=1 ;;
+ *) echo "Unknown parameter passed: $1" ;;
+ esac
+ shift
+done
+
+if [ $ipv4 -eq 1 ] && [ $ipv6 -eq 1 ]; then
+ ip a | grep inet | awk '{print $2}' | sed -e /^fe80::/d | awk -F/ '{print $1}'
+elif [ $ipv4 -eq 1 ] ; then
+ ip a | grep 'inet ' | awk '{print $2}' | awk -F/ '{print $1}'
+elif [ $ipv6 -eq 1 ] ; then
+ ip a | grep 'inet6 ' | awk '{print $2}' | sed -e /^fe80::/d | awk -F/ '{print $1}'
+else
+ echo "Usage:"
+ echo "-4|--ipv4 list only IPv4 addresses"
+ echo "-6|--ipv6 list only IPv6 addresses"
+ echo "--both list both IP4 and IPv6 addresses"
+ echo ""
+ exit 1
+fi