|
- #
- # Installation information:
- # ln -s ~lab/.local ~root
- # ~/.local/bin/virtaulenv venv
- # . ./venv/bin/activate
- # export TMPDIR=/var/tmp
- # pip install git+https://www.funkthat.com/gitea/jmg/vlanmang.git
- #
- # Configuration information:
- # . ./venv/bin/activate
- # python -m vlanmang
- #
-
- import vlanmang
- from pysnmp.hlapi import usmDESPrivProtocol
-
- protomapping = dict(DES=usmDESPrivProtocol)
-
- def parse_snmpconf(fname):
- snmpconf = {}
- with open(fname) as fp:
- snmpconf = dict((l.strip().split() for l in fp if l.strip()))
-
- return snmpconf
-
- def make_vlanswitch(fname, switch_info, *args):
- snmpconf = parse_snmpconf(fname)
-
- authdata = dict(username=snmpconf['defSecurityName'], authKey=snmpconf['defAuthPassphrase'],
- privKey=snmpconf['defPrivPassphrase'], privProtocol=protomapping[snmpconf['defPrivType']])
-
- switch = vlanmang.SwitchConfig(snmpconf['transport'], authdata, switch_info, *args)
-
- return switch
-
- switch = {
- 1: {
- 'u': [ 1, 24 ],
- }
- }
- for i in range(2, 24):
- switch[i + 100] = dict(t=[ 1 ], u=[ i ])
-
- switch = make_vlanswitch('/root/.snmp/hosts/poe.conf', switch, list(range(25, 36)))
|