Posted on May 14, 2021 4:51 am
 |  Asked by Mantas Alonderis
 |  48 views
0
0
Print Friendly, PDF & Email

Hello,

I’m trying to create multiple VLANs for Arista EOS switches with for loop but not sure how to as (config-vlan-number) changing on every vlan configuration. Any advice? Using pexpect for this:

“`

for n in range(2, 11):
print(“Creating VLAN ” + str(n))
ch.sendline(‘conf t’)
ch.expect(‘\(config\)#’)
config_commands = f’vlan {n}’
config_name = f’name PexpectVLAN{n}’
ch.sendline(config_commands)
ch.expect(‘\(config-vlan-{n}\)#’)    #how to read every vlan in the loop
ch.sendline(config_name)
ch.expect(‘\(config-vlan-{n}\)#’)
ch.sendline(‘end’)

“`

Thank you

 

Post your Answer

You must be logged in to post an answer.