예제 #1
0
    def validate_create_datasource(self, req):
        name = req['name']
        if not datalog_compile.string_is_servicename(name):
            raise exception.InvalidDatasourceName(value=name)
        driver = req['driver']
        config = req['config'] or {}
        for loaded_driver in self.loaded_drivers.values():
            if loaded_driver['id'] == driver:
                specified_options = set(config.keys())
                valid_options = set(loaded_driver['config'].keys())
                # Check that all the specified options passed in are
                # valid configuration options that the driver exposes.
                invalid_options = specified_options - valid_options
                if invalid_options:
                    raise exception.InvalidDriverOption(
                        invalid_options=invalid_options)

                # check that all the required options are passed in
                required_options = set([
                    k for k, v in loaded_driver['config'].items()
                    if v == constants.REQUIRED
                ])
                missing_options = required_options - specified_options
                if missing_options:
                    missing_options = ', '.join(missing_options)
                    raise exception.MissingRequiredConfigOptions(
                        missing_options=missing_options)
                return loaded_driver

        # If we get here no datasource driver match was found.
        raise exception.InvalidDriver(driver=req)
예제 #2
0
    def add_datasource(self, item, deleted=False, update_db=True):
        req = self.make_datasource_dict(item)

        # check the request has valid information
        self.node.validate_create_datasource(req)
        if (len(req['name']) == 0 or req['name'][0] == '_'):
            raise exception.InvalidDatasourceName(value=req['name'])

        new_id = req['id']
        LOG.debug("adding datasource %s", req['name'])
        if update_db:
            LOG.debug("updating db")
            try:
                driver_info = self.node.get_driver_info(req['driver'])
                # Note(thread-safety): blocking call
                datasource = datasources_db.add_datasource(
                    id_=req['id'],
                    name=req['name'],
                    driver=req['driver'],
                    config=req['config'],
                    description=req['description'],
                    enabled=req['enabled'],
                    secret_config_fields=driver_info.get('secret', []))
            except db_exc.DBDuplicateEntry:
                raise exception.DatasourceNameInUse(value=req['name'])
            except db_exc.DBError:
                LOG.exception('Creating a new datasource failed due to '
                              'database backend error.')
                raise exception.DatasourceCreationError(value=req['name'])

        new_id = datasource['id']
        try:
            self.synchronizer.sync_datasource(req['name'])
            # immediate synch policies on local PE if present
            # otherwise wait for regularly scheduled synch
            engine = self.node.service_object(api_base.ENGINE_SERVICE_ID)
            if engine is not None:
                engine.synchronizer.sync_one_policy(req['name'])
            # TODO(dse2): also broadcast to all PE nodes to synch
        except exception.DataServiceError:
            LOG.debug('the datasource service is already '
                      'created in the node')
        except Exception:
            LOG.exception(
                'Unexpected exception encountered while registering '
                'new datasource %s.', req['name'])
            if update_db:
                datasources_db.delete_datasource(req['id'])
            msg = ("Datasource service: %s creation fails." % req['name'])
            raise exception.DatasourceCreationError(message=msg)

        new_item = dict(item)
        new_item['id'] = new_id
        return self.node.make_datasource_dict(new_item)
예제 #3
0
    def validate_create_datasource(self, req):
        name = req['name']
        if not datalog_compile.string_is_servicename(name):
            raise exception.InvalidDatasourceName(value=name)
        driver = req['driver']
        config = req['config'] or {}

        try:
            loaded_driver = self.get_driver_info(driver)
        except exception.DriverNotFound:
            raise exception.InvalidDriver(driver=req)

        specified_options = set(config.keys())
        valid_options = set(loaded_driver['config'].keys())
        # Check that all the specified options passed in are
        # valid configuration options that the driver exposes.
        invalid_options = specified_options - valid_options
        if invalid_options:
            raise exception.InvalidDriverOption(
                invalid_options=invalid_options)

        # check that all the required options are passed in
        required_options = set([
            k for k, v in loaded_driver['config'].items()
            if v == constants.REQUIRED
        ])
        missing_options = required_options - specified_options

        if ('project_name' in missing_options
                and 'tenant_name' in specified_options):
            LOG.warning("tenant_name is deprecated, use project_name instead")
            missing_options.remove('project_name')

        if missing_options:
            missing_options = ', '.join(missing_options)
            raise exception.MissingRequiredConfigOptions(
                missing_options=missing_options)
        return loaded_driver