예제 #1
0
        print(str(i))

    result = dbManager.query(vid_gid_nid={Key.vendor.value: 'VendorA'},
                             condition={Key.nick.value: "Figo"})
    print("db query condition: ")
    for i in result:
        print(str(i))
    result = dbManager.count(vid_gid={
        Key.vendor.value: 'VendorA',
        Key.group.value: 'GroupA'
    })
    print("count: " + str(result))

    dbManager.update(vid_gid_nid={
        Key.vendor.value: 'VendorA',
        Key.group.value: 'GroupA'
    },
                     key_value={})

    print("update node")
    dbManager.update(vid_gid_nid={
        Key.vendor.value: 'VendorA',
        Key.group.value: 'GroupA'
    },
                     key_value={Key.location.value: 'shanghai'})
    result = dbManager.query(vid_gid_nid={
        Key.vendor.value: 'VendorA',
        Key.group.value: 'GroupA'
    })
    for i in result:
        print(str(i))
예제 #2
0
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})