i read data from my config file like this:
ip_vlan1 = "10.10.($id+100).5"
ip_vlan2 = "10.11.($id*2+1).6"
v.v...
And for each vlan, I want calculate vlan address for it, based on ID and vlan-expression:
def calculate_vlan_id(id, vlan_exp):
...
return ip_addr # string
Example:
def(3, ip_vlan1) --> result: "10.10.103.5"
def(5, ip_vlan2) --> result: "10.11.11.6"
Do you have a solution for this?
Thanks in advance, folks!
You could use a text templating engine. (Which is safer than using eval based tricks).
Here’s an example using genshi
If you really need the
calculate_vlan_idfunction it would look something like this:Edit:
As requested here’s an example using jinja2: This may not be the best way to do this, the jinja2 docs are large and confusing.
Both these methods are untested