Pure python NFS client
Project description
Introduction
pyNfsClient 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 using Python, supports both Python 2.7 and Python 3.
pyNfsClient project is hosted on GitHub where you can find source code, an issue tracker, and some further documentation.
Installation
If you already have Python with pip installed, you can simply run:
pip install pyNfsClient
Alternatively you can get source code by downloading the source distribution from PyPI and extracting it, or by cloning the project repository from GitHub. After that you can install the framework with:
python setup.py install
Example
Below is a simple example which lookup a file and then do several operations on it.
from pyNfsClient import (Portmap, Mount, NFSv3, MNT3_OK, NFS_PROGRAM,
NFS_V3, NFS3_OK, DATA_SYNC)
# variable preparation
host = "192.221.4.119"
mount_path = "/nfsshare"
auth = {"flavor": 1,
"machine_name": "host1",
"uid": 0,
"gid": 0,
"aux_gid": list(),
}
# portmap initialization
portmap = Portmap(host, timeout=3600)
portmap.connect()
# mount initialization
mnt_port = portmap.getport(Mount.program, Mount.program_version)
mount = Mount(host=host, port=mnt_port, timeout=3600)
mount.connect()
# do mount
mnt_res =mount.mnt(mount_path, auth)
if mnt_res["status"] == MNT3_OK:
root_fh =mnt_res["mountinfo"]["fhandle"]
try:
nfs_port =portmap.getport(NFS_PROGRAM, NFS_V3)
# nfs actions
nfs3 =NFSv3(host, nfs_port, 3600)
nfs3.connect()
lookup_res = nfs3.lookup(root_fh, "file.txt", auth)
if lookup_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)
if write_res["status"] == NFS3_OK:
read_res = nfs3.read(fh, offset=0, auth=auth)
if read_res["status"] == NFS3_OK:
read_content = str(read_res["resok"]["data"], encoding="utf-8")
assert read_content.startswith("Sample text")
else:
print("write failed")
else:
print("Lookup failed")
finally:
if nfs3:
nfs3.disconnect()
mount.umnt(mount_path, auth)
mount.disconnect()
portmap.disconnect()
else:
mount.disconnect()
portmap.disconnect()
License
The MIT License (MIT)
Copyright (c) 2019 Cooper Yang
Permission 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyNfsClient-0.1.5.tar.gz
.
File metadata
- Download URL: pyNfsClient-0.1.5.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6064bd3c365302a529002d0c24961ed7ab5e9b2b64a6da10329dbac85ac81a5 |
|
MD5 | b5d6afd78c3b52d500b9bb476de88ab7 |
|
BLAKE2b-256 | f530b45e9edad9507dcd88545688067fd8a51ab819ba11d934b9b218e5af68b7 |
File details
Details for the file pyNfsClient-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: pyNfsClient-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 37.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d988029d0b86ae2897bfb17162e47a81943a72508ccb37566ef23615c533cc59 |
|
MD5 | d99276b56bc8c159748df96fb3bd92d0 |
|
BLAKE2b-256 | d02b50136d18595dc478eb5e9418a1021d590a034fd3ac19f523eadc371d0270 |