Code Monkey home page Code Monkey logo

frosting's Introduction

Frosting

Frosting is the template library developed to provision network equipment based on small templates with a minimum of logic.

Outline

The idea is that you write a template, that template compiles in to a YAML structure in which you define the variables. Example:

Template

interface {{interface}}
 ipv4 address {{ipv4}} {{netmask}}
!

Service Definition

---
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

Example code

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)

Loading structure as python dict

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()

frosting's People

Contributors

eising avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.