summaryrefslogtreecommitdiff
path: root/cloudinit/registry.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/registry.py')
-rw-r--r--cloudinit/registry.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/cloudinit/registry.py b/cloudinit/registry.py
index 46cf0585..04368ddf 100644
--- a/cloudinit/registry.py
+++ b/cloudinit/registry.py
@@ -1,3 +1,7 @@
+# Copyright 2015 Canonical Ltd.
+# This file is part of cloud-init. See LICENCE file for license information.
+#
+# vi: ts=4 expandtab
import copy
@@ -5,6 +9,9 @@ class DictRegistry(object):
"""A simple registry for a mapping of objects."""
def __init__(self):
+ self.reset()
+
+ def reset(self):
self._items = {}
def register_item(self, key, item):
@@ -14,6 +21,13 @@ class DictRegistry(object):
'Item already registered with key {0}'.format(key))
self._items[key] = item
+ def unregister_item(self, key, force=True):
+ """Remove item from the registry."""
+ if key in self._items:
+ del self._items[key]
+ elif not force:
+ raise KeyError("%s: key not present to unregister" % key)
+
@property
def registered_items(self):
"""All the items that have been registered.