Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

Commit c11b394

Browse files
committed
Adding OFED option and Cluster singleton with global getter
1 parent 7825697 commit c11b394

18 files changed

Lines changed: 290 additions & 93 deletions

File tree

include/cloysterhpc/functions.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#ifndef CLOYSTERHPC_FUNCTIONS_H_
22
#define CLOYSTERHPC_FUNCTIONS_H_
33

4-
#include "services/log.h"
4+
#include <cloysterhpc/models/cluster.h>
5+
#include <cloysterhpc/services/log.h>
56
#include <boost/process/child.hpp>
67
#include <boost/process/pipe.hpp>
78
#include <cloysterhpc/services/repos.h>
@@ -19,6 +20,9 @@ namespace cloyster {
1920
extern bool dryRun;
2021

2122
using OS = cloyster::models::OS;
23+
24+
void initClusterSingleton(std::unique_ptr<models::Cluster> cluster);
25+
models::Cluster& getClusterSingleton();
2226
std::shared_ptr<cloyster::services::BaseRunner> getRunner();
2327
std::shared_ptr<cloyster::services::repos::RepoManager> getRepoManager(
2428
const OS& osinfo);
@@ -222,6 +226,29 @@ std::filesystem::directory_iterator openDir(const Path& path)
222226
fmt::format("Dry Run: Would open directory {}", path.string()));
223227
}
224228

229+
/**
230+
* @brief Converts enum to string.
231+
* @desc The case is the same used in the enum definition. Convert
232+
* it to lower before comparing.
233+
*/
234+
template <typename T>
235+
requires std::is_enum_v<T>
236+
std::string enumToString(T enumValue)
237+
{
238+
return static_cast<std::string>(magic_enum::enum_name<T>(enumValue));
239+
}
240+
241+
/**
242+
* @brief Converts a string to an enum if possible
243+
* @desc The comparison is made case insensitive
244+
*/
245+
template <typename T>
246+
requires std::is_enum_v<T>
247+
std::optional<T> enumOfStringOpt(const std::string& str)
248+
{
249+
return magic_enum::enum_cast<T>(str, magic_enum::case_insensitive);
250+
}
251+
225252
}
226253

227254
#endif // CLOYSTERHPC_FUNCTIONS_H_

include/cloysterhpc/models/answerfile.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <cloysterhpc/mailsystem/postfix.h>
1212
#include <cloysterhpc/models/os.h>
1313
#include <cloysterhpc/tools/ITool.h>
14+
#include <cloysterhpc/ofed.h>
15+
#include <magic_enum/magic_enum.hpp>
1416
#include <optional>
1517
#include <vector>
1618

@@ -156,6 +158,12 @@ class AnswerFile {
156158
std::filesystem::path key_file;
157159
};
158160

161+
struct AFOFED {
162+
std::string kind = static_cast<std::string>(magic_enum::enum_name(OFED::Kind::Inbox));
163+
std::string version = "latest";
164+
bool enabled = false;
165+
};
166+
159167
std::filesystem::path m_path;
160168
inifile m_ini;
161169

@@ -268,6 +276,7 @@ class AnswerFile {
268276
void loadNodes();
269277
void loadTools();
270278
void loadNVHPC();
279+
void loadOFED();
271280

272281
void dumpNodes();
273282

@@ -343,6 +352,7 @@ class AnswerFile {
343352
AFSystem system;
344353
AFNodes nodes;
345354
AFPostfix postfix;
355+
AFOFED ofed;
346356

347357
/**
348358
* @brief Loads the answer file from the specified path.

include/cloysterhpc/models/cluster.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class Cluster {
181181
void setProvisioner(Provisioner);
182182

183183
std::optional<OFED> getOFED() const;
184-
void setOFED(OFED::Kind kind);
184+
void setOFED(OFED::Kind kind, std::string version = "latest");
185185

186186
std::optional<std::unique_ptr<QueueSystem>>& getQueueSystem();
187187
void setQueueSystem(QueueSystem::Kind kind);

include/cloysterhpc/models/queuesystem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include <fmt/format.h>
1010
#include <string>
1111

12-
#include <cloysterhpc/functions.h>
13-
1412
// Forward declaration of Cluster
1513
namespace cloyster::models {
1614

include/cloysterhpc/ofed.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
#ifndef CLOYSTERHPC_OFED_H_
77
#define CLOYSTERHPC_OFED_H_
88

9-
#include <cloysterhpc/functions.h>
9+
#include "services/repos.h"
10+
#include <string>
11+
12+
#include <utility>
13+
1014

1115
/**
1216
* @class OFED
@@ -26,21 +30,28 @@ class OFED {
2630

2731
private:
2832
Kind m_kind { Kind::Inbox };
33+
std::string m_version;
2934

3035
public:
3136
OFED() = default;
32-
explicit OFED(Kind kind);
37+
OFED(Kind kind, std::string version)
38+
: m_kind(kind)
39+
, m_version(std::move(version))
40+
{}
3341

3442
void setKind(Kind kind);
3543
[[nodiscard]] Kind getKind() const;
3644

45+
void setVersion(std::string&& value) { m_version = std::move(value); }
46+
[[nodiscard]] std::string getVersion() const { return m_version; }
47+
3748
/**
3849
* @brief Installs the OFED software package.
3950
*
4051
* This method installs the appropriate OFED components based on the
4152
* specified kind.
4253
*/
43-
void install() const;
54+
void install(cloyster::services::repos::RepoManager& repoManager) const;
4455
};
4556

4657
#endif // CLOYSTERHPC_OFED_H_

include/cloysterhpc/services/shell.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ using cloyster::models::Cluster;
2323
*/
2424
class Shell final : public Execution {
2525
private:
26-
const std::unique_ptr<Cluster> m_cluster;
2726

2827
/**
2928
* @brief Configures SELinux mode.
@@ -171,20 +170,14 @@ class Shell final : public Execution {
171170
static void disableSELinux();
172171

173172
public:
174-
/**
175-
* @brief Constructs a Shell object.
176-
*
177-
* Initializes the Shell object with a reference to a Cluster object.
178-
*
179-
* @param cluster A reference to a unique pointer managing a Cluster object.
180-
*/
181-
explicit Shell(const std::unique_ptr<Cluster> cluster);
182173
/**
183174
* @brief Installs and configures the system.
184175
*
185176
* This function performs the installation and configuration processes.
186177
*/
187178
void install() override;
179+
180+
Shell();
188181
};
189182

190183
};

