Skip to content

Commit

Permalink
Create NFS class, implement autofs (#16)
Browse files Browse the repository at this point in the history
* Implement new way to manage NFS and integrate autofs

Signed-off-by: lbgracioso <[email protected]>

* Remove updatenode from NFS.cpp

Signed-off-by: lbgracioso <[email protected]>

* Create IService, adapt NFS functions

Signed-off-by: lbgracioso <[email protected]>

* Small fixes and annotations on NFS.cpp

Added some FIXME info to provide a better implementation later on. But the idea is very good.

Signed-off-by: Vinícius Ferrão <[email protected]>

* Fixed on pure abstract classes, minor issues and code identation.

Signed-off-by: Vinícius Ferrão <[email protected]>

---------

Signed-off-by: lbgracioso <[email protected]>
Signed-off-by: Vinícius Ferrão <[email protected]>
Signed-off-by: Vinícius Ferrão <[email protected]>
Co-authored-by: Vinícius Ferrão <[email protected]>
  • Loading branch information
lbgracioso and viniciusferrao committed Jul 2, 2023
1 parent b4694f3 commit a3570f2
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 29 deletions.
62 changes: 62 additions & 0 deletions src/NFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2023 Vinícius Ferrão <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#include "NFS.h"
#include "const.h"
#include "functions.h"
#include <fmt/format.h>

using cloyster::runCommand;

NFS::NFS(const std::string& directoryName, const std::string& directoryPath,
const boost::asio::ip::address& address, const std::string& permissions)
: m_directoryName(directoryName)
, m_directoryPath(directoryPath)
, m_permissions(permissions)
, m_address(address)
{
setFullPath();
}

void NFS::setFullPath()
{
m_fullPath = fmt::format("{}/{}", m_directoryPath, m_directoryName);
}

void NFS::configure()
{
const std::string_view filename = CHROOT "/etc/exports";
cloyster::backupFile(filename);
cloyster::addStringToFile(filename,
// @TODO make fsid dynamic
fmt::format("/home *(rw,no_subtree_check,fsid=10,no_root_squash)\n"
"{} *({},fsid={})\n",
m_fullPath, m_permissions, 11));

runCommand("exportfs -a");

// @FIXME: Create a file using std::filesystem and not with touch
runCommand(fmt::format("touch {}/conf/node/etc/auto.master.d/{}.autofs",
installPath, m_directoryName));
cloyster::addStringToFile(
fmt::format("{}/conf/node/etc/auto.master.d/{}.autofs", installPath,
m_directoryName),
fmt::format("{} /etc/auto.{}", m_fullPath, m_directoryName));

// @FIXME: Create a file using std::filesystem and not with touch
runCommand(fmt::format(
"touch {}/conf/node/etc/auto.{}", installPath, m_directoryName));
cloyster::addStringToFile(
fmt::format("{}/conf/node/etc/auto.{}", installPath, m_directoryName),
fmt::format("* {}:{}/&", m_address.to_string(), m_fullPath));
}

void NFS::enable() { runCommand("systemctl enable nfs-server"); }

void NFS::disable() { runCommand("systemctl disable nfs-server"); }

void NFS::start() { runCommand("systemctl start nfs-server"); }

void NFS::stop() { runCommand("systemctl stop nfs-server"); }
36 changes: 36 additions & 0 deletions src/NFS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 Vinícius Ferrão <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef CLOYSTERHPC_NFS_H_
#define CLOYSTERHPC_NFS_H_

#include "services/IService.h"
#include <boost/asio.hpp>
#include <string>

class NFS : public IService {
private:
std::string m_directoryName;
std::string m_directoryPath;
std::string m_permissions;
std::string m_fullPath;
boost::asio::ip::address m_address;

public:
NFS(const std::string& directoryName, const std::string& directoryPath,
const boost::asio::ip::address& address,
const std::string& permissions);

void configure();
void enable() final;
void disable() final;
void start() final;
void stop() final;

private:
void setFullPath();
};

#endif // CLOYSTERHPC_NFS_H_
20 changes: 20 additions & 0 deletions src/services/IService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2023 Vinícius Ferrão <[email protected]>
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef CLOYSTERHPC_ISERVICE_H_
#define CLOYSTERHPC_ISERVICE_H_

class IService {
protected:
virtual void enable() = 0;
[[maybe_unused]] virtual void disable() = 0;
virtual void start() = 0;
[[maybe_unused]] virtual void stop() = 0;

public:
virtual ~IService() = default;
};

#endif // CLOYSTERHPC_ISERVICE_H_
31 changes: 13 additions & 18 deletions src/services/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <fmt/format.h>
#include <memory>

#include "../NFS.h"
#include "../cluster.h"
#include "../repos.h"

Expand All @@ -25,6 +26,8 @@ Shell::Shell(const std::unique_ptr<Cluster>& cluster)
// Initialize directory tree
cloyster::createDirectory(installPath);
cloyster::createDirectory(std::string { installPath } + "/backup");
cloyster::createDirectory(
std::string { installPath } + "/conf/node/etc/auto.master.d");
}

