From 7296dab624754e5155cf4abffbe4827c176a7009 Mon Sep 17 00:00:00 2001 From: bastien ollier Date: Fri, 22 Sep 2023 13:56:58 +0200 Subject: [PATCH] add fct read config.toml --- CMakeLists.txt | 15 ++++++++++---- src/main.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e1f698..5d2378f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,9 +4,16 @@ project(planificador) add_compile_options(-Wall -Wextra -pedantic) -add_executable(planificador - src/host.cpp - src/runner.cpp - src/main.cpp +include(FetchContent) +FetchContent_Declare( + tomlplusplus + GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git + GIT_TAG v3.3.0 ) +FetchContent_MakeAvailable(tomlplusplus) + +file(GLOB nameFile "src/*.cpp") +add_executable(planificador src/host.cpp src/runner.cpp src/main.cpp) target_compile_features(planificador PUBLIC cxx_std_17) + +include_directories(${tomlplusplus_SOURCE_DIR}/include) diff --git a/src/main.cpp b/src/main.cpp index 03d4672..df7d99a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,10 +3,53 @@ #include #include +#include +#include + +#include +#include +#include +#include +#include "host.hpp" + +namespace fs = std::filesystem; + +std::vector makeMachinesFromToml(const fs::path& confFile){ + std::vector hosts; + + auto config = toml::parse_file( confFile.string() ); + toml::table *server_section = config.get_as("serveurs"); + + // 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("ip") && server_info.get_as("nbContainerMax")){ + std::string server_ip = server_info.get_as("ip")->get(); + int server_max_containers = server_info.get_as("nbContainerMax")->get(); + + hosts.push_back(sk::host(server_ip,server_max_containers)); + } + } + + return hosts; +} + + int main() { - std::queue queue; - queue.push(sk::program{"echo $(( 1 + 2 ))", - "ghcr.io/moshell-lang/moshell:master"}); + std::vector hosts = makeMachinesFromToml("conf.toml"); + for(int x=0;x < hosts.size();x++){ + std::cout< queue; + queue.push(sk::program{"echo $(( 1 + 2 ))", "ghcr.io/moshell-lang/moshell:master"}); sk::runner runner; while (!queue.empty()) { const sk::program ¤t = queue.front(); @@ -14,6 +57,6 @@ int main() { std::cout << "out: " << res.out << "\n"; std::cout << "err: " << res.err << "\n"; queue.pop(); - } + }*/ return 0; -} +} \ No newline at end of file