2011-09-27 66 views
-1

我想看看是否有表達網絡配置的語言。我可以使用M4和YAML來宏觀化一些配置,但是使用條件語句,它們似乎崩潰了。表達網絡配置的編程語言建議

任何建議?

感謝, 尼爾

+0

您的意思是[網絡本身的配置](http://en.wikipedia.org/wiki/Configuration_%28geometry%29)或[每個節點](http://en.wikipedia .ORG /維基/ CONFIGURATION_FILE)? –

+0

我想要一種表達設備配置的語言。 – user963986

回答

0

NCD programming language可能是你要找的。

下面是通過DHCP配置有線網絡接口(同一個從維基)的一個樣本程序:

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"); 
} 

請務必閱讀整個NCD維基頁面。 NCD的功能遠不止於它最初的樣子(比如,條件,循環,未知設備的動態配置......)。它甚至可以執行一些非網絡相關的任務,如報告輸入設備(鍵盤,鼠標)事件。