Exemplo n.º 1
0
    def _get_rbd_handle(self, connection_properties):
        try:
            user = connection_properties['auth_username']
            pool, volume = connection_properties['name'].split('/')
            cluster_name = connection_properties['cluster_name']
            monitor_ips = connection_properties['hosts']
            monitor_ports = connection_properties['ports']
            keyring = connection_properties.get('keyring')
        except (KeyError, ValueError):
            msg = _("Connect volume failed, malformed connection properties.")
            raise exception.BrickException(msg=msg)

        conf = self._create_ceph_conf(monitor_ips, monitor_ports,
                                      str(cluster_name), user, keyring)
        try:
            rbd_client = linuxrbd.RBDClient(user,
                                            pool,
                                            conffile=conf,
                                            rbd_cluster_name=str(cluster_name))
            rbd_volume = linuxrbd.RBDVolume(rbd_client, volume)
            rbd_handle = linuxrbd.RBDVolumeIOWrapper(
                linuxrbd.RBDImageMetadata(rbd_volume, pool, user, conf))
        except Exception:
            fileutils.delete_if_exists(conf)
            raise

        return rbd_handle
Exemplo n.º 2
0
    def _get_rbd_handle(self, connection_properties):
        try:
            user = connection_properties['auth_username']
            pool, volume = connection_properties['name'].split('/')
            cluster_name = connection_properties.get('cluster_name')
            monitor_ips = connection_properties.get('hosts')
            monitor_ports = connection_properties.get('ports')
        except IndexError:
            msg = _("Connect volume failed, malformed connection properties")
            raise exception.BrickException(msg=msg)

        conf = self._create_ceph_conf(monitor_ips, monitor_ports,
                                      str(cluster_name), user)
        rbd_client = linuxrbd.RBDClient(user,
                                        pool,
                                        conffile=conf,
                                        rbd_cluster_name=str(cluster_name))
        rbd_volume = linuxrbd.RBDVolume(rbd_client, volume)
        rbd_handle = linuxrbd.RBDVolumeIOWrapper(
            linuxrbd.RBDImageMetadata(rbd_volume, pool, user, conf))

        if os.path.exists(conf):
            os.remove(conf)

        return rbd_handle
Exemplo n.º 3
0
    def _get_rbd_handle(self, connection_properties):
        try:
            user = connection_properties['auth_username']
            pool, volume = connection_properties['name'].split('/')
            cluster_name = connection_properties['cluster_name']
            monitor_ips = connection_properties['hosts']
            monitor_ports = connection_properties['ports']
            # NOTE: cinder no longer passes keyring data in the connection
            # properties as of the victoria release.  See OSSN-0085.  But
            # cinderlib does, so we must keep the code related to the keyring.
            keyring = connection_properties.get('keyring')
        except (KeyError, ValueError):
            msg = _("Connect volume failed, malformed connection properties.")
            raise exception.BrickException(msg=msg)

        conf = self._create_ceph_conf(monitor_ips, monitor_ports,
                                      str(cluster_name), user, keyring)
        try:
            rbd_client = linuxrbd.RBDClient(user,
                                            pool,
                                            conffile=conf,
                                            rbd_cluster_name=str(cluster_name))
            rbd_volume = linuxrbd.RBDVolume(rbd_client, volume)
            rbd_handle = linuxrbd.RBDVolumeIOWrapper(
                linuxrbd.RBDImageMetadata(rbd_volume, pool, user, conf))
        except Exception:
            fileutils.delete_if_exists(conf)
            raise

        return rbd_handle
Exemplo n.º 4
0
 def test_close(self, rbd_disconnect, mock_rados, mock_rbd):
     rbd_client = linuxrbd.RBDClient('user', 'pool')
     rbd_volume = linuxrbd.RBDVolume(rbd_client, 'volume')
     rbd_handle = linuxrbd.RBDVolumeIOWrapper(
         linuxrbd.RBDImageMetadata(rbd_volume, 'pool', 'user', None))
     rbd_handle.close()
     self.assertEqual(1, rbd_disconnect.call_count)
Exemplo n.º 5
0
    def restore_backup(self, context, backup, volume, backup_service):
        """Restore an existing backup to a new or existing volume."""
        with RBDVolumeProxy(self, volume.name,
                            self.configuration.rbd_pool) as rbd_image:
            rbd_meta = linuxrbd.RBDImageMetadata(
                rbd_image, self.configuration.rbd_pool,
                self.configuration.rbd_user, self.configuration.rbd_ceph_conf)
            rbd_fd = linuxrbd.RBDVolumeIOWrapper(rbd_meta)
            backup_service.restore(backup, volume.id, rbd_fd)

        LOG.debug("volume restore complete.")
Exemplo n.º 6
0
    def backup_volume(self, context, backup, backup_service):
        """Create a new backup from an existing volume."""
        volume = self.db.volume_get(context, backup.volume_id)

        with RBDVolumeProxy(self, volume.name,
                            self.configuration.rbd_pool) as rbd_image:
            rbd_meta = linuxrbd.RBDImageMetadata(
                rbd_image, self.configuration.rbd_pool,
                self.configuration.rbd_user, self.configuration.rbd_ceph_conf)
            rbd_fd = linuxrbd.RBDVolumeIOWrapper(rbd_meta)
            backup_service.backup(backup, rbd_fd)

        LOG.debug("volume backup complete.")