d2 = {**d1, **param} print("MERGE" + str(d2)) if __name__ == '__main__': print("test_DB") dbManager = DBManager(host='127.0.0.1') # dbManager.remove({Key.vendor.value: 'VendorA'}) issue: #000001 dbManager.remove({Key.vendor.value: 'VendorA', Key.group.value: 'GroupA'}) dbManager.remove({Key.vendor.value: 'VendorA', Key.group.value: 'GroupB'}) dbManager.insert(vid_gid={ Key.vendor.value: 'VendorA', Key.group.value: 'GroupA' }, document={ Key.id.value: "001", Key.nick.value: "Ronald", Key.role.value: 'pusher', Key.date.value: _current_time_() }) dbManager.insert(vid_gid={ Key.vendor.value: 'VendorA', Key.group.value: 'GroupA' }, document={ Key.id.value: "001", Key.nick.value: "Ronaldllllll", Key.role.value: 'pusher', Key.date.value: _current_time_() }) dbManager.insert(vid_gid={
class OnlineNodes(object): def __init__(self, url=config['mongo']['server_url'], port=config['mongo']['server_port']): self._db_manager = DBManager(host=url, port=port) def reset(self): # clear the data base each time mc bootup dblist = self._db_manager.get_db_list() for d in dblist: #Waring: this host should not name a db start with 'V' if d.startswith('V'): self._db_manager.remove(vid_gid_nid={Key.vendor.value: d}) def find_one(self, source_tag): """ :param source_tag: :return: a dic """ vid, gid, nid = source_tag.split('_') node_info = self._db_manager.query(vid_gid_nid={ Key.vendor.value: vid, Key.group.value: gid, Key.node.value: nid }) if len(node_info) == 0: return None else: return node_info[0] def find_role(self, source_tag, role): vid, gid, nid = source_tag.split('_') role_info = self._db_manager.query(vid_gid_nid={ Key.vendor.value: vid, Key.group.value: gid }, condition={Key.role.value: role}) return role_info #return str(role_info) def insert(self, source_tag, document): vid, gid, nid = source_tag.split('_') self._db_manager.insert(vid_gid={ Key.vendor.value: vid, Key.group.value: gid }, document=document) def remove(self, source_tag): vid, gid, nid = source_tag.split('_') self._db_manager.remove(vid_gid_nid={ Key.vendor.value: vid, Key.group.value: gid, Key.node.value: nid }) def update(self, source_tag, field, value): vid, gid, nid = source_tag.split('_') self._db_manager.update(vid_gid_nid={ Key.vendor.value: vid, Key.group.value: gid, Key.node.value: nid }, key_value={field: value})