commit message from python script

This commit is contained in:
2023-10-09 09:49:50 +02:00
parent 107b50a3ad
commit 9e20352d7f

View File

@@ -9,7 +9,9 @@ class nfs_server_conf:
self.nfs_srv_folders = nfs_srv_folders self.nfs_srv_folders = nfs_srv_folders
self.nfs_config_file = nfs_config_file self.nfs_config_file = nfs_config_file
self.allow_network = allow_network self.allow_network = allow_network
def mount_serverfolder(self): def mount_serverfolder(self):
list_mountfiles = []
for srv_folder in self.nfs_srv_folders: for srv_folder in self.nfs_srv_folders:
unit_mount_file = "/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount" unit_mount_file = "/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount"
mountfile = os.path.basename(unit_mount_file) mountfile = os.path.basename(unit_mount_file)
@@ -30,12 +32,13 @@ class nfs_server_conf:
print("Systemed daemon-reload wurde ausgeführt") print("Systemed daemon-reload wurde ausgeführt")
else: else:
raise "Reloade konnte nicht ausgeführt werden." raise "Reloade konnte nicht ausgeführt werden."
#Starte UnitFile #Starte UnitFile
list_mountfiles.append(mountfile)
if subprocess.run(['systemctl', 'start', mountfile]).returncode == 0: if subprocess.run(['systemctl', 'start', mountfile]).returncode == 0:
print(mountfile, "wurde gestartet !", sep=" ") print(mountfile, "wurde gestartet !", sep=" ")
else: else:
raise "Service" + mountfile +" konnte nicht gestart werden" raise "Service" + mountfile +" konnte nicht gestart werden"
return list_mountfiles
def nfs_server_conf(self): def nfs_server_conf(self):
folder_count = [] folder_count = []
@@ -54,7 +57,9 @@ class nfs_server_conf:
if folder_counting["count_exist"] > 0: if folder_counting["count_exist"] > 0:
print(folder_counting["folder_name"], "ist vorhanden in", self.nfs_config_file ) print(folder_counting["folder_name"], "ist vorhanden in", self.nfs_config_file )
else: else:
os.path.abspath(folder_counting["folder_name"])
with open(self.nfs_config_file, 'a') as add_exportfile: with open(self.nfs_config_file, 'a') as add_exportfile:
print(os.path.dirname(folder_counting["folder_name"]), self.allow_network + "(rw,sync,insecure,root_squash,no_subtree_check,fsid=0)", file=add_exportfile)
print(folder_counting["folder_name"], self.allow_network + "(rw,sync,insecure,root_squash,no_subtree_check)", file=add_exportfile) print(folder_counting["folder_name"], self.allow_network + "(rw,sync,insecure,root_squash,no_subtree_check)", file=add_exportfile)
print(folder_counting["folder_name"], "ist NICHT vorhanden in", self.nfs_config_file ) print(folder_counting["folder_name"], "ist NICHT vorhanden in", self.nfs_config_file )
@@ -62,15 +67,23 @@ class nfs_server_conf:
pass pass
def start_nfs_server(self): def start_nfs_server(self):
pass unitname_nfsv4 = "nfsv4-server.service"
if subprocess.run(['systemctl', 'start', unitname_nfsv4]).returncode == 0:
print(unitname_nfsv4, "wurde gestartet !", sep=" ")
return True
else:
raise "Service" + unitname_nfsv4 +" konnte nicht gestart werden"
def main(self):
def main_install(self):
nfs_server_conf.mount_serverfolder(self) nfs_server_conf.mount_serverfolder(self)
nfs_server_conf.nfs_server_conf(self) nfs_server_conf.nfs_server_conf(self)
nfs_server_conf.start_nfs_server(self)
def __str__(self) -> str: def __str__(self) -> str:
pass pass
if __name__ == "__main__": if __name__ == "__main__":
my_nfs_server = nfs_server_conf() my_nfs_server = nfs_server_conf(allow_network="192.168.150.0/24")
my_nfs_server.main() my_nfs_server.main_install()