diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-26 06:13:58 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-26 06:13:58 -0500 |
commit | 71a729feb9242fa5f809c6ec4e7a3db572ec8822 (patch) | |
tree | d2b7919f7a0f73522cac26a61f56e4ee021ecc0d /hscript/network.cc | |
parent | 1efbbaf0145dd785b2cefcf1f51703372efed2f3 (diff) | |
download | horizon-71a729feb9242fa5f809c6ec4e7a3db572ec8822.tar.gz horizon-71a729feb9242fa5f809c6ec4e7a3db572ec8822.tar.bz2 horizon-71a729feb9242fa5f809c6ec4e7a3db572ec8822.tar.xz horizon-71a729feb9242fa5f809c6ec4e7a3db572ec8822.zip |
hscript: Implement NetAddress::execute
Diffstat (limited to 'hscript/network.cc')
-rw-r--r-- | hscript/network.cc | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/hscript/network.cc b/hscript/network.cc index e375385..a47e69e 100644 --- a/hscript/network.cc +++ b/hscript/network.cc @@ -265,7 +265,41 @@ bool NetAddress::validate(ScriptOptions opts) const { } bool NetAddress::execute(ScriptOptions) const { - return false; + std::ofstream config("/tmp/horizon/netifrc/config_" + this->iface(), + std::ios_base::app); + if(!config) { + output_error("installfile:" + std::to_string(this->lineno()), + "netaddress: couldn't write network configuration for " + + this->iface()); + return false; + } + + switch(this->type()) { + case DHCP: + config << "dhcp"; + break; + case SLAAC: + /* automatically handled by netifrc */ + break; + case Static: + config << this->address() << "/" << std::to_string(this->prefix()) + << std::endl; + break; + } + + if(!this->gateway().empty()) { + std::ofstream route("/tmp/horizon/netifrc/routes_" + this->iface(), + std::ios_base::app); + if(!route) { + output_error("installfile:" + std::to_string(this->lineno()), + "netaddress: couldn't write route configuration for " + + this->iface()); + return false; + } + route << "default via " << this->gateway() << std::endl; + } + + return true; } |