summaryrefslogtreecommitdiff
path: root/hscript
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-17 00:52:38 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2020-03-17 00:52:38 -0500
commitbbe669b761db4cb03fca2dbf9a7890d5a7e120af (patch)
tree580b71e39783a72c0416b65ef6714f454696e221 /hscript
parent28c81a32aa59a9b2d39ddd7f86fb1d2677da32cc (diff)
downloadhorizon-bbe669b761db4cb03fca2dbf9a7890d5a7e120af.tar.gz
horizon-bbe669b761db4cb03fca2dbf9a7890d5a7e120af.tar.bz2
horizon-bbe669b761db4cb03fca2dbf9a7890d5a7e120af.tar.xz
horizon-bbe669b761db4cb03fca2dbf9a7890d5a7e120af.zip
hscript: Add new netconfigtype key and associated tests
Not wired up to netaddress et al, but does parse properly.
Diffstat (limited to 'hscript')
-rw-r--r--hscript/network.cc33
-rw-r--r--hscript/network.hh22
-rw-r--r--hscript/script.cc3
-rw-r--r--hscript/script_i.hh13
4 files changed, 71 insertions, 0 deletions
diff --git a/hscript/network.cc b/hscript/network.cc
index 1750a60..a7b2bee 100644
--- a/hscript/network.cc
+++ b/hscript/network.cc
@@ -47,6 +47,39 @@ bool Network::execute() const {
}
+Key *NetConfigType::parseFromData(const std::string &data, int lineno,
+ int *errors, int *, const Script *script) {
+ std::string type = data;
+ ConfigSystem system;
+
+ std::transform(type.cbegin(), type.cend(), type.begin(), ::tolower);
+
+ if(type == "netifrc") {
+ system = Netifrc;
+ } else if(type == "eni") {
+ system = ENI;
+ } else {
+ if(errors) *errors += 1;
+ output_error("installfile:" + std::to_string(lineno),
+ "netconfigtype: invalid or missing config type",
+ "one of 'netifrc', 'eni' required");
+ return nullptr;
+ }
+
+ return new NetConfigType(script, lineno, system);
+}
+
+bool NetConfigType::validate() const {
+ /* Validation takes place during parsing. */
+ return true;
+}
+
+bool NetConfigType::execute() const {
+ /* This key doesn't perform any action by itself. */
+ return true;
+}
+
+
Key *NetAddress::parseFromData(const std::string &data, int lineno, int *errors,
int *, const Script *script) {
long elements = std::count(data.cbegin(), data.cend(), ' ') + 1;
diff --git a/hscript/network.hh b/hscript/network.hh
index ec8d2cf..415a337 100644
--- a/hscript/network.hh
+++ b/hscript/network.hh
@@ -29,6 +29,28 @@ public:
bool execute() const override;
};
+class NetConfigType : public Key {
+public:
+ enum ConfigSystem {
+ Netifrc,
+ ENI
+ };
+private:
+ ConfigSystem _sys;
+
+ NetConfigType(const Script *_sc, int _line, const ConfigSystem _s) :
+ Key(_sc, _line), _sys(_s) {}
+public:
+ static Key *parseFromData(const std::string &, int, int*, int*,
+ const Script *);
+
+ /*! Retrieve the desired network configuration system. */
+ ConfigSystem type() const { return this->_sys; }
+
+ bool validate() const override;
+ bool execute() const override;
+};
+
class NetAddress : public Key {
public:
/*! Determines the type of address an interface will obtain. */
diff --git a/hscript/script.cc b/hscript/script.cc
index 7db3ed0..fd9fc5a 100644
--- a/hscript/script.cc
+++ b/hscript/script.cc
@@ -49,6 +49,7 @@ const std::map<std::string, key_parse_fn> valid_keys = {
{"repository", &Repository::parseFromData},
{"signingkey", &SigningKey::parseFromData},
+ {"netconfigtype", &NetConfigType::parseFromData},
{"netaddress", &NetAddress::parseFromData},
{"nameserver", &Nameserver::parseFromData},
{"netssid", &NetSSID::parseFromData},
@@ -78,6 +79,8 @@ bool Script::ScriptPrivate::store_key(const std::string &key_name, Key *obj,
const ScriptOptions &opts) {
if(key_name == "network") {
return store_network(obj, lineno, errors, warnings, opts);
+ } else if(key_name == "netconfigtype") {
+ return store_netconfig(obj, lineno, errors, warnings, opts);
} else if(key_name == "netaddress") {
std::unique_ptr<NetAddress> addr(dynamic_cast<NetAddress *>(obj));
this->addresses.push_back(std::move(addr));
diff --git a/hscript/script_i.hh b/hscript/script_i.hh
index 0ed362e..a94a0d7 100644
--- a/hscript/script_i.hh
+++ b/hscript/script_i.hh
@@ -43,6 +43,8 @@ struct Script::ScriptPrivate {
/*! Determines whether or not to enable networking. */
std::unique_ptr<Network> network;
+ /*! Determines the network configuration system to use. */
+ std::unique_ptr<NetConfigType> netconfig;
/*! The target system's hostname. */
std::unique_ptr<Hostname> hostname;
/*! The packages to install to the target system. */
@@ -126,6 +128,17 @@ struct Script::ScriptPrivate {
return true;
}
+ bool store_netconfig(Key *obj, int line, int *errors, int *, ScriptOptions) {
+ if(netconfig) {
+ DUPLICATE_ERROR(netconfig, "netconfigtype",
+ netconfig->type());
+ return false;
+ }
+ std::unique_ptr<NetConfigType> nc(dynamic_cast<NetConfigType *>(obj));
+ netconfig = std::move(nc);
+ return true;
+ }
+
bool store_hostname(Key* obj, int line, int *errors, int *, ScriptOptions) {
if(hostname) {
DUPLICATE_ERROR(hostname, "hostname", hostname->value())