开发者

programming language recommendation for Expressing Network Configs

I would like to see开发者_如何学Go if there is a language for expressing network configuration. I can use M4 and YAML for macro-fying some of the configs but with conditional statements, they seem to break down.

Any recommendations?

Thanks, Neel


My NCD programming language may be just what you're looking for.

Here's a sample program for configuring a wired network interface with DHCP (same one as from the wiki):

process lan {
    # Set device.
    var("eth0") dev;

    # Wait for device, set it up, and wait for network cable.
    net.backend.waitdevice(dev);
    net.up(dev);
    net.backend.waitlink(dev);

    # DHCP configuration.
    # net.ipv4.dhcp() will block here until it obtaines an IP address.
    # Note that it will only obtain the IP address, and *not* assign it;
    # we do that with a separate command below.
    net.ipv4.dhcp(dev) dhcp;

    # Check IP address - make sure it's not local.
    # If you have other reserved subnets around, check for those too.
    ip_in_network(dhcp.addr, "127.0.0.0", "8") test_local;
    ifnot(test_local);

    # Assign IP address, as obtained by DHCP.
    net.ipv4.addr(dev, dhcp.addr, dhcp.prefix);

    # Add default route, as obtained by DHCP.
    net.ipv4.route("0.0.0.0", "0", dhcp.gateway, "20", dev);

    # Configure DNS servers, as obtained by DHCP.
    net.dns(dhcp.dns_servers, "20");
}

Be sure to read the entire NCD wiki page. NCD is capable of much more then what it may look like at first (say, conditionals, loops, dynamic configuration of unknown devices...). It can even do some non-network-related tasks, like report input device (keyboard, mouse) events.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