summaryrefslogtreecommitdiff
path: root/trove/common/utils.py
diff options
context:
space:
mode:
authorPetr Malik <pmalik@tesora.com>2015-06-03 11:42:00 -0400
committerPetr Malik <pmalik@tesora.com>2015-06-25 20:57:27 -0400
commitd37a99e584c5f56f8838e33c95e997e762f4e9f4 (patch)
tree019bbd49b7c282e2ab6933c1cfcaeb7e2654e616 /trove/common/utils.py
parentfda90810908076be007a4d9ca90061a77e3c28a7 (diff)
downloadtrove-d37a99e584c5f56f8838e33c95e997e762f4e9f4.tar.gz
Implement guestagent Configuration Manager
Facilitate code reuse by implementing a manager class that could be used by all guestagents to manage their configuration files and overrides. ConfigurationManager is responsible for management of datastore configuration. Its base functionality includes reading and writing configuration files. It is responsible for validating user inputs and requests. When supplied an override strategy it allows the user to manage configuration overrides as well. ConfigurationOverrideStrategy handles configuration files. The strategy provides functionality to enumerate, apply and remove configuration overrides (revisions). The patch set also includes functionality for reading and writing files and implements codecs for serialization and deserialization of common configuration formats. The implemented codecs get reused in the existing configuration parsers. Includes a couple of little fixes to the taskmanager that will be required by other datastores. - Do not validate value ranges if min/max is not specified in the validation rules. - Do not attempt to parse non-string configuration values in the taskmanager. Implements: blueprint guestagent-configuration-manager Change-Id: I1c940c96deb20ca722d9fd400a6ef757b2ba249f
Diffstat (limited to 'trove/common/utils.py')
-rw-r--r--trove/common/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/trove/common/utils.py b/trove/common/utils.py
index fc43cc01..77411094 100644
--- a/trove/common/utils.py
+++ b/trove/common/utils.py
@@ -14,11 +14,13 @@
# under the License.
"""I totally stole most of this from melange, thx guys!!!"""
+import collections
import datetime
import inspect
import os
import shutil
import time
+import types
import uuid
from eventlet.timeout import Timeout
@@ -289,3 +291,23 @@ def gen_ports(portstr):
if int(from_port) > int(to_port):
raise ValueError
return from_port, to_port
+
+
+def unpack_singleton(container):
+ """Unpack singleton collections.
+
+ Check whether a given collection is a singleton (has exactly one element)
+ and unpack it if that is the case.
+ Return the original collection otherwise.
+ """
+ if is_collection(container) and len(container) == 1:
+ return unpack_singleton(container[0])
+
+ return container
+
+
+def is_collection(item):
+ """Return True is a given item is an iterable collection, but not a string.
+ """
+ return (isinstance(item, collections.Iterable) and
+ not isinstance(item, types.StringTypes))