Package: pyNfsClient
IntroductionInstallationExampleLicenseIntroductionpyNfsClient is a generic open source toolkit for Linux NFS file system simulation as client.
Constructed parameters sent via RPC and then analyse the response in reference to NFS protocol specifications (RFC1813).
You could form your custom scenarios that consist of basic actions to meet expecations.Currently only NFS v3 supported, NFS v4.1 is under development.pyNfsClient is operating system and application independent. The toolkit is implemented usingPython, supports both
Python 2.7 and Python 3.pyNfsClient project is hosted onGitHubwhere you can find source code,
an issue tracker, and some further documentation.InstallationIf you already havePythonwithpipinstalled,
you can simply run:pip install pyNfsClientAlternatively you can get source code by downloading the source
distribution fromPyPIand extracting it, or by cloning the project repository
fromGitHub. After that you can install the framework with:python setup.py installExampleBelow is a simple example which lookup a file and then do several operations on it.frompyNfsClientimport(Portmap,Mount,NFSv3,MNT3_OK,NFS_PROGRAM,NFS_V3,NFS3_OK,DATA_SYNC)# variable preparationhost="192.221.4.119"mount_path="/nfsshare"auth={"flavor":1,"machine_name":"host1","uid":0,"gid":0,"aux_gid":list(),}# portmap initializationportmap=Portmap(host,timeout=3600)portmap.connect()# mount initializationmnt_port=portmap.getport(Mount.program,Mount.program_version)mount=Mount(host=host,port=mnt_port,timeout=3600)mount.connect()# do mountmnt_res=mount.mnt(mount_path,auth)ifmnt_res["status"]==MNT3_OK:root_fh=mnt_res["mountinfo"]["fhandle"]try:nfs_port=portmap.getport(NFS_PROGRAM,NFS_V3)# nfs actionsnfs3=NFSv3(host,nfs_port,3600)nfs3.connect()lookup_res=nfs3.lookup(root_fh,"file.txt",auth)iflookup_res["status"]==NFS3_OK:fh=lookup_res["resok"]["object"]["data"]write_res=nfs3.write(fh,offset=0,count=11,content="Sample text",stable_how=DATA_SYNC,auth=auth)ifwrite_res["status"]==NFS3_OK:read_res=nfs3.read(fh,offset=0,auth=auth)ifread_res["status"]==NFS3_OK:read_content=str(read_res["resok"]["data"],encoding="utf-8")assertread_content.startswith("Sample text")else:print("write failed")else:print("Lookup failed")finally:ifnfs3:nfs3.disconnect()mount.umnt(mount_path,auth)mount.disconnect()portmap.disconnect()else:mount.disconnect()portmap.disconnect()LicenseThe MIT License (MIT)Copyright (c) 2019Cooper YangPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.