def set_proxy_config(peer_id, name, capabilities, port_property_capability, storage, callback):
    """
    Store node
    """
    try:
        for c in list_port_property_capabilities(which=port_property_capability):
            storage.add_index(['node', 'capabilities', c], peer_id, root_prefix_level=3)
        for c in capabilities:
            storage.add_index(['node', 'capabilities', c], peer_id, root_prefix_level=3)
    except:
        _log.error("Failed to set capabilities")

    attributes = AttributeResolver({"indexed_public": {"node_name": {"name": name}}})
    indexes = attributes.get_indexed_public()
    try:
        for index in indexes:
            storage.add_index(index, peer_id)
    except:
        _log.error("Failed to add node index")

    storage.set(prefix="node-", key=peer_id,
                value={"proxy": storage.node.id,
                "uris": None,
                "control_uris": None,
                "authz_server": None, # Set correct value
                "attributes": {'public': attributes.get_public(),
                'indexed_public': attributes.get_indexed_public(as_list=False)}},
                cb=CalvinCB(set_proxy_config_cb, callback=callback))
class PeerNode(object):
    def __init__(self, node, peer_id, attributes, capabilities,
                 port_property_capability):
        self.node = node
        self.id = peer_id
        self.attributes = AttributeResolver(json.loads(attributes))
        self.capabilities = capabilities
        self.port_property_capability = port_property_capability

    def add_node(self, cb):
        try:
            for c in list_port_property_capabilities(
                    which=self.port_property_capability):
                self.node.storage.add_index(['node', 'capabilities', c],
                                            self.id,
                                            root_prefix_level=3)
            for c in self.capabilities:
                self.node.storage.add_index(['node', 'capabilities', c],
                                            self.id,
                                            root_prefix_level=3)
        except Exception as e:
            _log.error("Failed to set capabilities %s" % e)

        public = None
        indexed_public = None
        indexes = self.attributes.get_indexed_public()
        for index in indexes:
            self.node.storage.add_index(index, self.id)
        public = self.attributes.get_public()
        indexed_public = self.attributes.get_indexed_public(as_list=False)

        self.node.storage.set(prefix="node-",
                              key=self.id,
                              value={
                                  "proxy": self.node.id,
                                  "uris": None,
                                  "control_uris": None,
                                  "attributes": {
                                      'public': public,
                                      'indexed_public': indexed_public
                                  }
                              },
                              cb=cb)

    def remove_node(self):
        self.node.storage.delete(prefix="node-", key=self.id, cb=None)
        try:
            for c in list_port_property_capabilities(
                    which=self.port_property_capability):
                self.node.storage.remove_index(['node', 'capabilities', c],
                                               self.id)
            for c in self.capabilities:
                self.node.storage.remove_index(['node', 'capabilities', c],
                                               self.id)
            for index in self.attributes.get_indexed_public():
                self.node.storage.remove_index(index, self.id)
        except Exception as e:
            _log.error("Failed to remove index %s" % e)
class PeerNode(object):

    def __init__(self, node, peer_id, attributes, capabilities, port_property_capability):
        self.node = node
        self.id = peer_id
        self.attributes = AttributeResolver(json.loads(attributes))
        self.capabilities = capabilities
        self.port_property_capability = port_property_capability

    def add_node(self, cb):
        try:
            for c in list_port_property_capabilities(which=self.port_property_capability):
                self.node.storage.add_index(['node', 'capabilities', c], self.id, root_prefix_level=3)
            for c in self.capabilities:
                self.node.storage.add_index(['node', 'capabilities', c], self.id, root_prefix_level=3)
        except Exception as e:
            _log.error("Failed to set capabilities %s" % e)

        public = None
        indexed_public = None
        indexes = self.attributes.get_indexed_public()
        for index in indexes:
            self.node.storage.add_index(index, self.id)
        public = self.attributes.get_public()
        indexed_public = self.attributes.get_indexed_public(as_list=False)

        self.node.storage.set(prefix="node-", key=self.id,
                    value={"proxy": self.node.id,
                    "uris": None,
                    "control_uris": None,
                    "attributes": {'public': public,
                    'indexed_public': indexed_public}},
                    cb=cb)

    def remove_node(self):
        self.node.storage.delete(prefix="node-", key=self.id, cb=None)
        try:
            for c in list_port_property_capabilities(which=self.port_property_capability):
                self.node.storage.remove_index(['node', 'capabilities', c], self.id)
            for c in self.capabilities:
                self.node.storage.remove_index(['node', 'capabilities', c], self.id)
            for index in self.attributes.get_indexed_public():
                self.node.storage.remove_index(index, self.id)
        except Exception as e:
            _log.error("Failed to remove index %s" % e)