Skip to content

Commit

Permalink
Add name spaces and move files to their places
Browse files Browse the repository at this point in the history
I'm favoring to move stuff to models/ or services/
folders/namespaces. There is a lot of moves to do
yet but this already outlines some structure
  • Loading branch information
Daniel Hilst committed Feb 12, 2025
1 parent 086f661 commit 0487532
Show file tree
Hide file tree
Showing 72 changed files with 688 additions and 443 deletions.
4 changes: 2 additions & 2 deletions include/cloysterhpc/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ concept IsMoveable
template <typename T>
concept NotCopiableMoveable = !IsMoveable<T> && !IsCopyable<T>;
/**
* @brief Parser<P, T> means: P can parse and unparse Ts from streams. The
* @brief IsParser<P, T> means: P can parse and unparse Ts from streams. The
* parsers are allowed to throw exceptions
*/
template <typename Parser_, typename T>
concept Parser = requires(Parser_ parser, std::istream& parseInput,
concept IsParser = requires(Parser_ parser, std::istream& parseInput,
std::ostream& unparseOutput, const T& unparseInput, T& parseOutput) {
{ parser.parse(parseInput, parseOutput) } -> std::same_as<void>;
{ parser.unparse(unparseInput, unparseOutput) } -> std::same_as<void>;
Expand Down
5 changes: 2 additions & 3 deletions include/cloysterhpc/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
#ifndef CLOYSTERHPC_CONNECTION_H_
#define CLOYSTERHPC_CONNECTION_H_

#include <cloysterhpc/network.h>

#include <arpa/inet.h>
#include <boost/asio.hpp>
#include <expected>
#include <ifaddrs.h>
#include <memory>
#include <string>

#include <gsl/gsl-lite.hpp>

#include <cloysterhpc/network.h>

/* Each server can have one and only one connection to a given network, although
* it can have more than one address on the same interface. This may seem
* incorrect, but it is standard TCP networking.
Expand Down
17 changes: 7 additions & 10 deletions include/cloysterhpc/functions.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#ifndef CLOYSTERHPC_FUNCTIONS_H_
#define CLOYSTERHPC_FUNCTIONS_H_

#include "repos.h"
#include <cloysterhpc/services/repos.h>
#include <boost/process/child.hpp>
#include <boost/process/pipe.hpp>
#include <filesystem>
#include <glibmm/ustring.h>
#include <list>
#include <optional>
#include <string>
#include <vector>

#include <boost/asio.hpp>
#include <glibmm/keyfile.h>
#include <cloysterhpc/runner.h>
#include <cloysterhpc/services/runner.h>

namespace cloyster {
// Globals
extern bool dryRun;

std::shared_ptr<BaseRunner> getRunner();
std::shared_ptr<RepoManager<repository, BaseRunner>> getRepoManager(const OS& osinfo);
using OS = cloyster::models::OS;
std::shared_ptr<cloyster::services::BaseRunner> getRunner();
std::shared_ptr<cloyster::services::repos::RepoManager> getRepoManager(const OS& osinfo);


/**
* A command proxy, to us to be able to get the
Expand Down Expand Up @@ -171,9 +171,6 @@ std::string findAndReplace(const std::string_view& source,
*/
void copyFile(std::filesystem::path source, std::filesystem::path destination);

std::optional<Glib::ustring> readKeyfileString(Glib::RefPtr<Glib::KeyFile> file,
const std::string_view group, const std::string_view key);

} /* namespace cloyster */
} // namespace cloyster

#endif // CLOYSTERHPC_FUNCTIONS_H_
7 changes: 4 additions & 3 deletions include/cloysterhpc/mailsystem/postfix.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef CLOYSTERHPC_POSTFIX_H_
#define CLOYSTERHPC_POSTFIX_H_

#include <cloysterhpc/runner.h>
#include <cloysterhpc/services/runner.h>
#include <cstdint>
#include <filesystem>
#include <optional>
Expand All @@ -15,12 +15,13 @@
#include <cloysterhpc/messagebus.h>
#include <cloysterhpc/services/IService.h>

