Frosting is the template library developed to provision network equipment based on small templates with a minimum of logic.
The idea is that you write a template, that template compiles in to a YAML structure in which you define the variables. Example:
interface {{interface}} ipv4 address {{ipv4}} {{netmask}} !
---
service:
name: myservice
vars:
interface:
type: types.TextInput
validator: validators.Ios_interface
ipv4:
type: types.TextInput
validator: validators.IPv4_Address
netmask:
type: types.TextInput
validator: validators.IPv4_Address
from frosting import Frosting
template = """
interface {{interface}}.{{vlan}}
encapsulation dot1q {{vlan}}
ipv4 address {{ipv4}} {{netmask}}
!
"""
structure = """
---
available_validators:
- frosting.validators.IPv4_Address: 'Validates IPv4 Addresses, e.g. 10.0.0.1'
- frosting.validators.IPv6_Address: 'Validates IPv6 Addresses, e.g. 2001:db8::f00'
name: "MyService"
vars:
interface:
type: frosting.types.TextInput
validator: ""
ipv4:
type: frosting.types.TextInput
validator: "frosting.validators.IPv4_Address"
netmask:
type: frosting.types.TextInput
validator: "frosting.validators.IPv4_Address"
vlan:
type: types.IntegerInput
limit: 1..4094
"""
frosting = Frosting(template)
frosting.load_yaml_structure(structure)
frosting.add("interface", "TenGigE0/1/2/3")
frosting.add("ipv4", "1.1.1.1")
frosting.add("netmask", "255.255.255.252")
frosting.add("vlan", 400)
result = frosting.compile()
print(result)
frosting = Frosting(template)
frosting.load_structure({
'var1': {
'type': 'frosting.types.TextInput',
'validator': 'frosting.validators.IPv4_Address'
}
})
frosting.add("var1", "1.1.1.1")
configuration = frosting.compile()