Зачем объявлять
config = []
пустым и потом снова очищать, и еще несколько раз?
def generate_access_config(access, ps = False):
config_all = {}
access_template = ['switchport mode access',
'switchport access vlan',
'switchport nonegotiate',
'spanning-tree portfast',
'spanning-tree bpduguard enable']
port_security = ['switchport port-security maximum 2',
'switchport port-security violation restrict',
'switchport port-security']
for intf in access:
config = []
for line in access_template:
if line.endswith('vlan') == True:
config.append('{} {}'.format(line, access[intf]))
else:
config.append(line)
if ps == True:
config.extend(port_security)
config_all[intf] = config
return(config_all)