Exemplo n.º 1
0
    def manage_existing_get_size(self, volume, existing_ref):
        """Return size of the volume to be managed by manage_existing."""
        existing_vol_name = self._get_existing_vol_name(existing_ref)

        # The ZFSSA NFS driver only has one mounted share.
        local_share_mount = self._get_mount_point_for_share(
            self._mounted_shares[0])
        local_vol_path = os.path.join(local_share_mount, existing_vol_name)

        try:
            if os.path.isfile(local_vol_path):
                size = int(
                    math.ceil(
                        float(utils.get_file_size(local_vol_path)) / units.Gi))
        except (OSError, ValueError):
            err_msg = (_("Failed to get size of existing volume: %(vol)s. "
                         "Volume Manage failed."), {
                             'vol': existing_vol_name
                         })
            LOG.error(err_msg)
            raise exception.VolumeBackendAPIException(data=err_msg)

        LOG.debug("Size volume: %(vol)s to be migrated is: %(size)s.", {
            'vol': existing_vol_name,
            'size': size
        })

        return size
Exemplo n.º 2
0
    def manage_existing_get_size(self, volume, existing_vol_ref):
        """Returns the size of volume to be managed by manage_existing.

        When calculating the size, round up to the next GB.

        :param volume:           Cinder volume to manage
        :param existing_vol_ref: Existing volume to take under management
        """
        # Attempt to find NFS share, NFS mount, and volume path from vol_ref.
        (nfs_share, nfs_mount, vol_path) = \
            self._get_share_mount_and_vol_from_vol_ref(existing_vol_ref)

        try:
            LOG.debug("Asked to get size of NFS vol_ref %s.",
                      existing_vol_ref['source-name'])

            file_path = os.path.join(nfs_mount, vol_path)
            file_size = float(utils.get_file_size(file_path)) / units.Gi
            vol_size = int(math.ceil(file_size))
        except (OSError, ValueError):
            exception_message = (_("Failed to manage existing volume "
                                   "%(name)s, because of error in getting "
                                   "volume size."),
                                 {'name': existing_vol_ref['source-name']})
            raise exception.VolumeBackendAPIException(data=exception_message)

        LOG.debug("Reporting size of NFS volume ref %(ref)s as %(size)d GB.",
                  {'ref': existing_vol_ref['source-name'], 'size': vol_size})

        return vol_size
Exemplo n.º 3
0
    def manage_existing_get_size(self, volume, existing_vol_ref):
        """Returns the size of volume to be managed by manage_existing.

        When calculating the size, round up to the next GB.

        :param volume:           Cinder volume to manage
        :param existing_vol_ref: Existing volume to take under management
        """
        # Attempt to find NFS share, NFS mount, and volume path from vol_ref.
        (nfs_share, nfs_mount, vol_path) = \
            self._get_share_mount_and_vol_from_vol_ref(existing_vol_ref)

        try:
            LOG.debug("Asked to get size of NFS vol_ref %s.",
                      existing_vol_ref['source-name'])

            file_path = os.path.join(nfs_mount, vol_path)
            file_size = float(utils.get_file_size(file_path)) / units.Gi
            vol_size = int(math.ceil(file_size))
        except (OSError, ValueError):
            exception_message = (_("Failed to manage existing volume "
                                   "%(name)s, because of error in getting "
                                   "volume size."),
                                 {'name': existing_vol_ref['source-name']})
            raise exception.VolumeBackendAPIException(data=exception_message)

        LOG.debug("Reporting size of NFS volume ref %(ref)s as %(size)d GB.",
                  {'ref': existing_vol_ref['source-name'], 'size': vol_size})

        return vol_size
Exemplo n.º 4
0
    def _manage_existing_get_size(self, existing_ref):
        # Attempt to find NFS share, NFS mount, and path from vol_ref.
        (nfs_share, nfs_mount,
         path) = self._get_share_mount_and_vol_from_vol_ref(existing_ref)

        try:
            LOG.debug("Asked to get size of NFS ref %(ref)s.",
                      {'ref': existing_ref['source-name']})

            file_path = os.path.join(nfs_mount, path)
            file_size = float(cutils.get_file_size(file_path)) / units.Gi
            # Round up to next Gb
            size = int(math.ceil(file_size))
        except (OSError, ValueError):
            exception_message = (_("Failed to manage existing volume/snapshot "
                                   "%(name)s, because of error in getting "
                                   "its size."), {
                                       'name': existing_ref['source-name']
                                   })
            LOG.exception(exception_message)
            raise exception.VolumeBackendAPIException(data=exception_message)

        LOG.debug("Reporting size of NFS ref %(ref)s as %(size)d GB.", {
            'ref': existing_ref['source-name'],
            'size': size
        })

        return size
Exemplo n.º 5
0
    def _manage_existing_get_size(self, existing_ref):
        # Attempt to find NFS share, NFS mount, and path from vol_ref.
        (nfs_share, nfs_mount, path
         ) = self._get_share_mount_and_vol_from_vol_ref(existing_ref)

        try:
            LOG.debug("Asked to get size of NFS ref %(ref)s.",
                      {'ref': existing_ref['source-name']})

            file_path = os.path.join(nfs_mount, path)
            file_size = float(cutils.get_file_size(file_path)) / units.Gi
            # Round up to next Gb
            size = int(math.ceil(file_size))
        except (OSError, ValueError):
            exception_message = (_("Failed to manage existing volume/snapshot "
                                   "%(name)s, because of error in getting "
                                   "its size."),
                                 {'name': existing_ref['source-name']})
            LOG.exception(exception_message)
            raise exception.VolumeBackendAPIException(data=exception_message)

        LOG.debug("Reporting size of NFS ref %(ref)s as %(size)d GB.",
                  {'ref': existing_ref['source-name'], 'size': size})

        return size
