Example #1
0
def add(request, path='/'):
    stat = zkutils._get_stat(zh, path)
    if stat:
        return HttpResponse(jdumps({'error': 'Node already exists'}))
    control_masters = list(zkconfig.control_machines)
    control_masters.append("127.0.0.1")
    control_masters.append(socket.gethostbyname(socket.gethostname()))
    default_acl = zkutils.AclSet(["ip:%s:31" %(id) for id in control_masters])
    try:
        ret = zk.create(zh, path, "", default_acl.to_dict())
        if ret == path:
            return HttpResponse(jdumps({'status':'ok'}))
        else:
            return HttpResponse(jdumps({'error':str(ret)}))
    except IOError, errmsg:
        return HttpResponse(jdumps({'error': str(errmsg)}))
Example #2
0
def add(request, path='/'):
    stat = zkutils._get_stat(zh, path)
    if stat:
        return HttpResponse(jdumps({'error': 'Node already exists'}))
    control_masters = list(zkconfig.control_machines)
    control_masters.append("127.0.0.1")
    control_masters.append(socket.gethostbyname(socket.gethostname()))
    default_acl = zkutils.AclSet(["ip:%s:31" % (id) for id in control_masters])
    try:
        ret = zk.create(zh, path, "", default_acl.to_dict())
        if ret == path:
            return HttpResponse(jdumps({'status': 'ok'}))
        else:
            return HttpResponse(jdumps({'error': str(ret)}))
    except IOError, errmsg:
        return HttpResponse(jdumps({'error': str(errmsg)}))
Example #3
0
def children(request, path='/'):
    childrens = []
    data = zkutils._get_children(zh, path)
    if data[0] == False:
        return HttpResponse(jdumps({"error":str(data[1])}))
    for child in data[1]:
        child_path = os.path.join(path, child)
        if child_path == '/zookeeper':
            continue
        if check_path_perm(request, child_path) == False:
            continue
        child_dict = {"text":child, "id": child_path}
        stat = zkutils._get_stat(zh, child_path)
        if stat != False and stat['numChildren'] > 0:
            child_dict['leaf'] = False
        else:
            child_dict['leaf'] = True
        childrens.append(child_dict)
    return HttpResponse(jdumps(childrens))
Example #4
0
File: views.py Project: tczf1128/zk
def add(request, path='/'):
    stat = zkutils._get_stat(zh, path)
    if stat:
        return HttpResponse(jdumps({'error': 'Node already exists'}))
    control_masters = list(zkconfig.control_machines)
    control_masters.append("127.0.0.1")
    control_masters.append(socket.gethostbyname(socket.gethostname()))
    acl_set = zkutils.AclSet(["ip:%s:31" %(id) for id in control_masters])
    if 'acl' in request.POST:
        acl_set.addmany(request.POST['acl'].split())
    node_data = request.POST.get('data', "")
    try:
        ret = zk.create(zh, path, node_data, acl_set.to_dict())
        if ret == path:
            return HttpResponse(jdumps({'status':'ok'}))
        else:
            return HttpResponse(jdumps({'error':str(ret)}))
    except IOError, errmsg:
        return HttpResponse(jdumps({'error': str(errmsg)}))
Example #5
0
def children(request, path='/'):
    childrens = []
    data = zkutils._get_children(zh, path)
    if data[0] == False:
        return HttpResponse(jdumps({"error": str(data[1])}))
    for child in data[1]:
        child_path = os.path.join(path, child)
        if child_path == '/zookeeper':
            continue
        if check_path_perm(request, child_path) == False:
            continue
        child_dict = {"text": child, "id": child_path}
        stat = zkutils._get_stat(zh, child_path)
        if stat != False and stat['numChildren'] > 0:
            child_dict['leaf'] = False
        else:
            child_dict['leaf'] = True
        childrens.append(child_dict)
    return HttpResponse(jdumps(childrens))
Example #6
0
            acl['host'] = hostname
            # javascript conflict with 'id' key.
            acl['acl_id'] = acl['id']
            acl.pop('id')
            node_dict['acl'].append(acl)

    stat,data = zkutils._get(zh,path)
    logging.debug("get data from %s " % path)
    logging.debug("stat: %s " % str(stat))
    logging.debug("data: %s " % str(data))
    if stat != False:
        node_dict['data'] = data
    else:
        node_dict['data'] = "error: Get Node Data Failed"

    stats = zkutils._get_stat(zh,path)
    if stats == False:
        node_dict['stat'] = {"error":'Get Node Stat Failed'}
    else:
        stat_keys = stats.keys()
        # stat_keys.sort()
        for k in stat_keys:
            node_dict['stat'].append({"name":k,"value":stats[k]})
        node_dict['stat'].append({
            'name':'Created Time',
            'value':time.strftime("%F %X", time.localtime(float(stats['ctime']/1000.0)))
        })
        node_dict['stat'].append({
            'name':'Modified Time',
            'value':time.strftime("%F %X", time.localtime(float(stats['mtime']/1000.0)))
        })
Example #7
0
                    hostname = socket.gethostbyaddr(acl['id'])[0]
                except socket.herror, errmsg:
                    hostname = 'Unknow host'
            acl['host'] = hostname
            # javascript conflict with 'id' key.
            acl['acl_id'] = acl['id']
            acl.pop('id')
            node_dict['acl'].append(acl)

    stat, data = zkutils._get(zh, path)
    if stat != False:
        node_dict['data'] = data
    else:
        node_dict['data'] = "error: Get Node Data Failed"

    stats = zkutils._get_stat(zh, path)
    if stats == False:
        node_dict['stat'] = {"error": 'Get Node Stat Failed'}
    else:
        stat_keys = stats.keys()
        # stat_keys.sort()
        for k in stat_keys:
            node_dict['stat'].append({"name": k, "value": stats[k]})
        node_dict['stat'].append({
            'name':
            'Created Time',
            'value':
            time.strftime("%F %X",
                          time.localtime(float(stats['ctime'] / 1000.0)))
        })
        node_dict['stat'].append({