diff options
author | Prashanth Pai <ppai@redhat.com> | 2016-08-10 15:28:48 +0530 |
---|---|---|
committer | Prashanth Pai <ppai@redhat.com> | 2016-08-10 18:20:57 +0530 |
commit | 655b0d2793386d2059b9c682e931035a83619917 (patch) | |
tree | c1dfcc19202af123b649767c6a0bb5c4b340bd63 /gluster/gfapi/utils.py | |
parent | d4b8804abb876bda9803cee61c6c4298b475e6be (diff) |
Move source files into gfapi/ dir
Currently, many source files are directly placed under gluster/ dir:
gluster/exceptions.py
gluster/gfapi.py
gluster/utils.py
When multiple packages (RPMs) are sharing the same gluster namespace,
these source files will conflict if there are source files with same
names provided by other projects.
Fix: Move all source files in gluster/* to gluster/gfapi/*
Note that this patch does not break how existing users import gfapi.
Change-Id: Idf9d07eefafe8333215d6c61201c97c982565ba9
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Diffstat (limited to 'gluster/gfapi/utils.py')
-rw-r--r-- | gluster/gfapi/utils.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/gluster/gfapi/utils.py b/gluster/gfapi/utils.py new file mode 100644 index 0000000..a556a41 --- /dev/null +++ b/gluster/gfapi/utils.py @@ -0,0 +1,57 @@ +# Copyright (c) 2016 Red Hat, Inc. +# +# This file is part of libgfapi-python project which is a +# subproject of GlusterFS ( www.gluster.org) +# +# This file is licensed to you under your choice of the GNU Lesser +# General Public License, version 3 or any later version (LGPLv3 or +# later), or the GNU General Public License, version 2 (GPLv2), in all +# cases as published by the Free Software Foundation. + +import os +import errno +from functools import wraps +from gluster.gfapi.exceptions import VolumeNotMounted + + +def validate_mount(func): + """ + Decorator to assert that volume is initialized and mounted before any + further I/O calls are invoked by methods. + + :param func: method to be decorated and checked. + """ + def _exception(volname): + raise VolumeNotMounted('Volume "%s" not mounted.' % (volname)) + + @wraps(func) + def wrapper(*args, **kwargs): + self = args[0] + if self.fs and self._mounted: + return func(*args, **kwargs) + else: + return _exception(self.volname) + wrapper.__wrapped__ = func + + return wrapper + + +def validate_glfd(func): + """ + Decorator to assert that glfd is valid. + + :param func: method to be decorated and checked. + """ + def _exception(): + raise OSError(errno.EBADF, os.strerror(errno.EBADF)) + + @wraps(func) + def wrapper(*args, **kwargs): + self = args[0] + if self.fd: + return func(*args, **kwargs) + else: + return _exception() + wrapper.__wrapped__ = func + + return wrapper |