Open lgfausak opened 5 years ago
How about a way to add your own builtins?
- defbuiltin:
name: CIDR-OFFSET
args: [$net, $inc]
module: lgfausak_cidr
function: cider_offset
This would python import the code specified. The code in lgfausak_cidr.py
would contain a python function:
import ipaddress
def cider_offset(tree, args, bindings):
return str(ipaddress.IPv4Network(unicode(args["$net"])).network_address + args["$inc"])
The point being users could add their own Python code as required.
yup, that would do the trick.
While working on a ansible deployment I often find myself needing ip manipulation. I have modified the version of yamp I get by adding this to the top:
This is super handy for me because I can use it in python_eval, e.g.
I pass this macro an ip cidr address (e.g. 10.20.30.128/25) and an offset (like 5) and the result is 10.20.30.133. I use this all the time. It might even make sense to have a built in for ip address manipulation.