Exemple #1
0
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)
Exemple #2
0
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}
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))