Coder Social home page Coder Social logo

iscdhcp's Introduction

Build Status

Brief

This is a config-file parser and generator library for ISC-DHCP, written in the Go programming language.

The parser is generated using the goyacc utility.

Supported statements to date include a common subset of those used by DHCPd. The code should be easy to extend.

Usage

Parsing

fd, err := os.Open(fileName)
if err != nil {
    log.Fatalf("os.Open(%q): %s", fileName, err)
}

statements, err := iscdhcp.Decode(fd)
if err != nil {
    log.Fatalf("iscdhcp.Decode(): %s", err)
}

Generating

hs := HostStatement{
    Hostname: "serverA.myDomain.tld",
}
hs.Statements = append(hs.Statements, HardwareStatement{"ethernet", "0:1:2:3:4:5"})
hs.Statements = append(hs.Statements, FixedAddressStatement{net.ParseIP("1.2.3.4")})
hs.Statements = append(hs.Statements, IncludeStatement{"filename.cfg"})

subnetStmt := SubnetStatement{
    SubnetNumber: net.ParseIP("1.2.3.0"),
    Netmask:      net.ParseIP("255.255.255.0"),
}
subnetStmt.Statements = append(subnetStmt.Statements, hs)

fmt.Println(subnetStmt.IndentedString(""))

The above yields this:

subnet 1.2.3.0 netmask 255.255.255.0 {
    host serverA.myDomain.tld {
        hardware ethernet 0:1:2:3:4:5;
        fixed-address 1.2.3.4;
        include "filename.cfg";
    }
}

Modifying

New statements must first be defined in statements.go, and satisfy the iscdhcp.Statement interface.

To update the parser, edit the goyacc grammar definitions in the parser.y file. After updating these you must call goyacc parser.y to regenerate the y.go file, after which you can rebuild the package.

To update generator code, edit the IndentedString() method of the statements with which you're concerned.

It's best to modify both parser- and generator-code in lockstep, and add "round-trip" tests for any new statements introduced to ensure that the generated output is understandable to the parser. Round-trip tests are found in statements_test.go.

Contributing

Contributions should be submitted as pull requests from a named (i.e. not master) branch.

Running make (and the unit tests and linter checks it entails) on the result of merging or rebasing your PR branch over current master branch must exit successfully.

iscdhcp's People

Contributors

sayotte avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lwgboy

iscdhcp's Issues

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.