add config class
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
8c814590f9
commit
ffaaf13d19
@ -0,0 +1,12 @@
|
||||
[serveurs]
|
||||
[serveurs.serveur1]
|
||||
ip = '100.000.000.000'
|
||||
nbContainerMax = 10
|
||||
|
||||
[serveurs.serveur2]
|
||||
ip = '200.000.000.000'
|
||||
nbContainerMax = 20
|
||||
|
||||
[serveurs.serveur3]
|
||||
ip = '300.000.000.000'
|
||||
nbContainerMax = 30
|
@ -0,0 +1,32 @@
|
||||
#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 *server_section = config.get_as<toml::table>("serveurs");
|
||||
if (server_section == nullptr) {
|
||||
return hosts;
|
||||
}
|
||||
|
||||
// Parcourir les serveurs
|
||||
for (const auto& [server_name_key, server_info_value] : *server_section) {
|
||||
std::string server_name{server_name_key};
|
||||
toml::table *server_info_ptr = server_info_value.as_table();
|
||||
if (server_info_ptr == nullptr) {
|
||||
|
||||
}
|
||||
toml::table &server_info = *server_info_ptr;
|
||||
|
||||
if(server_info.get_as<std::string>("ip") && server_info.get_as<int64_t>("nbContainerMax")){
|
||||
std::string server_ip = server_info.get_as<std::string>("ip")->get();
|
||||
int server_max_containers = server_info.get_as<int64_t>("nbContainerMax")->get();
|
||||
|
||||
hosts.push_back(sk::host(server_ip,server_max_containers));
|
||||
}
|
||||
}
|
||||
|
||||
return hosts;
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <toml++/toml.h>
|
||||
|
||||
#include "host.hpp"
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace sk{
|
||||
class config{
|
||||
public:
|
||||
static std::vector<sk::host> loadHostsFromToml(const fs::path& confFile);
|
||||
|
||||
};
|
||||
}
|
Loading…
Reference in new issue