void Shell::disableSELinux()
Expand Down Expand Up @@ -179,7 +182,7 @@ void Shell::configureNetworks(const std::list<Connection>& connections)
std::vector<address> nameservers
= connection.getNetwork()->getNameservers();
std::vector<std::string> formattedNameservers;
for (int i = 0; i < nameservers.size(); i++) {
for (std::size_t i = 0; i < nameservers.size(); i++) {
formattedNameservers.emplace_back(nameservers[i].to_string());
}

Expand Down Expand Up @@ -303,22 +306,6 @@ void Shell::configureInfiniband()
}
}

/* TODO: Restrict by networks */
void Shell::configureNetworkFileSystem()
{
LOG_INFO("Setting up the Network File System");

std::string_view filename = CHROOT "/etc/exports";

cloyster::backupFile(filename);
cloyster::addStringToFile(filename,
"/home *(rw,no_subtree_check,fsid=10,no_root_squash)\n"
"/opt/ohpc/pub *(ro,no_subtree_check,fsid=11)\n");

runCommand("exportfs -a");
runCommand("systemctl enable --now nfs-server");
}

void Shell::removeMemlockLimits()
{
LOG_INFO("Removing memlock limits on headnode");
Expand Down Expand Up @@ -380,7 +367,15 @@ void Shell::install()
installOpenHPCBase();

configureInfiniband();
configureNetworkFileSystem();

NFS networkFileSystem = NFS("pub", "/opt/ohpc",
m_cluster->getHeadnode()
.getConnection(Network::Profile::Management)
.getAddress(),
"ro,no_subtree_check");
networkFileSystem.configure();
networkFileSystem.enable();
networkFileSystem.start();

configureQueueSystem();
removeMemlockLimits();
Expand Down
1 change: 0 additions & 1 deletion src/services/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class Shell : public Execution {
void configureTimeService(const std::list<Connection>&);
void configureQueueSystem();
void configureInfiniband();
void configureNetworkFileSystem();

void removeMemlockLimits();
void installDevelopmentComponents();
Expand Down
10 changes: 0 additions & 10 deletions src/services/xcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,6 @@ void XCAT::generatePostinstallFile()

cloyster::removeFile(filename);

m_stateless.postinstall.emplace_back(
fmt::format("cat << END >> $IMG_ROOTIMGDIR/etc/fstab\n"
"{0}:/home /home nfs nfsvers=3,nodev,nosuid 0 0\n"
"{0}:/opt/ohpc/pub /opt/ohpc/pub nfs nfsvers=3,nodev 0 0\n"
"END\n\n",
m_cluster->getHeadnode()
.getConnection(Network::Profile::Management)
.getAddress()
.to_string()));

m_stateless.postinstall.emplace_back(
"perl -pi -e 's/# End of file/\\* soft memlock unlimited\\n$&/s' "
"$IMG_ROOTIMGDIR/etc/security/limits.conf\n"
Expand Down

0 comments on commit a3570f2

Please sign in to comment.