Ejemplo n.º 1
0
def get_tag(tag_name, controller_ip):
    try:
        if r_server.sismember('tags:%s' % controller_ip, tag_name):
            tag = {}
            tag['name'] = tag_name
            tag['address'] = r_server.hget('tag:%s:%s' % (controller_ip, tag_name), 'address')
            tag['type'] = r_server.hget('tag:%s:%s' % (controller_ip, tag_name), 'type')
            tag['controller_ip'] = r_server.hget('tag:%s:%s' % (controller_ip, tag_name), 'controller_ip')
            return tag
        else:
            return None
    except RedisError:
        return None
Ejemplo n.º 2
0
def delete_tag(tag_name, controller_ip):
    try:
        if r_server.sismember('tags:%s' % controller_ip, tag_name):
            print('removing tag: %s, with ip: %s' % (tag_name, controller_ip))
            r_server.srem('tags:%s' % controller_ip, tag_name)
            r_server.delete('tag:%s:%s' % (controller_ip, tag_name))
            if not r_server.smembers('tags:%s' % controller_ip):
                r_server.srem('controllers', controller_ip)
                print('No more tags for the controller, removing controller')
            return True
        else:
            return False
    except RedisError:
        return False