class ShowExports(): def __init__(self, parent=None): self.exportmgr = ExportMgr(SERVICE, '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr') def showexports(self): print "Show exports" status, msg, reply = self.exportmgr.ShowExports() if status == True: ts = reply[0] exports = reply[1] self.proc_exports(ts, exports) else: self.status_message(status, msg) def addexport(self, conf_path, exp_expr): print "Add Export in %s" % conf_path status, msg = self.exportmgr.AddExport(conf_path, exp_expr) self.status_message(status, msg) def removeexport(self, exp_id): print "Remove Export with id %d" % int(exp_id) self.exportmgr.RemoveExport(exp_id) def displayexport(self, exp_id): print "Display export with id %d" % int(exp_id) status, msg, reply = self.exportmgr.DisplayExport(exp_id) if status == True: id = reply[0] path = reply[1] pseudo = reply[2] tag = reply[3] self.proc_export(id, path, pseudo, tag) else: self.status_message(status, msg) def proc_export(self, id, path, pseudo, tag): print "export %d: path = %s, pseudo = %s, tag = %s" % (id, path, pseudo, tag) def proc_exports(self, ts, exports): print "Timestamp: ", time.ctime(ts[0]), ts[1], " nsecs" if len(exports) == 0: print "No exports" else: print "Exports:" print " Id, path, nfsv3, mnt, nlm4, rquota,nfsv40, nfsv41, nfsv42, 9p, last" for export in exports: print( " %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d nsecs" % (export.ExportID, export.ExportPath, export.HasNFSv3, export.HasMNT, export.HasNLM4, export.HasRQUOTA, export.HasNFSv40, export.HasNFSv41, export.HasNFSv42, export.Has9P, time.ctime( export.LastTime[0]), export.LastTime[1])) def status_message(self, status, errormsg): print "Returns: status = %s, %s" % (str(status), errormsg)
def get_exports_info(): """ Returns the status info of each export exported by NFS-ganesha """ caller = SaltClient.Caller() if not caller.cmd('service.status', 'nfs-ganesha'): return { 'success': False, 'message': 'nfs-ganesha service is not running' } if not ExportMgr: return { 'success': False, 'message': 'nfs-ganesha utils scripts are not installed' } mgr = ExportMgr('org.ganesha.nfsd', '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr') status, msg, reply = mgr.ShowExports() if not status: return {'success': False, 'message': msg} exports = [] for export in reply[1]: status2, msg2, reply2 = mgr.DisplayExport(export.ExportID) if not status2: exports.append({ 'export_id': export.ExportID, 'path': export.ExportPath, 'active': False, 'message': msg2 }) continue exports.append({ 'export_id': export.ExportID, 'path': reply2[1], 'pseudo': reply2[2], 'tag': reply2[3], 'active': True }) return {'success': True, 'exports': exports}
def del_conf(abs_conf_path, params_list): export_set = set() _exec = "cat %s | grep Path" % (CONF_PATH) try: result, err = exec_shell(_exec, p=True, need_return=True, timeout=60) except Exception as e: raise Exp(e.errno, str(e)) with open(abs_conf_path, 'r') as fp: content = fp.read() #去重 for export in params_list: export_path_uss = export.keys()[0].strip(' ') export_set.add(export_path_uss) path_list = result.split('\n') for l_path in path_list: path = l_path.split('=') if len(path) == 2: export_path_conf = path[1].split(';')[0].strip(' ') export_id = get_export_id_by_path(content, export_path_conf) # 判断配置文件中的path是否share中也存在 if export_path_conf not in export_set: delete_export_by_id(content, export_id) exportmgr = ExportMgr(SERVICE, '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr') status, msg = exportmgr.RemoveExport(export_id) status_message(status, msg) continue # 判断配置文件中的client是否share中也存在 share_clients = get_clients_from_share(params_list, export_path_conf) conf_clients = get_clients_by_path(content, export_path_conf) for c_client in conf_clients: c_Cli = c_client.strip(' ') if c_Cli not in share_clients: delete_client_by_host(content, export_id, c_Cli) exportmgr = ExportMgr(SERVICE, '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr') export_expression = build_expression(export_id) status, msg = exportmgr.UpdateExport( abs_conf_path, export_expression) status_message(status, msg)
def __init__(self, parent=None): self.exportmgr = ExportMgr(SERVICE, '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr')
class ShowExports(): def __init__(self, parent=None): self.exportmgr = ExportMgr(SERVICE, '/org/ganesha/nfsd/ExportMgr', 'org.ganesha.nfsd.exportmgr') def showexports(self): print("Show exports") status, msg, reply = self.exportmgr.ShowExports() if status == True: _ts = reply[0] exports = reply[1] self.proc_exports(_ts, exports) else: self.status_message(status, msg) def addexport(self, conf_path, exp_expr): print("Add Export in %s" % conf_path) status, msg = self.exportmgr.AddExport(conf_path, exp_expr) self.status_message(status, msg) def removeexport(self, exp_id): print("Remove Export with id %d" % int(exp_id)) self.exportmgr.RemoveExport(exp_id) def updateexport(self, conf_path, exp_expr): print("Update Export in %s" % conf_path) status, msg = self.exportmgr.UpdateExport(conf_path, exp_expr) self.status_message(status, msg) def displayexport(self, exp_id): print("Display export with id %d" % int(exp_id)) status, msg, reply = self.exportmgr.DisplayExport(exp_id) if status == True: _id = reply[0] path = reply[1] pseudo = reply[2] tag = reply[3] clients = reply[4] self.proc_export(_id, path, pseudo, tag, clients) else: self.status_message(status, msg) def proc_export(self, _id, path, pseudo, tag, clients): print("export %d: path = %s, pseudo = %s, tag = %s" %\ (_id, path, pseudo, tag)) print(" Client type, CIDR version, CIDR address, CIDR mask, " +\ "CIDR proto, Anonymous UID, Anonymous GID, " +\ "Attribute timeout, Options, Set") for client in clients: print(" %s, %d, %d, %d, %d, %d, %d, %d, %d, %d" % (client.Client_type, client.CIDR_version, client.CIDR_address, client.CIDR_mask, client.CIDR_proto, client.Anonymous_uid, client.Anonymous_gid, client.Expire_time_attr, client.Options, client.Set)) def proc_exports(self, _ts, exports): print("Timestamp: ", time.ctime(_ts[0]), _ts[1], " nsecs") if len(exports) == 0: print("No exports") else: print("Exports:") print( " Id, path, nfsv3, mnt, nlm4, rquota,nfsv40, nfsv41, nfsv42, 9p, last" ) for export in exports: print( " %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d nsecs" % (export.ExportID, export.ExportPath, export.HasNFSv3, export.HasMNT, export.HasNLM4, export.HasRQUOTA, export.HasNFSv40, export.HasNFSv41, export.HasNFSv42, export.Has9P, time.ctime( export.LastTime[0]), export.LastTime[1])) def status_message(self, status, errormsg): print("Returns: status = %s, %s" % (str(status), errormsg))