-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create NFS class, implement autofs (#16)
* 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
1 parent
b4694f3
commit a3570f2
Showing
6 changed files
with
131 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters