#! /usr/bin/env python3 import os, sys, subprocess class nfs_server_conf: def __init__(self, nfs_srv_folders = ["/nfsroot/publicnfs","/nfsroot/datennfs"]) -> None: if not os.geteuid()==0: raise PermissionError("Sie sind kein Root") self.nfs_srv_folders = nfs_srv_folders def mount_serverfolder(self): for srv_folder in self.nfs_srv_folders: unit_mount_file = "/etc/systemd/system/" + os.path.basename(srv_folder) + ".mount" mountfile = os.path.basename(unit_mount_file) #mount Verzeichnis anlegen if os.path.exists(srv_folder): print("Das Verzeichnis", srv_folder,"ist bereits vorhanden !") else: os.makedirs(srv_folder, mode=1777) if os.path.exists(unit_mount_file) is True: print("Die Unit", unit_mount_file, "existiert bereits !", sep=" ") else: with open(unit_mount_file, "w") as unit_file: print("""[Unit]\nDescription=Mount nfs Server Share\n[Mount]\nWhat={srv_folder}\nWhere={srv_point}\nType=None\nOptions=bind\n[Install]\nWantedBy=multi-user.target""".format( srv_folder=srv_folder, srv_point="/" + os.path.basename(srv_folder)), file=unit_file) if subprocess.run(['systemctl', 'daemon-reload']) .returncode == 0: print("Systemed daemon-reload wurde ausgeführt") else: raise "Reloade konnte nicht ausgeführt werden." #Starte UnitFile if subprocess.run(['systemctl', 'start', mountfile]).returncode == 0: print(mountfile, "wurde gestartet !", sep=" ") else: raise "Service" + mountfile +" konnte nicht gestart werden" def nfs_server_conf(self): with open("/etc/exports",'r') as exportfs_file: for exportfs_line in map(str(exportfs_file.readlines()).rstrip("\n")): print(exportfs_line) #print(exportfs_line.rstrip("\n"), sep="") def nfs_con_user(self): pass def start_nfs_server(self): pass def main(self): nfs_server_conf.mount_serverfolder(self) nfs_server_conf.nfs_server_conf(self) def __str__(self) -> str: pass if __name__ == "__main__": my_nfs_server = nfs_server_conf() my_nfs_server.main()