Esempio n. 1
0
    def validate_create_datasource(self, req):
        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)
Esempio n. 2
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