summaryrefslogtreecommitdiff
path: root/hscript/network.cc
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 06:13:58 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-10-26 06:13:58 -0500
commit71a729feb9242fa5f809c6ec4e7a3db572ec8822 (patch)
treed2b7919f7a0f73522cac26a61f56e4ee021ecc0d /hscript/network.cc
parent1efbbaf0145dd785b2cefcf1f51703372efed2f3 (diff)
downloadhorizon-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.cc36
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;
}