New method GetUserspaceAccessURI in storage class
authorRaffa Santi <rsanti@google.com>
Wed, 2 Oct 2013 09:02:32 +0000 (11:02 +0200)
committerThomas Thrainer <thomasth@google.com>
Wed, 2 Oct 2013 14:55:25 +0000 (16:55 +0200)
Returns a hypervisor specific URI for RBD template when userspace
access is requested.

Signed-off-by: Santi Raffa <rsanti@google.com>
Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Thomas Thrainer <thomasth@google.com>

lib/storage/base.py
lib/storage/bdev.py

index 3f244e5..ee8c0c6 100644 (file)
@@ -359,6 +359,18 @@ class BlockDev(object):
     """
     return (self.GetActualSize(), self.GetActualSpindles())
 
+  def GetUserspaceAccessUri(self, hypervisor):
+    """Return URIs hypervisors can use to access disks in userspace mode.
+
+    @rtype: string
+    @return: userspace device URI
+    @raise errors.BlockDeviceError if userspace access is not supported
+
+    """
+    ThrowError("Userspace access with %s block device and %s hypervisor is not "
+               "supported." % (self.__class__.__name__,
+                               hypervisor))
+
   def __repr__(self):
     return ("<%s: unique_id: %s, children: %s, %s:%s, %s>" %
             (self.__class__, self.unique_id, self._children,
index e3ffae8..c7a7417 100644 (file)
@@ -1006,6 +1006,7 @@ class RADOSBlockDevice(base.BlockDev):
       raise ValueError("Invalid configuration data %s" % str(unique_id))
 
     self.driver, self.rbd_name = unique_id
+    self.rbd_pool = params[constants.LDP_POOL]
 
     self.major = self.minor = None
     self.Attach()
@@ -1343,6 +1344,18 @@ class RADOSBlockDevice(base.BlockDev):
       base.ThrowError("rbd resize failed (%s): %s",
                       result.fail_reason, result.output)
 
+  def GetUserspaceAccessUri(self, hypervisor):
+    """Generate KVM userspace URIs to be used as `-drive file` settings.
+
+    @see: L{BlockDev.GetUserspaceAccessUri}
+
+    """
+    if hypervisor == constants.HT_KVM:
+      return "rbd:" + self.rbd_pool + "/" + self.rbd_name
+    else:
+      base.ThrowError("Hypervisor %s doesn't support RBD userspace access" %
+                      hypervisor)
+
 
 class ExtStorageDevice(base.BlockDev):
   """A block device provided by an ExtStorage Provider.