def add_mark_rule(src_ip, environment):
"""Add an environment mark for all traffic coming from an IP.
:param ``str`` src_ip:
Source IP to be marked
:param ``str`` environment:
Environment to use for the mark
"""
assert environment in SET_BY_ENVIRONMENT, \
"Unknown environment: %r" % environment
target_set = SET_BY_ENVIRONMENT[environment]
add_ip_set(target_set, src_ip)
# Check that the IP is not marked in any other environment
other_env_sets = {
env_set for env_set in six.viewvalues(SET_BY_ENVIRONMENT)
if env_set != target_set
}
for other_set in other_env_sets:
if test_ip_set(other_set, src_ip) is True:
raise Exception('%r is already in %r', src_ip, other_set)
评论列表
文章目录