include/cloysterhpc/services/xcat.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class XCAT : public Provisioner {
4545
*/
4646
enum class NodeType { Compute, Service };
4747

48-
const std::unique_ptr<Cluster>& m_cluster;
49-
5048
struct {
5149
std::vector<std::string_view> otherpkgs = {};
5250
// @TODO: We need to support more than one osimage (:
@@ -189,6 +187,9 @@ class XCAT : public Provisioner {
189187
static void configureEL9();
190188

191189
public:
190+
XCAT();
191+
192+
192193
/**
193194
* @brief Download the repositories
194195
*/
@@ -262,8 +263,6 @@ class XCAT : public Provisioner {
262263
* This function resets the nodes.
263264
*/
264265
static void resetNodes();
265-
266-
explicit XCAT(const std::unique_ptr<Cluster>& cluster);
267266
};
268267

269268
};

src/functions.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <cloysterhpc/functions.h>
7+
#include <cloysterhpc/models/cluster.h>
78

89
#include <chrono>
910
#include <cstdio> /* FILE*, fopen, fclose */
@@ -62,8 +63,22 @@ std::shared_ptr<BaseRunner> getRunner()
6263
return runner.value();
6364
}
6465

66+
using cloyster::models::Cluster;
6567
using cloyster::services::repos::RepoManager;
6668

69+
static std::unique_ptr<Cluster> clusterSingleton;
70+
void initClusterSingleton(std::unique_ptr<Cluster> cluster)
71+
{
72+
assert(!clusterSingleton);
73+
clusterSingleton = std::move(cluster);
74+
}
75+
76+
Cluster& getClusterSingleton()
77+
{
78+
assert(clusterSingleton);
79+
return *clusterSingleton;
80+
}
81+
6782
std::shared_ptr<RepoManager> getRepoManager(const OS& osinfo)
6883
{
6984
static std::optional<std::shared_ptr<RepoManager>> repoManager

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cloysterhpc/services/shell.h>
1818
#include <cloysterhpc/verification.h>
1919
#include <cloysterhpc/view/newt.h>
20+
#include <cloysterhpc/functions.h>
2021
#include <internal_use_only/config.hpp>
2122
#include <regex>
2223

@@ -190,8 +191,10 @@ int main(int argc, const char** argv)
190191
model->dumpData(dumped_answerfile);
191192
}
192193

194+
cloyster::initClusterSingleton(std::move(model));
195+
193196
std::unique_ptr<Execution> executionEngine
194-
= std::make_unique<cloyster::services::Shell>(std::move(model));
197+
= std::make_unique<cloyster::services::Shell>();
195198

196199
executionEngine->install();
197200

src/models/answerfile.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void AnswerFile::loadOptions()
4949
loadNodes();
5050
loadTools();
5151
loadPostfix();
52+
loadOFED();
5253
}
5354

5455
void AnswerFile::dumpNetwork(
@@ -397,6 +398,9 @@ void AnswerFile::loadSystemSettings()
397398
afDistro, magic_enum::case_insensitive)) {
398399
system.distro = formatDistro.value();
399400
} else {
401+
if (cloyster::dryRun) {
402+
return;
403+
}
400404
throw std::runtime_error(
401405
fmt::format("Unsupported distro: {}", afDistro));
402406
}
@@ -607,6 +611,23 @@ void AnswerFile::loadPostfix()
607611
postfix.key_file = m_ini.getValue("postfix", "smtpd_tls_key_file", false);
608612
}
609613

614+
void AnswerFile::loadOFED()
615+
{
616+
auto kind = m_ini.getValue("ofed", "kind");
617+
if (kind != "") {
618+
ofed.enabled = true;
619+
ofed.kind = kind;
620+
auto afVersion = m_ini.getValue("ofed", "version");
621+
if (afVersion != "") {
622+
ofed.version = afVersion;
623+
} else {
624+
ofed.version = "latest"; // use as default
625+
}
626+
627+
LOG_DEBUG("OFED enabled, {} {}", ofed.kind, ofed.version)
628+
}
629+
}
630+
610631
};
611632

612633
#ifdef BUILD_TESTING

0 commit comments

Comments
 (0)