def purge_rules()

in src/ansible_collections/alibaba/apsarastack/plugins/modules/ali_security_group.py [0:0]


def purge_rules(module, group, existing_rule, rules, direction):

    if not isinstance(existing_rule, dict):
        module.fail_json(msg='Invalid existing rule type [{0}].'.format(type(existing_rule)))

    if not isinstance(rules, list):
        module.fail_json(msg='Invalid rules type [{0}]. The specified rules should be a list.'.format(type(rules)))

    VALID_PARAMS = VALID_INGRESS_PARAMS
    if direction == "egress":
        VALID_PARAMS = VALID_EGRESS_PARAMS

    # Find the rules which is not in the specified rules
    find = False
    for rule in rules:
        for key in VALID_PARAMS:
            if not rule.get(key):
                continue
            if existing_rule.get(key) != rule.get(key):
                find = False
                break
            find = True
        if find:
            break
    # If it is not found, there will not purge anythind
    if not find:
        return group.revoke(existing_rule, direction)
    return False