diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-12 03:17:02 -0500 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-10-12 03:17:02 -0500 |
commit | 35de0bc2f701c79a7c5bb9a20bcc2b3a01665ab0 (patch) | |
tree | 8aff0d19d795d9689d73a21fb300dab359fafd34 /hscript | |
parent | 6d857cc2dd223fde89eb9c3c08815a14c08ea7a9 (diff) | |
download | horizon-35de0bc2f701c79a7c5bb9a20bcc2b3a01665ab0.tar.gz horizon-35de0bc2f701c79a7c5bb9a20bcc2b3a01665ab0.tar.bz2 horizon-35de0bc2f701c79a7c5bb9a20bcc2b3a01665ab0.tar.xz horizon-35de0bc2f701c79a7c5bb9a20bcc2b3a01665ab0.zip |
Implmement some 'netaddress' requirements
Diffstat (limited to 'hscript')
-rw-r--r-- | hscript/script.cc | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/hscript/script.cc b/hscript/script.cc index b5efa47..267b892 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -78,6 +78,9 @@ struct Script::ScriptPrivate { /*! Target system's mountpoints. */ std::vector< std::unique_ptr<Horizon::Keys::Mount> > mounts; + /*! Network addressing configuration */ + std::vector< std::unique_ptr<Horizon::Keys::NetAddress> > addresses; + /*! Store +key_obj+ representing the key +key_name+. * @param key_name The name of the key that is being stored. * @param key_obj The Key object associated with the key. @@ -148,6 +151,12 @@ struct Script::ScriptPrivate { ); this->mounts.push_back(std::move(mount)); return true; + } else if(key_name == "netaddress") { + std::unique_ptr<Keys::NetAddress> addr( + dynamic_cast<Keys::NetAddress *>(key_obj) + ); + this->addresses.push_back(std::move(addr)); + return true; } else { return false; } @@ -299,6 +308,7 @@ const Script *Script::load(std::istream &sstream, const ScriptOptions opts) { bool Script::validate() const { int failures = 0; std::set<std::string> seen_mounts; + std::map<const std::string, int> seen_iface; if(!this->internal->network->validate(this->opts)) failures++; if(!this->internal->hostname->validate(this->opts)) failures++; @@ -316,7 +326,7 @@ bool Script::validate() const { output_error("installfile:" + std::to_string(mount->lineno()), "mount: mountpoint " + mount->mountpoint() + " has already been specified; " + mount->device() + - " is a duplicate", ""); + " is a duplicate"); } seen_mounts.insert(mount->mountpoint()); if(this->opts.test(InstallEnvironment)) { @@ -327,7 +337,35 @@ bool Script::validate() const { /* Runner.Validate.mount.Root */ if(seen_mounts.find("/") == seen_mounts.end()) { failures++; - output_error("installfile:0", "mount: no root mount specified", ""); + output_error("installfile:0", "mount: no root mount specified"); + } + + /* Runner.Validate.network.netaddress */ + if(this->internal->network->test() && + this->internal->addresses.size() == 0) { + failures++; + output_error("installfile:0", + "networking requested but no 'netaddress' defined", + "You need to specify at least one address to enable " + "networking."); + } + for(auto &address : this->internal->addresses) { + if(!address->validate(this->opts)) { + failures++; + } + + /* Runner.Validate.network.netaddress.Count */ + if(seen_iface.find(address->iface()) == seen_iface.end()) { + seen_iface.insert(std::make_pair(address->iface(), 1)); + } else { + seen_iface[address->iface()] += 1; + if(seen_iface[address->iface()] > 255) { + failures++; + output_error("installfile:" + std::to_string(address->lineno()), + "netaddress: interface '" + address->iface() + + "' has too many addresses assigned"); + } + } } output_message("validator", "0", "installfile", |