项目作者: sayotte

项目描述 :
Go goyacc-based config file parser/generator for ISC-DHCP
高级语言: Go
项目地址: git://github.com/sayotte/iscdhcp.git
创建时间: 2017-08-20T17:38:09Z
项目社区:https://github.com/sayotte/iscdhcp

开源协议:BSD 3-Clause "New" or "Revised" License

下载


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

  1. fd, err := os.Open(fileName)
  2. if err != nil {
  3. log.Fatalf("os.Open(%q): %s", fileName, err)
  4. }
  5. statements, err := iscdhcp.Decode(fd)
  6. if err != nil {
  7. log.Fatalf("iscdhcp.Decode(): %s", err)
  8. }

Generating

  1. hs := HostStatement{
  2. Hostname: "serverA.myDomain.tld",
  3. }
  4. hs.Statements = append(hs.Statements, HardwareStatement{"ethernet", "0:1:2:3:4:5"})
  5. hs.Statements = append(hs.Statements, FixedAddressStatement{net.ParseIP("1.2.3.4")})
  6. hs.Statements = append(hs.Statements, IncludeStatement{"filename.cfg"})
  7. subnetStmt := SubnetStatement{
  8. SubnetNumber: net.ParseIP("1.2.3.0"),
  9. Netmask: net.ParseIP("255.255.255.0"),
  10. }
  11. subnetStmt.Statements = append(subnetStmt.Statements, hs)
  12. fmt.Println(subnetStmt.IndentedString(""))

The above yields this:

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

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.