Exemplo n.º 6
0
    def test_get_file_size(self, mock_stat):
        class stat_result(object):
            st_mode = 0o777
            st_size = 1074253824

        test_file = '/var/tmp/made_up_file'
        mock_stat.return_value = stat_result
        size = utils.get_file_size(test_file)
        self.assertEqual(size, stat_result.st_size)
        mock_stat.assert_called_once_with(test_file)
Exemplo n.º 7
0
    def test_get_file_size(self, mock_stat):

        class stat_result(object):
            st_mode = 0o777
            st_size = 1074253824

        test_file = '/var/tmp/made_up_file'
        mock_stat.return_value = stat_result
        size = utils.get_file_size(test_file)
        self.assertEqual(size, stat_result.st_size)
        mock_stat.assert_called_once_with(test_file)
Exemplo n.º 8
0
    def manage_existing_get_size(self, volume, existing_ref):
        """Returns size of volume to be managed by manage_existing.

        When calculating the size, round up to the next GB.

        :param volume:       Cinder volume to manage
        :param existing_ref: Driver-specific information used to identify a
                             volume
        """
        nfs_share, nfs_mount, volume_name = self._get_share_mount(existing_ref)

        try:
            volume_path = os.path.join(nfs_mount, volume_name)
            vol_size = math.ceil(float(utils.get_file_size(volume_path)) /
                                 units.Gi)
        except OSError:
            msg = (_('Failed to get size of volume %s') %
                   existing_ref['source-name'])
            raise exception.VolumeDriverException(msg)

        return vol_size
Exemplo n.º 9
0
    def manage_existing_get_size(self, volume, existing_ref):
        """Returns size of volume to be managed by manage_existing.

        When calculating the size, round up to the next GB.

        :param volume:       Cinder volume to manage
        :param existing_ref: Driver-specific information used to identify a
                             volume
        """
        nfs_share, nfs_mount, volume_name = self._get_share_mount(existing_ref)

        try:
            volume_path = os.path.join(nfs_mount, volume_name)
            vol_size = int(math.ceil(float(utils.get_file_size(volume_path)) /
                                     units.Gi))
        except OSError:
            msg = (_('Failed to get size of volume %s') %
                   existing_ref['source-name'])
            raise exception.VolumeDriverException(msg)

        return vol_size
Exemplo n.º 10
0
    def manage_existing_get_size(self, volume, existing_ref):
        """Return size of the volume to be managed by manage_existing."""
        existing_vol_name = self._get_existing_vol_name(existing_ref)

        # The ZFSSA NFS driver only has one mounted share.
        local_share_mount = self._get_mount_point_for_share(
            self._mounted_shares[0])
        local_vol_path = os.path.join(local_share_mount, existing_vol_name)

        try:
            if os.path.isfile(local_vol_path):
                size = int(math.ceil(float(
                    utils.get_file_size(local_vol_path)) / units.Gi))
        except (OSError, ValueError):
            err_msg = (_("Failed to get size of existing volume: %(vol). "
                         "Volume Manage failed."), {'vol': existing_vol_name})
            LOG.error(err_msg)
            raise exception.VolumeBackendAPIException(data=err_msg)

        LOG.debug("Size volume: %(vol)s to be migrated is: %(size)s.",
                  {'vol': existing_vol_name, 'size': size})

        return size
Exemplo n.º 11
0
 def _get_file_size(self, file_path):
     file_size = float(cutils.get_file_size(file_path)) / units.Gi
     # Round up to next Gb
     return int(math.ceil(file_size))
Exemplo n.º 12
0
 def _get_file_size(self, file_path):
     file_size = float(cutils.get_file_size(file_path)) / units.Gi
     # Round up to next Gb
     return int(math.ceil(file_size))
Exemplo n.º 13
0
        When calculating the size, round up to the next GB.

        :param volume:           Cinder volume to manage
        :param existing_vol_ref: Existing volume to take under management
        """
        # Attempt to find NFS share, NFS mount, and volume path from vol_ref.
        (nfs_share, nfs_mount, vol_path) = \
            self._get_share_mount_and_vol_from_vol_ref(existing_vol_ref)

        try:
            LOG.debug("Asked to get size of NFS vol_ref %s.",
                      existing_vol_ref['source-name'])

            file_path = os.path.join(nfs_mount, vol_path)
            file_size = float(utils.get_file_size(file_path)) / units.Gi
            vol_size = int(math.ceil(file_size))
        except (OSError, ValueError):
            exception_message = (_("Failed to manage existing volume "
                                   "%(name)s, because of error in getting "
                                   "volume size."),
                                 {'name': existing_vol_ref['source-name']})
            raise exception.VolumeBackendAPIException(data=exception_message)

        LOG.debug("Reporting size of NFS volume ref %(ref)s as %(size)d GB.",
                  {'ref': existing_vol_ref['source-name'], 'size': vol_size})

        return vol_size

    def unmanage(self, volume):
        """Removes the specified volume from Cinder management.