Beispiel #1
0
def create_l7policy(l7policy_dict, lb_id, listener_id):
    l7policy_dict = validate.sanitize_l7policy_api_args(l7policy_dict,
                                                        create=True)
    l7policy_dict[constants.PROVISIONING_STATUS] = constants.PENDING_CREATE
    l7policy_dict[constants.OPERATING_STATUS] = constants.OFFLINE
    if not l7policy_dict.get('id'):
        l7policy_dict['id'] = uuidutils.generate_uuid()
    l7policy_dict['listener_id'] = listener_id
    if l7policy_dict.get('redirect_pool'):
        pool_dict = l7policy_dict.pop('redirect_pool')
        prepped_pool = create_pool(pool_dict, lb_id)
        l7policy_dict['redirect_pool'] = prepped_pool
        l7policy_dict['redirect_pool_id'] = prepped_pool['id']
    rules = l7policy_dict.pop('rules', None)
    if rules:
        l7policy_dict['l7rules'] = rules
    if l7policy_dict.get('l7rules'):
        if (len(l7policy_dict.get('l7rules')) >
                constants.MAX_L7RULES_PER_L7POLICY):
            raise exceptions.TooManyL7RulesOnL7Policy(id=l7policy_dict['id'])
        prepped_l7rules = []
        for l7rule_dict in l7policy_dict.get('l7rules'):
            try:
                validate.l7rule_data(l7rule.L7RulePOST(**l7rule_dict))
            except Exception as e:
                raise exceptions.L7RuleValidation(error=e)
            prepped_l7rule = create_l7rule(l7rule_dict, l7policy_dict['id'])
            prepped_l7rules.append(prepped_l7rule)
    return l7policy_dict
Beispiel #2
0
    def _graph_create(self, lock_session, rule_dict):
        try:
            validate.l7rule_data(l7rule_types.L7RulePOST(**rule_dict))
        except Exception as e:
            raise exceptions.L7RuleValidation(error=e)
        rule_dict = db_prepare.create_l7rule(rule_dict, self.l7policy_id)
        db_rule = self._validate_create_l7rule(lock_session, rule_dict)

        return db_rule