You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
1.0 KiB
32 lines
1.0 KiB
#include "config.hpp"
|
|
|
|
std::vector<sk::host> sk::config::loadHostsFromToml(const fs::path &confFile) {
|
|
std::vector<sk::host> hosts;
|
|
|
|
auto config = toml::parse_file(confFile.string());
|
|
toml::table *serverSection = config.get_as<toml::table>("serveurs");
|
|
if (serverSection == nullptr) {
|
|
return hosts;
|
|
}
|
|
|
|
// Parcourir les serveurs
|
|
for (const auto &[serverNameKey, serverInfoValue] : *serverSection) {
|
|
std::string serverName{serverNameKey};
|
|
toml::table *serverInfoPtr = serverInfoValue.as_table();
|
|
if (serverInfoPtr == nullptr) {
|
|
}
|
|
toml::table &serverInfo = *serverInfoPtr;
|
|
|
|
if (serverInfo.get_as<std::string>("ip") &&
|
|
serverInfo.get_as<int64_t>("nbContainerMax")) {
|
|
std::string serverIp = serverInfo.get_as<std::string>("ip")->get();
|
|
int serverMaxContainers =
|
|
serverInfo.get_as<int64_t>("nbContainerMax")->get();
|
|
|
|
hosts.push_back(sk::host(serverIp, serverMaxContainers));
|
|
}
|
|
}
|
|
|
|
return hosts;
|
|
}
|