On Tue, Apr 21, 2015 at 06:31:26PM +0200, 'Klaus Aehlig' via ganeti-devel wrote:
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: Klaus Aehlig <[email protected]>
---
Makefile.am | 1 +
lib/utils/__init__.py | 1 +
lib/utils/tags.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
create mode 100644 lib/utils/tags.py
diff --git a/Makefile.am b/Makefile.am
index a8e6f3c..c45779a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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 \
diff --git a/lib/utils/__init__.py b/lib/utils/__init__.py
index bdd9761..ce89869 100644
--- a/lib/utils/__init__.py
+++ b/lib/utils/__init__.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 *
diff --git a/lib/utils/tags.py b/lib/utils/tags.py
new file mode 100644
index 0000000..1353901
--- /dev/null
+++ b/lib/utils/tags.py
@@ -0,0 +1,59 @@
+#
+#
+
+# 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
--
2.2.0.rc0.207.ga3a616c
LGTM