// @TODO move this to its own namespace
class Postfix : public IService {
public:
enum class Profile { Local, Relay, SASL };

private:
BaseRunner& m_runner;
cloyster::services::BaseRunner& m_runner;
Profile m_profile;
std::optional<std::string> m_hostname {};
std::optional<std::string> m_domain {};
Expand Down Expand Up @@ -75,7 +76,7 @@ class Postfix : public IService {
void setup(const std::filesystem::path& basedir = "/etc/postfix");

explicit Postfix(
std::shared_ptr<MessageBus> bus, BaseRunner& runner, Profile profile);
std::shared_ptr<MessageBus> bus, cloyster::services::BaseRunner& runner, Profile profile);
};

#endif // CLOYSTERHPC_POSTFIX_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define CLOYSTERHPC_ANSWERFILE_H_

#include <cloysterhpc/tools/ITool.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/models/os.h>
#include <boost/asio.hpp>
#include <cloysterhpc/inifile.h>
#include <cloysterhpc/mailsystem/postfix.h>
Expand All @@ -16,6 +16,8 @@

using boost::asio::ip::address;

namespace cloyster::models {

/**
* @struct AFNode
* @brief Holds individual node settings.
Expand Down Expand Up @@ -64,6 +66,7 @@ class AnswerFile {
std::optional<address> gateway;
std::optional<std::string> domain_name;
std::optional<std::vector<std::string>> nameservers;

std::optional<std::string> con_interface;
std::optional<address> con_ip_addr;
std::optional<std::string> con_mac_addr;
Expand Down Expand Up @@ -374,4 +377,6 @@ class answerfile_validation_exception : public std::exception {
const char* what() const noexcept override { return message.c_str(); }
};

};

#endif // CLOYSTERHPC_ANSWERFILE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@

#include <cloysterhpc/dbus_client.h>
#include <cloysterhpc/diskImage.h>
#include <cloysterhpc/headnode.h>
#include <cloysterhpc/models/headnode.h>
#include <cloysterhpc/models/node.h>
#include <cloysterhpc/models/queuesystem.h>
#include <cloysterhpc/mailsystem/postfix.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/node.h>
#include <cloysterhpc/ofed.h>
#include <cloysterhpc/queuesystem/pbs.h>
#include <cloysterhpc/queuesystem/slurm.h>
#include <cloysterhpc/repos.h>
#include <cloysterhpc/runner.h>
#include <cloysterhpc/services/runner.h>
#include <cloysterhpc/services/locale.h>
#include <cloysterhpc/services/repos.h>
#include <cloysterhpc/services/repofile.h>
#include <cloysterhpc/services/timezone.h>

// @TODO: Shouldn't Cluster be below cloyster namespace?

/**
* @class Cluster
Expand All @@ -35,13 +34,22 @@
* environment, including headnode, nodes, networks, provisioner, timezone,
* locale, and more.
*/

namespace cloyster::models {

/**
* @brief Represents the cluster state and configuration
*/
class Cluster {
public:
/**
* @enum SELinuxMode
* @brief Enumeration for SELinux modes.
*
*/
enum class SELinuxMode { Permissive, Enforcing, Disabled };

// @TODO: This class should not know about DBusClient

/**
* @enum Provisioner
Expand Down Expand Up @@ -74,9 +82,6 @@ class Cluster {
bool m_updateSystem { false };
DiskImage m_diskImage;

// Relace repository with generic repository
std::optional<RepoManager<repository, BaseRunner>> m_repos = std::nullopt;

public:
Cluster();

Expand Down Expand Up @@ -186,7 +191,7 @@ class Cluster {
void setQueueSystem(QueueSystem::Kind kind);

std::optional<Postfix>& getMailSystem();
void setMailSystem(Postfix::Profile profile, std::shared_ptr<BaseRunner> runner);
void setMailSystem(Postfix::Profile profile, std::shared_ptr<services::BaseRunner> runner);

const std::filesystem::path& getDiskImage() const;
void setDiskImage(const std::filesystem::path& diskImagePath);
Expand Down Expand Up @@ -257,4 +262,6 @@ class Cluster {
std::string nodeRootPassword;
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_CLUSTER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define CLOYSTERHPC_CPU_H_

#include <cstddef>
#include <stdexcept>

namespace cloyster::models {

class CPU {
private:
Expand Down Expand Up @@ -39,4 +40,6 @@ class CPU {
void setThreadsPerCore(std::size_t threadsPerCore);
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_CPU_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

#include <cloysterhpc/connection.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/server.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/models/server.h>

namespace cloyster::models {
class Headnode : public Server {
public:
enum class BootTarget { Text, Graphical };
Expand All @@ -32,4 +33,7 @@ class Headnode : public Server {
void setBootTarget(BootTarget bootTarget);
};


}; // namespace cloyster::models

#endif // CLOYSTERHPC_HEADNODE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

#include <cloysterhpc/connection.h>
#include <cloysterhpc/network.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/server.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/models/server.h>


namespace cloyster::models {
/**
* @class Node
* @brief A class representing a node in a server cluster.
Expand Down Expand Up @@ -59,4 +61,6 @@ class Node : public Server {
const std::optional<std::string>& nodeRootPassword);
};

}; // namespace cloyster::models {

#endif // CLOYSTERHPC_NODE_H_
22 changes: 22 additions & 0 deletions include/cloysterhpc/os.h → include/cloysterhpc/models/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <string>
#include <variant>


namespace cloyster::models {
/**
* @class OS
* @brief A class representing an Operating System (OS).
Expand Down Expand Up @@ -49,6 +51,12 @@ class OS {
*/
enum class Distro { RHEL, OL, Rocky, AlmaLinux };

/**
* @enum PackageManager
* @brief What
*/
enum class PackageType { RPM, DEB };

private:
std::variant<std::monostate, Arch> m_arch;
std::variant<std::monostate, Family> m_family;
Expand Down Expand Up @@ -124,6 +132,19 @@ class OS {

gsl::not_null<package_manager*> packageManager() const;

[[nodiscard]] constexpr PackageType getPackageType() const {
switch (getDistro()) {
case Distro::RHEL:
case Distro::OL:
case Distro::Rocky:
case Distro::AlmaLinux:
return PackageType::RPM;
default:
throw std::runtime_error("Unknonw distro type");
};
}


#ifndef NDEBUG
/**
* @brief Prints the data of the OS.
Expand All @@ -134,4 +155,5 @@ class OS {
#endif
};

}; // namespace cloyster::models
#endif // CLOYSTERHPC_OS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#ifndef CLOYSTERHPC_PBS_H_
#define CLOYSTERHPC_PBS_H_

#include <cloysterhpc/runner.h>
#include <cloysterhpc/queuesystem/queuesystem.h>
#include <cloysterhpc/services/runner.h>
#include <cloysterhpc/models/queuesystem.h>

namespace cloyster::models {

class PBS : public QueueSystem {
public:
Expand All @@ -24,4 +26,6 @@ class PBS : public QueueSystem {
explicit PBS(const Cluster& cluster);
};

};

#endif // CLOYSTERHPC_PBS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <cloysterhpc/functions.h>

// Forward declaration of Cluster
namespace cloyster::models {

class Cluster;

class QueueSystem {
Expand All @@ -36,4 +38,6 @@ class QueueSystem {
virtual ~QueueSystem() = default;
};

};

#endif // CLOYSTERHPC_QUEUESYSTEM_H_
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include <expected>
#include <fmt/format.h>
#include <list>
#include <regex>
#include <string>

#include <cloysterhpc/connection.h>
#include <cloysterhpc/cpu.h>
#include <cloysterhpc/os.h>
#include <cloysterhpc/models/cpu.h>
#include <cloysterhpc/models/os.h>
#include <cloysterhpc/services/bmc.h>

namespace cloyster::models {
/**
* @class Server
* @brief Represents a server in a cluster.
Expand Down Expand Up @@ -108,4 +108,6 @@ class Server {
Server() = default;
};

}; // namespace cloyster::models

#endif // CLOYSTERHPC_SERVER_H_
Loading

0 comments on commit 0487532

Please sign in to comment.