summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/lldp_op.py21
-rwxr-xr-xsrc/op_mode/ping.py8
-rwxr-xr-xsrc/op_mode/show_interfaces.py3
-rwxr-xr-xsrc/op_mode/wireguard.py17
4 files changed, 26 insertions, 23 deletions
diff --git a/src/op_mode/lldp_op.py b/src/op_mode/lldp_op.py
index 5d48e3210..0df6749aa 100755
--- a/src/op_mode/lldp_op.py
+++ b/src/op_mode/lldp_op.py
@@ -14,19 +14,19 @@
# 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 argparse
import jinja2
-from xml.dom import minidom
from sys import exit
from tabulate import tabulate
+from xml.dom import minidom
-from vyos.util import popen
+from vyos.util import cmd
from vyos.config import Config
parser = argparse.ArgumentParser()
parser.add_argument("-a", "--all", action="store_true", help="Show LLDP neighbors on all interfaces")
+parser.add_argument("-d", "--detail", action="store_true", help="Show detailes LLDP neighbor information on all interfaces")
parser.add_argument("-i", "--interface", action="store", help="Show LLDP neighbors on specific interface")
# Please be careful if you edit the template.
@@ -40,10 +40,8 @@ Device ID Local Proto Cap Platform Port ID
{% endfor -%}
"""
-def _get_neighbors():
- command = '/usr/sbin/lldpcli -f xml show neighbors'
- out,_ = popen(command)
- return out
+def get_neighbors():
+ return cmd('/usr/sbin/lldpcli -f xml show neighbors')
def extract_neighbor(neighbor):
"""
@@ -148,12 +146,17 @@ if __name__ == '__main__':
exit(0)
if args.all:
- neighbors = minidom.parseString(_get_neighbors())
+ neighbors = minidom.parseString(get_neighbors())
for neighbor in neighbors.getElementsByTagName('interface'):
tmp['neighbors'].append( extract_neighbor(neighbor) )
+ elif args.detail:
+ out = cmd('/usr/sbin/lldpctl -f plain')
+ print(out)
+ exit(0)
+
elif args.interface:
- neighbors = minidom.parseString(_get_neighbors())
+ neighbors = minidom.parseString(get_neighbors())
for neighbor in neighbors.getElementsByTagName('interface'):
# check if neighbor appeared on proper interface
if neighbor.getAttribute('name') == args.interface:
diff --git a/src/op_mode/ping.py b/src/op_mode/ping.py
index e56952c38..29b430d53 100755
--- a/src/op_mode/ping.py
+++ b/src/op_mode/ping.py
@@ -118,7 +118,8 @@ options = {
'vrf': {
'ping': 'sudo ip vrf exec {value} {command}',
'type': '<vrf>',
- 'help': 'Use specified VRF table'
+ 'help': 'Use specified VRF table',
+ 'dflt': 'default',
},
'verbose': {
'ping': '{command} -v',
@@ -207,6 +208,11 @@ if __name__ == '__main__':
sys.stdout.write(options[matched[0]]['type'])
sys.exit(0)
+ for name,option in options.items():
+ if 'dflt' in option and name not in args:
+ args.append(name)
+ args.append(option['dflt'])
+
try:
ip = socket.gethostbyname(host)
except socket.gaierror:
diff --git a/src/op_mode/show_interfaces.py b/src/op_mode/show_interfaces.py
index 46571c0c0..d4dae3cd1 100755
--- a/src/op_mode/show_interfaces.py
+++ b/src/op_mode/show_interfaces.py
@@ -220,8 +220,7 @@ def run_show_intf_brief(ifnames, iftypes, vif, vrrp):
oper = ['u', ] if oper_state in ('up', 'unknown') else ['A', ]
admin = ['u', ] if oper_state in ('up', 'unknown') else ['D', ]
addrs = [_ for _ in interface.get_addr() if not _.startswith('fe80::')] or ['-', ]
- # do not ask me why 56, it was the number in the perl code ...
- descs = list(split_text(interface.get_alias(),56))
+ descs = list(split_text(interface.get_alias(),0))
while intf or oper or admin or addrs or descs:
i = intf.pop(0) if intf else ''
diff --git a/src/op_mode/wireguard.py b/src/op_mode/wireguard.py
index 15bf63e81..e08bc983a 100755
--- a/src/op_mode/wireguard.py
+++ b/src/op_mode/wireguard.py
@@ -21,22 +21,17 @@ import shutil
import syslog as sl
import re
+from vyos.config import Config
from vyos.ifconfig import WireGuardIf
-
+from vyos.util import cmd
+from vyos.util import run
+from vyos.util import check_kmod
from vyos import ConfigError
-from vyos.config import Config
-from vyos.util import cmd, run
dir = r'/config/auth/wireguard'
psk = dir + '/preshared.key'
-def check_kmod():
- """ check if kmod is loaded, if not load it """
- if not os.path.exists('/sys/module/wireguard'):
- sl.syslog(sl.LOG_NOTICE, "loading wirguard kmod")
- if run('sudo modprobe wireguard') != 0:
- sl.syslog(sl.LOG_ERR, "modprobe wireguard failed")
- raise ConfigError("modprobe wireguard failed")
+k_mod = 'wireguard'
def generate_keypair(pk, pub):
""" generates a keypair which is stored in /config/auth/wireguard """
@@ -106,7 +101,7 @@ def del_key_dir(kname):
if __name__ == '__main__':
- check_kmod()
+ check_kmod(k_mod)
parser = argparse.ArgumentParser(description='wireguard key management')
parser.add_argument(
'--genkey', action="store_true", help='generate key-pair')