Example #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)
Example #2
0
    def create_policy(self, policy_dict):
        policy_dict = copy.deepcopy(policy_dict)
        validate_policy_item(policy_dict)
        policy_name = policy_dict['name']

        # check name is valid
        if not compile.string_is_servicename(policy_name):
            raise exception.PolicyException(
                'name `%s` is not a valid policy name' % policy_name)

        # make defaults
        if 'kind' not in policy_dict:
            policy_dict['kind'] = 'nonrecursive'
        if 'abbreviation' not in policy_dict:
            policy_dict['abbreviation'] = policy_name[:5]
        if 'description' not in policy_dict:
            policy_dict['description'] = ''

        try:
            # Note(thread-safety): blocking call
            policy = db_library_policies.add_policy(policy_dict=policy_dict)
            return policy.to_dict()
        except db_exc.DBError:
            LOG.exception('Creating a new library policy failed due to '
                          'backend database error.')
            raise
Example #3
0
    def replace_policy(self, id_, policy_dict):
        validate_policy_item(policy_dict)
        policy_name = policy_dict['name']

        # check name is valid
        if not compile.string_is_servicename(policy_name):
            raise exception.PolicyException(
                "Policy name %s is not a valid service name" % policy_name)

        # make defaults
        if 'kind' not in policy_dict:
            policy_dict['kind'] = 'nonrecursive'
        if 'abbreviation' not in policy_dict:
            policy_dict['abbreviation'] = policy_name[:5]
        if 'description' not in policy_dict:
            policy_dict['description'] = ''

        # Note(thread-safety): blocking call
        policy = db_library_policies.replace_policy(id_,
                                                    policy_dict=policy_dict)
        return policy.to_dict()
Example #4
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
Example #5
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