summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-11-12 10:03:25 +0100
committerMergify <37929162+mergify[bot]@users.noreply.github.com>2023-11-12 09:12:27 +0000
commite769d0d4b504e71ea152a31af28e09dd7bc1e43e (patch)
treee2a8743cc6f3edc035b4d576e208a368f7869ccc /src
parent822a80e98744a92f2f15bc552f611e7327d11c9f (diff)
downloadvyos-1x-e769d0d4b504e71ea152a31af28e09dd7bc1e43e.tar.gz
vyos-1x-e769d0d4b504e71ea152a31af28e09dd7bc1e43e.zip
T5658: add common methods interface_list() and vrf_list() to vyos.utils.network
Reduce amount of duplicated (3 times) code in op-mode scripts for ping, traceroute and mtr. (cherry picked from commit 7b27a20c8664460482301cc8d7554048f152485e)
Diffstat (limited to 'src')
-rw-r--r--src/op_mode/mtr.py27
-rwxr-xr-xsrc/op_mode/ping.py28
-rwxr-xr-xsrc/op_mode/traceroute.py26
3 files changed, 13 insertions, 68 deletions
diff --git a/src/op_mode/mtr.py b/src/op_mode/mtr.py
index 759f7078c..57aab5389 100644
--- a/src/op_mode/mtr.py
+++ b/src/op_mode/mtr.py
@@ -14,29 +14,13 @@
# 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
import sys
import socket
import ipaddress
-from vyos.utils.network import get_all_vrfs
-from vyos.ifconfig import Section
-
-
-def interface_list() -> list:
- """
- Get list of interfaces in system
- :rtype: list
- """
- return Section.interfaces()
-
-
-def vrf_list() -> list:
- """
- Get list of VRFs in system
- :rtype: list
- """
- return list(get_all_vrfs().keys())
+from vyos.utils.network import interface_list
+from vyos.utils.network import vrf_list
+from vyos.utils.process import call
options = {
'report': {
@@ -214,7 +198,6 @@ mtr = {
6: '/bin/mtr -6',
}
-
class List(list):
def first(self):
return self.pop(0) if self else ''
@@ -337,6 +320,4 @@ if __name__ == '__main__':
sys.exit(f'mtr: Unknown host: {host}')
command = convert(mtr[version], args)
-
- # print(f'{command} {host}')
- os.system(f'{command} {host}')
+ call(f'{command} --curses --displaymode 0 {host}')
diff --git a/src/op_mode/ping.py b/src/op_mode/ping.py
index f1d87a118..583d8792c 100755
--- a/src/op_mode/ping.py
+++ b/src/op_mode/ping.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python3
-# Copyright (C) 2020 VyOS maintainers and contributors
+# Copyright (C) 2023 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
@@ -14,29 +14,13 @@
# 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
import sys
import socket
import ipaddress
-from vyos.utils.network import get_all_vrfs
-from vyos.ifconfig import Section
-
-
-def interface_list() -> list:
- """
- Get list of interfaces in system
- :rtype: list
- """
- return Section.interfaces()
-
-
-def vrf_list() -> list:
- """
- Get list of VRFs in system
- :rtype: list
- """
- return list(get_all_vrfs().keys())
+from vyos.utils.network import interface_list
+from vyos.utils.network import vrf_list
+from vyos.utils.process import call
options = {
'audible': {
@@ -295,6 +279,4 @@ if __name__ == '__main__':
sys.exit(f'ping: Unknown host: {host}')
command = convert(ping[version], args)
-
- # print(f'{command} {host}')
- os.system(f'{command} {host}')
+ call(f'{command} {host}')
diff --git a/src/op_mode/traceroute.py b/src/op_mode/traceroute.py
index 2f0edf53a..d2bac3f7c 100755
--- a/src/op_mode/traceroute.py
+++ b/src/op_mode/traceroute.py
@@ -14,29 +14,13 @@
# 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
import sys
import socket
import ipaddress
-from vyos.utils.network import get_all_vrfs
-from vyos.ifconfig import Section
-
-
-def interface_list() -> list:
- """
- Get list of interfaces in system
- :rtype: list
- """
- return Section.interfaces()
-
-
-def vrf_list() -> list:
- """
- Get list of VRFs in system
- :rtype: list
- """
- return list(get_all_vrfs().keys())
+from vyos.utils.network import interface_list
+from vyos.utils.network import vrf_list
+from vyos.utils.process import call
options = {
'backward-hops': {
@@ -251,6 +235,4 @@ if __name__ == '__main__':
sys.exit(f'traceroute: Unknown host: {host}')
command = convert(traceroute[version], args)
-
- # print(f'{command} {host}')
- os.system(f'{command} {host}')
+ call(f'{command} {host}')