Commit 3b7c4c4d authored by Klaus Aehlig's avatar Klaus Aehlig

Add a utility function for extracting exclusion tags

In order to be able to verify exclusion tag violations in cluster
verify, we need to decide which tags are exclusion tags. So add
two python utility functions: one for extracting exclusion prefixes
from from the cluster tags and one testing if a tag starts with
one of a set of given prefixes.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarPetr Pudlak <pudlak@google.com>
parent 4b4c4fab
......@@ -629,6 +629,7 @@ utils_PYTHON = \
lib/utils/security.py \
lib/utils/storage.py \
lib/utils/text.py \
lib/utils/tags.py \
lib/utils/version.py \
lib/utils/wrapper.py \
lib/utils/x509.py \
......
......@@ -65,6 +65,7 @@ from ganeti.utils.process import *
from ganeti.utils.retry import *
from ganeti.utils.security import *
from ganeti.utils.storage import *
from ganeti.utils.tags import *
from ganeti.utils.text import *
from ganeti.utils.wrapper import *
from ganeti.utils.version import *
......
#
#
# Copyright (C) 2015 Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""Utility functions for tag related operations
"""
from ganeti import constants
def GetExclusionPrefixes(ctags):
"""Extract the exclusion tag prefixes from the cluster tags
"""
prefixes = set([])
for tag in ctags:
if tag.startswith(constants.EX_TAGS_PREFIX):
prefixes.add(tag[len(constants.EX_TAGS_PREFIX):])
return prefixes
def IsGoodTag(prefixes, tag):
"""Decide if a string is a tag
@param prefixes: set of prefixes that would indicate
the tag being suitable
@param tag: the tag in question
"""
for prefix in prefixes:
if tag.startswith(prefix):
return True
return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment