summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gluster/gfapi/api.py5
-rw-r--r--gluster/gfapi/gfapi.py19
-rw-r--r--test/functional/libgfapi-python-tests.py15
3 files changed, 39 insertions, 0 deletions
diff --git a/gluster/gfapi/api.py b/gluster/gfapi/api.py
index c440de6..971e98c 100644
--- a/gluster/gfapi/api.py
+++ b/gluster/gfapi/api.py
@@ -510,3 +510,8 @@ glfs_utimens = gfapi_prototype('glfs_utimens', ctypes.c_int,
ctypes.c_void_p,
ctypes.c_char_p,
ctypes.POINTER(Timespec))
+
+glfs_get_volumeid = gfapi_prototype('glfs_get_volumeid', ctypes.c_int,
+ ctypes.c_void_p,
+ ctypes.c_char_p,
+ ctypes.c_size_t)
diff --git a/gluster/gfapi/gfapi.py b/gluster/gfapi/gfapi.py
index d48aa06..c01d534 100644
--- a/gluster/gfapi/gfapi.py
+++ b/gluster/gfapi/gfapi.py
@@ -14,6 +14,7 @@ import math
import time
import stat
import errno
+import uuid
from collections import Iterator
from gluster.gfapi import api
@@ -666,6 +667,7 @@ class Volume(object):
self.host = host
self.volname = volname
+ self.volid = None
self.protocol = proto
self.port = port
@@ -770,6 +772,23 @@ class Volume(object):
self.log_level = log_level
@validate_mount
+ def get_volume_id(self):
+ """
+ Returns the volume ID (of type uuid.UUID) for the currently mounted
+ volume.
+ """
+ if self.volid != None:
+ return self.volid
+ size = 16
+ buf = ctypes.create_string_buffer(size)
+ ret = api.glfs_get_volumeid(self.fs, buf, size)
+ if ret < 0:
+ err = ctypes.get_errno()
+ raise OSError(err, os.strerror(err))
+ self.volid = uuid.UUID(bytes=buf.raw)
+ return self.volid
+
+ @validate_mount
def access(self, path, mode):
"""
Use the real uid/gid to test for access to path.
diff --git a/test/functional/libgfapi-python-tests.py b/test/functional/libgfapi-python-tests.py
index c209302..58bda89 100644
--- a/test/functional/libgfapi-python-tests.py
+++ b/test/functional/libgfapi-python-tests.py
@@ -15,6 +15,7 @@ import types
import errno
import hashlib
import threading
+import uuid
from test import get_test_config
from ConfigParser import NoSectionError, NoOptionError
from uuid import uuid4
@@ -1159,3 +1160,17 @@ class TestVolumeInit(unittest.TestCase):
self.assertTrue(vol.mounted)
vol.umount()
self.assertFalse(vol.mounted)
+
+ def test_get_volume_id(self):
+ vol = Volume(HOST, VOLNAME)
+ vol.mount()
+ self.assertTrue(vol.mounted)
+ self.assertTrue(vol.volid == None)
+ volid = vol.get_volume_id()
+ self.assertTrue(volid != None)
+ try:
+ volid = uuid.UUID(str(volid))
+ except ValueError:
+ self.fail("Invalid UUID")
+ self.assertTrue(vol.volid != None)
+ vol.umount()