summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRunar Borge <runar@borge.nu>2018-06-09 22:31:09 +0200
committerRunar Borge <runar@borge.nu>2018-06-09 22:31:09 +0200
commitf3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1 (patch)
treea043804da4a0b841c86455ceb8c9e8d5f73f7717 /src
parent06b807f9b898c6bef55c9c0888bf5fd1c96bc9bd (diff)
parente916c9a55ffdff970c1796829d1bee319802b353 (diff)
downloadvyos-1x-f3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1.tar.gz
vyos-1x-f3b4cfecbe48c75c88b9396f68c4b9fc2d7babc1.zip
Merge branch 'current' of git://github.com/vyos/vyos-1x into current
Diffstat (limited to 'src')
-rwxr-xr-xsrc/completion/list_interfaces.py31
-rwxr-xr-xsrc/conf_mode/snmp.py31
-rwxr-xr-xsrc/op_mode/cpu_summary.py24
3 files changed, 77 insertions, 9 deletions
diff --git a/src/completion/list_interfaces.py b/src/completion/list_interfaces.py
index 59c9dffad..a4968c52f 100755
--- a/src/completion/list_interfaces.py
+++ b/src/completion/list_interfaces.py
@@ -1,8 +1,31 @@
#!/usr/bin/env python3
-import netifaces
+import sys
+import argparse
-if __name__ == '__main__':
- interfaces = netifaces.interfaces()
+import vyos.interfaces
- print(" ".join(interfaces))
+
+parser = argparse.ArgumentParser()
+group = parser.add_mutually_exclusive_group()
+group.add_argument("-t", "--type", type=str, help="List interfaces of specific type")
+group.add_argument("-b", "--broadcast", action="store_true", help="List all broadcast interfaces")
+
+args = parser.parse_args()
+
+if args.type:
+ try:
+ interfaces = vyos.interfaces.list_interfaces_of_type(args.type)
+
+ except ValueError as e:
+ print(e, file=sys.stderr)
+ print("")
+elif args.broadcast:
+ eth = vyos.interfaces.list_interfaces_of_type("ethernet")
+ bridge = vyos.interfaces.list_interfaces_of_type("bridge")
+ bond = vyos.interfaces.list_interfaces_of_type("bonding")
+ interfaces = eth + bridge + bond
+else:
+ interfaces = vyos.interfaces.list_interfaces()
+
+print(" ".join(interfaces))
diff --git a/src/conf_mode/snmp.py b/src/conf_mode/snmp.py
index 7623206b4..863f7e2e2 100755
--- a/src/conf_mode/snmp.py
+++ b/src/conf_mode/snmp.py
@@ -18,6 +18,7 @@
import sys
import os
+import shutil
import stat
import pwd
import time
@@ -46,7 +47,6 @@ OIDs = {
'des' : '.1.3.6.1.6.3.10.1.2.2',
'none': '.1.3.6.1.6.3.10.1.2.1'
}
-
# SNMPS template - be careful if you edit the template.
client_config_tmpl = """
### Autogenerated by snmp.py ###
@@ -634,6 +634,9 @@ def verify(snmp):
if user['privPassword'] == '' and user['privMasterKey'] == '':
raise ConfigError('Must specify encrypted-key or plaintext-key for user privacy')
+ if user['privMasterKey'] and user['engineID'] == '':
+ raise ConfigError('Can not have "encrypted-key" without engineid')
+
if user['authPassword'] == '' and user['authMasterKey'] == '' and user['privTsmKey'] == '':
raise ConfigError('Must specify auth or tsm-key for user auth')
@@ -711,12 +714,30 @@ def generate(snmp):
def apply(snmp):
if snmp is not None:
- if not os.path.exists('/config/snmp/tls'):
- os.makedirs('/config/snmp/tls')
- os.chmod('/config/snmp/tls', stat.S_IWUSR | stat.S_IRUSR)
+ nonvolatiledir = '/config/snmp/tls'
+ volatiledir = '/etc/snmp/tls'
+ if not os.path.exists(nonvolatiledir):
+ os.makedirs(nonvolatiledir)
+ os.chmod(nonvolatiledir, stat.S_IWUSR | stat.S_IRUSR)
# get uid for user 'snmp'
snmp_uid = pwd.getpwnam('snmp').pw_uid
- os.chown('/config/snmp/tls', snmp_uid, -1)
+ os.chown(nonvolatiledir, snmp_uid, -1)
+
+ # move SNMP certificate files from volatile location to non volatile /config/snmp
+ if os.path.exists(volatiledir) and os.path.isdir(volatiledir):
+ files = os.listdir(volatiledir)
+ for f in files:
+ shutil.move(volatiledir + '/' + f, nonvolatiledir)
+ os.chmod(nonvolatiledir + '/' + f, stat.S_IWUSR | stat.S_IRUSR)
+
+ os.rmdir(volatiledir)
+ os.symlink(nonvolatiledir, volatiledir)
+
+ if os.path.islink(volatiledir):
+ link = os.readlink(volatiledir)
+ if link != nonvolatiledir:
+ os.unlink(volatiledir)
+ os.symlink(nonvolatiledir, volatiledir)
# start SNMP daemon
os.system("sudo systemctl restart snmpd.service")
diff --git a/src/op_mode/cpu_summary.py b/src/op_mode/cpu_summary.py
new file mode 100755
index 000000000..3da5835e9
--- /dev/null
+++ b/src/op_mode/cpu_summary.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import re
+
+from vyos.util import colon_separated_to_dict
+
+
+FILE_NAME = '/proc/cpuinfo'
+
+with open(FILE_NAME, 'r') as f:
+ data_raw = f.read()
+
+data = colon_separated_to_dict(data_raw)
+
+# Accumulate all data in a dict for future support for machine-readable output
+cpu_data = {}
+cpu_data['cpu_number'] = len(data['processor'])
+cpu_data['models'] = list(set(data['model name']))
+
+# Strip extra whitespace from CPU model names, /proc/cpuinfo is prone to that
+cpu_data['models'] = map(lambda s: re.sub('\s+', ' ', s), cpu_data['models'])
+
+print("CPU(s): {0}".format(cpu_data['cpu_number']))
+print("CPU model(s): {0}".format(",".join(cpu_data['models'])))