Example #1
0
 def share(self, dst_image_dir, hard=True):
     """
     Share this volume to dst_image_dir
     'hard' - link type: file volumes should use hardlinks (default behaviour)
                         block volumes should use softlinks (explicitly hard=False)
     """
     self.log.debug("Volume.share)share  %s to %s hard %s" % (self.volUUID, dst_image_dir, hard))
     if not self.isShared():
         raise se.VolumeNonShareable(self)
     if os.path.basename(dst_image_dir) == os.path.basename(self.imagePath):
         raise se.VolumeOwnershipError(self)
     try:
         src = self.getDevPath()
         dst = os.path.join(dst_image_dir, self.volUUID)
         taskName = "share volume rollback: " + dst
         vars.task.pushRecovery(task.Recovery(taskName, "volume", "Volume", "shareVolumeRollback",
                                              [dst]))
         if os.path.lexists(dst):
             os.unlink(dst)
         if hard:
             os.link(src, dst)
         else:
             os.symlink(src, dst)
     except Exception, e:
         raise se.CannotShareVolume(src, dst, str(e))
Example #2
0
    def share(self, dstImgPath):
        """
        Share this volume to dstImgPath
        """
        self.log.debug("Share volume %s to %s", self.volUUID, dstImgPath)

        if not self.isShared():
            raise se.VolumeNonShareable(self)

        if os.path.basename(dstImgPath) == os.path.basename(self.imagePath):
            raise se.VolumeOwnershipError(self)

        dstPath = os.path.join(dstImgPath, self.volUUID)
        clsModule, clsName = self._getModuleAndClass()

        try:
            vars.task.pushRecovery(
                task.Recovery("Share volume rollback: %s" % dstPath, clsModule,
                              clsName, "shareVolumeRollback", [dstPath])
            )

            self._share(dstImgPath)

        except Exception as e:
            raise se.CannotShareVolume(self.getVolumePath(), dstPath, str(e))