def init_host(self):
    'Perform any required initialization.'
    ctxt = context.get_admin_context()
    LOG.info(_LI('Starting volume driver %(driver_name)s (%(version)s)'), {'driver_name': self.driver.__class__.__name__, 'version': self.driver.get_version()})
    try:
        self.driver.do_setup(ctxt)
        self.driver.check_for_setup_error()
    except Exception:
        LOG.exception(_LE('Failed to initialize driver.'), resource={'type': 'driver', 'id': self.__class__.__name__})
        return
    self.driver.init_capabilities()
    volumes = objects.VolumeList.get_all_by_host(ctxt, self.host)
    snapshots = self.db.snapshot_get_by_host(ctxt, self.host)
    self._sync_provider_info(ctxt, volumes, snapshots)
    try:
        self.stats['pools'] = {}
        self.stats.update({'allocated_capacity_gb': 0})
        for volume in volumes:
            if (volume['status'] in ['in-use', 'available']):
                self._count_allocated_capacity(ctxt, volume)
                try:
                    if (volume['status'] in ['in-use']):
                        self.driver.ensure_export(ctxt, volume)
                except Exception:
                    LOG.exception(_LE('Failed to re-export volume, setting to ERROR.'), resource=volume)
                    volume.status = 'error'
                    volume.save()
            elif (volume['status'] in ('downloading', 'creating')):
                LOG.warning(_LW('Detected volume stuck in %(curr_status)s status, setting to ERROR.'), {'curr_status': volume['status']}, resource=volume)
                if (volume['status'] == 'downloading'):
                    self.driver.clear_download(ctxt, volume)
                volume.status = 'error'
                volume.save()
            elif (volume.status == 'uploading'):
                self.db.volume_update_status_based_on_attachment(ctxt, volume.id)
            else:
                pass
        snapshots = objects.SnapshotList.get_by_host(ctxt, self.host, {'status': fields.SnapshotStatus.CREATING})
        for snapshot in snapshots:
            LOG.warning(_LW('Detected snapshot stuck in creating status, setting to ERROR.'), resource=snapshot)
            snapshot.status = fields.SnapshotStatus.ERROR
            snapshot.save()
    except Exception:
        LOG.exception(_LE('Error during re-export on driver init.'), resource=volume)
        return
    self.driver.set_throttle()
    self.driver.set_initialized()
    for volume in volumes:
        if (volume['status'] == 'deleting'):
            if CONF.volume_service_inithost_offload:
                self._add_to_threadpool(self.delete_volume, ctxt, volume['id'], volume=volume)
            else:
                self.delete_volume(ctxt, volume['id'], volume=volume)
            LOG.info(_LI('Resume volume delete completed successfully.'), resource=volume)
    self.publish_service_capabilities(ctxt)
    LOG.info(_LI('Driver initialization completed successfully.'), resource={'type': 'driver', 'id': self.driver.__class__.__name__})
Perform any required initialization.
def init_host(self):
    
    ctxt = context.get_admin_context()
    LOG.info(_LI('Starting volume driver %(driver_name)s (%(version)s)'), {'driver_name': self.driver.__class__.__name__, 'version': self.driver.get_version()})
    try:
        self.driver.do_setup(ctxt)
        self.driver.check_for_setup_error()
    except Exception:
        LOG.exception(_LE('Failed to initialize driver.'), resource={'type': 'driver', 'id': self.__class__.__name__})
        return
    self.driver.init_capabilities()
    volumes = objects.VolumeList.get_all_by_host(ctxt, self.host)
    snapshots = self.db.snapshot_get_by_host(ctxt, self.host)
    self._sync_provider_info(ctxt, volumes, snapshots)
    try:
        self.stats['pools'] = {}
        self.stats.update({'allocated_capacity_gb': 0})
        for volume in volumes:
            if (volume['status'] in ['in-use', 'available']):
                self._count_allocated_capacity(ctxt, volume)
                try:
                    if (volume['status'] in ['in-use']):
                        self.driver.ensure_export(ctxt, volume)
                except Exception:
                    LOG.exception(_LE('Failed to re-export volume, setting to ERROR.'), resource=volume)
                    volume.status = 'error'
                    volume.save()
            elif (volume['status'] in ('downloading', 'creating')):
                LOG.warning(_LW('Detected volume stuck in %(curr_status)s status, setting to ERROR.'), {'curr_status': volume['status']}, resource=volume)
                if (volume['status'] == 'downloading'):
                    self.driver.clear_download(ctxt, volume)
                volume.status = 'error'
                volume.save()
            elif (volume.status == 'uploading'):
                self.db.volume_update_status_based_on_attachment(ctxt, volume.id)
            else:
                pass
        snapshots = objects.SnapshotList.get_by_host(ctxt, self.host, {'status': fields.SnapshotStatus.CREATING})
        for snapshot in snapshots:
            LOG.warning(_LW('Detected snapshot stuck in creating status, setting to ERROR.'), resource=snapshot)
            snapshot.status = fields.SnapshotStatus.ERROR
            snapshot.save()
    except Exception:
        LOG.exception(_LE('Error during re-export on driver init.'), resource=volume)
        return
    self.driver.set_throttle()
    self.driver.set_initialized()
    for volume in volumes:
        if (volume['status'] == 'deleting'):
            if CONF.volume_service_inithost_offload:
                self._add_to_threadpool(self.delete_volume, ctxt, volume['id'], volume=volume)
            else:
                self.delete_volume(ctxt, volume['id'], volume=volume)
            LOG.info(_LI('Resume volume delete completed successfully.'), resource=volume)
    self.publish_service_capabilities(ctxt)
    LOG.info(_LI('Driver initialization completed successfully.'), resource={'type': 'driver', 'id': self.driver.__class__.__name__})