Python Vymgmt not being able to pass variables

Hello guys is there a way to run a command that replaces certain pieces of the set command with the variables values?? I have tried doing this with %s but i think im missing something here…

Basic idea is to create queues one after the other for a certain ip…

Code

import vymgmt

vyos = vymgmt.Router(‘192.168.1.126’, ‘vyos’, password=‘vyos’, port=22)

vyos.login()
vyos.configure()
x = 5
counter = 20
classip = 100

vyos.set(“traffic-policy shaper EGRESS_QOS bandwidth ‘1800kbit’”)
for x in range(5) :
x =+ 1

vyos.set("traffic-policy shaper EGRESS_QOS class %s bandwidth '35%'")(,classip)
vyos.set("traffic-policy shaper EGRESS_QOS class %s burst '2kb'")(,classip)
vyos.set("traffic-policy shaper EGRESS_QOS class %s ceiling '100%'")(,classip)
vyos.set("traffic-policy shaper EGRESS_QOS class %s match CLIENT1 ip source address '192.168.1.%s/24'")(classip, counter)
vyos.set("traffic-policy shaper EGRESS_QOS class %s queue-type 'fq-codel'")(,classip)
counter =+ 1
classip =+ 1

vyos.set(“traffic-policy shaper EGRESS_QOS default bandwidth ‘65%’”)
vyos.set(“traffic-policy shaper EGRESS_QOS default burst ‘2kb’”)
vyos.set(“traffic-policy shaper EGRESS_QOS default ceiling ‘100%’”)
vyos.set(“traffic-policy shaper EGRESS_QOS default queue-type ‘fq-codel’”)
vyos.set(“interfaces ethernet eth0 traffic-policy out ‘EGRESS_QOS’”)

#vyos.delete(“system options reboot-on-panic”)

vyos.commit()
vyos.save()
vyos.exit()
vyos.logout()

Hi,

this is python, so you have to build the string.
Look here for more infos:
https://pyformat.info/

since python 3.6 you can use “f strings” what i personal like.

1 Like

This will do exacly what i need …thanks…