summaryrefslogtreecommitdiff
path: root/cloudinit/registry.py
blob: 46cf0585207d915134e3dc07f197ff7f08f067ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import copy


class DictRegistry(object):
    """A simple registry for a mapping of objects."""

    def __init__(self):
        self._items = {}

    def register_item(self, key, item):
        """Add item to the registry."""
        if key in self._items:
            raise ValueError(
                'Item already registered with key {0}'.format(key))
        self._items[key] = item

    @property
    def registered_items(self):
        """All the items that have been registered.

        This cannot be used to modify the contents of the registry.
        """
        return copy.copy(self._items)