2525#include < cloysterhpc/dbus_client.h>
2626#include < ranges>
2727
28+ using cloyster::getClusterSingleton;
2829using cloyster::OS;
2930using cloyster::runCommand;
31+ using cloyster::models::Cluster;
3032
3133namespace {
3234
@@ -49,12 +51,12 @@ auto getToEnableRepoNames(const OS& osinfo)
4951 }
5052}
5153
54+ Cluster& cluster () { return getClusterSingleton (); }
5255}
5356
5457namespace cloyster ::services {
5558
56- Shell::Shell (std::unique_ptr<Cluster> cluster)
57- : m_cluster(std::move(cluster))
59+ Shell::Shell ()
5860{
5961 // Initialize directory tree
6062 cloyster::createDirectory (installPath);
@@ -79,7 +81,7 @@ void Shell::configureSELinuxMode()
7981{
8082 LOG_INFO (" Setting up SELinux" )
8183
82- switch (m_cluster-> getSELinux ()) {
84+ switch (cluster (). getSELinux ()) {
8385 case Cluster::SELinuxMode::Permissive:
8486 runCommand (" setenforce 0" );
8587 /* Permissive mode */
@@ -104,22 +106,22 @@ void Shell::configureFirewall()
104106{
105107 LOG_INFO (" Setting up firewall" )
106108
107- if (m_cluster-> isFirewall ()) {
109+ if (cluster (). isFirewall ()) {
108110 runCommand (" systemctl enable --now firewalld" );
109111
110112 // Add the management interface as trusted
111113 runCommand (fmt::format (
112114 " firewall-cmd --permanent --zone=trusted --change-interface={}" ,
113- m_cluster-> getHeadnode ()
115+ cluster (). getHeadnode ()
114116 .getConnection (Network::Profile::Management)
115117 .getInterface ()
116118 .value ()));
117119
118120 // If we have IB, also add its interface as trusted
119- if (m_cluster-> getOFED ())
121+ if (cluster (). getOFED ())
120122 runCommand (fmt::format (
121123 " firewall-cmd --permanent --zone=trusted --change-interface={}" ,
122- m_cluster-> getHeadnode ()
124+ cluster (). getHeadnode ()
123125 .getConnection (Network::Profile::Application)
124126 .getInterface ()
125127 .value ()));
@@ -137,15 +139,15 @@ void Shell::configureFQDN()
137139 LOG_INFO (" Setting up hostname" )
138140
139141 runCommand (fmt::format (
140- " hostnamectl set-hostname {}" , m_cluster-> getHeadnode ().getFQDN ()));
142+ " hostnamectl set-hostname {}" , cluster (). getHeadnode ().getFQDN ()));
141143}
142144
143145// TODO: Proper file parsing
144146void Shell::configureHostsFile ()
145147{
146148 LOG_INFO (" Setting up additional entries on hosts file" )
147149
148- const auto & headnode = m_cluster-> getHeadnode ();
150+ const auto & headnode = cluster (). getHeadnode ();
149151
150152 const auto & ip = headnode.getConnection (Network::Profile::Management)
151153 .getAddress ()
@@ -165,15 +167,15 @@ void Shell::configureTimezone()
165167 LOG_INFO (" Setting up timezone" )
166168
167169 runCommand (fmt::format (
168- " timedatectl set-timezone {}" , m_cluster-> getTimezone ().getTimezone ()));
170+ " timedatectl set-timezone {}" , cluster (). getTimezone ().getTimezone ()));
169171}
170172
171173void Shell::configureLocale ()
172174{
173175 LOG_INFO (" Setting up locale" )
174176
175177 runCommand (fmt::format (
176- " localectl set-locale {}" , m_cluster-> getLocale ().getLocale ()));
178+ " localectl set-locale {}" , cluster (). getLocale ().getLocale ()));
177179}
178180
179181void Shell::disableNetworkManagerDNSOverride ()
@@ -271,7 +273,7 @@ void Shell::configureNetworks(const std::list<Connection>& connections)
271273
272274void Shell::runSystemUpdate ()
273275{
274- if (m_cluster-> isUpdateSystem ()) {
276+ if (cluster (). isUpdateSystem ()) {
275277 LOG_INFO (" Checking if system updates are available" )
276278 runCommand (" dnf -y update" );
277279 }
@@ -339,7 +341,7 @@ void Shell::configureQueueSystem()
339341{
340342 LOG_INFO (" Setting up the queue system" )
341343
342- if (const auto & queue = m_cluster-> getQueueSystem ()) {
344+ if (const auto & queue = cluster (). getQueueSystem ()) {
343345 switch (queue.value ()->getKind ()) {
344346 case QueueSystem::Kind::None: {
345347 __builtin_unreachable ();
@@ -375,14 +377,14 @@ void Shell::configureMailSystem()
375377{
376378 LOG_INFO (" Setting up the mail system" );
377379
378- m_cluster-> getMailSystem ()->setup ();
380+ cluster (). getMailSystem ()->setup ();
379381}
380382
381383void Shell::configureInfiniband ()
382384{
383- const auto & osinfo = m_cluster-> getHeadnode ().getOS ();
385+ const auto & osinfo = cluster (). getHeadnode ().getOS ();
384386 auto repos = cloyster::getRepoManager (osinfo);
385- if (const auto & ofed = m_cluster-> getOFED ()) {
387+ if (const auto & ofed = cluster (). getOFED ()) {
386388 LOG_INFO (" Setting up Infiniband support" )
387389 ofed->install (*repos); // shared pointer
388390 }
@@ -421,7 +423,7 @@ void Shell::installDevelopmentComponents()
421423
422424void Shell::configureRepositories ()
423425{
424- const auto & osinfo = m_cluster-> getHeadnode ().getOS ();
426+ const auto & osinfo = cluster (). getHeadnode ().getOS ();
425427 auto repos = cloyster::getRepoManager (osinfo);
426428 // 1. Install files into /etc, these files are the templates
427429 // at include/cloysterhpc/repos/el*/*.repo
@@ -437,7 +439,7 @@ void Shell::configureRepositories()
437439 */
438440void Shell::install ()
439441{
440- auto systemdBus = m_cluster-> getDaemonBus ();
442+ auto systemdBus = cluster (). getDaemonBus ();
441443
442444 configureSELinuxMode ();
443445 configureFirewall ();
@@ -448,17 +450,17 @@ void Shell::install()
448450 configureTimezone ();
449451 configureLocale ();
450452
451- configureNetworks (m_cluster-> getHeadnode ().getConnections ());
453+ configureNetworks (cluster (). getHeadnode ().getConnections ());
452454 runSystemUpdate ();
453- configureTimeService (m_cluster-> getHeadnode ().getConnections ());
455+ configureTimeService (cluster (). getHeadnode ().getConnections ());
454456 installRequiredPackages ();
455457 configureRepositories ();
456458 installOpenHPCBase ();
457459 configureInfiniband ();
458460
459461 // BUG: Broken. Compute nodes does not mount anything.
460462 NFS networkFileSystem = NFS (systemdBus, " pub" , " /opt/ohpc" ,
461- m_cluster-> getHeadnode ()
463+ cluster (). getHeadnode ()
462464 .getConnection (Network::Profile::Management)
463465 .getAddress (),
464466 " ro,no_subtree_check" );
@@ -467,21 +469,22 @@ void Shell::install()
467469 networkFileSystem.start ();
468470
469471 configureQueueSystem ();
470- if (m_cluster-> getMailSystem ().has_value ())
472+ if (cluster (). getMailSystem ().has_value ()) {
471473 configureMailSystem ();
474+ }
472475 removeMemlockLimits ();
473476
474477 installDevelopmentComponents ();
475478
476479 const auto & provisionerName { magic_enum::enum_name (
477- m_cluster-> getProvisioner ()) };
480+ cluster (). getProvisioner ()) };
478481
479482 LOG_DEBUG (" Setting up the provisioner: {}" , provisionerName)
480483 // std::unique_ptr<Provisioner> provisioner;
481484 std::unique_ptr<XCAT> provisioner;
482- switch (m_cluster-> getProvisioner ()) {
485+ switch (cluster (). getProvisioner ()) {
483486 case Cluster::Provisioner::xCAT:
484- provisioner = std::make_unique<XCAT>(m_cluster );
487+ provisioner = std::make_unique<XCAT>();
485488 break ;
486489 }
487490
0 commit comments