def edit_as_text(request, id, path): cluster = get_cluster_or_404(id) zk = ZooKeeper(cluster['rest_url']) node = zk.get(path) if request.method == 'POST': if not request.user.is_superuser: raise PopupException(_('You are not a superuser')) form = EditZNodeForm(request.POST) if form.is_valid(): zk.set(path, form.cleaned_data['data']) return tree(request, id, path) else: form = EditZNodeForm( dict(data=node.get('data64', '').decode('base64').strip(), version=node.get('version', '-1'))) return render( 'edit.mako', request, { 'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(), })
def create(request, id, path): if not request.user.is_superuser: raise PopupException(_('You are not a superuser')) cluster = get_cluster_or_404(id) if request.method == 'POST': form = CreateZNodeForm(request.POST) if form.is_valid(): zk = ZooKeeper(cluster['rest_url']) full_path = ("%s/%s" % (path, form.cleaned_data['name'])).replace( '//', '/') zk.create(full_path, form.cleaned_data['data'], sequence=form.cleaned_data['sequence']) return tree(request, id, path) else: form = CreateZNodeForm() return render( 'create.mako', request, { 'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(), })
def edit_as_base64(request, id, path): cluster = get_cluster_or_404(id) zk = ZooKeeper(cluster['rest_url']) node = zk.get(path) if request.method == 'POST': form = EditZNodeForm(request.POST) if form.is_valid(): # TODO is valid base64 string? data = form.cleaned_data['data'].decode('base64') zk.set(path, data, form.cleaned_data['version']) return tree(request, id, path) else: form = EditZNodeForm(dict(\ data=node.get('data64', ''), version=node.get('version', '-1'))) return render( 'edit.mako', request, { 'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(), })
def tree(request, id, path): cluster = get_cluster_or_404(id) zk = ZooKeeper(cluster['rest_url']) znode = zk.get(path) children = sorted(zk.get_children_paths(path)) return render('tree.mako', request, {'cluster': cluster, 'path': path, 'znode': znode, 'children': children, 'clusters': CLUSTERS.get(),})
def delete(request, id, path): cluster = get_cluster_or_404(id) redir = {} if request.method == 'POST': zk = ZooKeeper(cluster['rest_url']) try: zk.recursive_delete(path) except ZooKeeper.NotFound: pass redir = { 'redirect': reverse('zookeeper:tree', kwargs={'id':id, 'path': path[:path.rindex('/')] or '/'}) } return HttpResponse(json.dumps(redir), mimetype="application/json")
def edit_as_text(request, id, path): cluster = get_cluster_or_404(id) zk = ZooKeeper(cluster['rest_url']) node = zk.get(path) if request.method == 'POST': form = EditZNodeForm(request.POST) if form.is_valid(): zk.set(path, form.cleaned_data['data']) return tree(request, id, path) else: form = EditZNodeForm(dict(data=node.get('data64', '').decode('base64').strip(), version=node.get('version', '-1'))) return render('edit.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
def create(request, id, path): cluster = get_cluster_or_404(id) if request.method == 'POST': form = CreateZNodeForm(request.POST) if form.is_valid(): zk = ZooKeeper(cluster['rest_url']) full_path = ("%s/%s" % (path, form.cleaned_data['name'])).replace('//', '/') zk.create(full_path, form.cleaned_data['data'], sequence = form.cleaned_data['sequence']) return tree(request, id, path) else: form = CreateZNodeForm() return render('create.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})
def delete(request, id, path): if not is_admin(request.user): raise PopupException(_('You are not a superuser')) cluster = get_cluster_or_404(id) redir = {} if request.method == 'POST': zk = ZooKeeper(cluster['rest_url']) try: zk.recursive_delete(path) except ZooKeeper.NotFound: pass redir = { 'redirect': reverse('zookeeper:tree', kwargs={'id':id, 'path': path[:path.rindex('/')] or '/'}) } return JsonResponse(redir)
def edit_as_base64(request, id, path): cluster = get_cluster_or_404(id) zk = ZooKeeper(cluster['rest_url']) node = zk.get(path) if request.method == 'POST': if not request.user.is_superuser: raise PopupException(_('You are not a superuser')) form = EditZNodeForm(request.POST) if form.is_valid(): # TODO is valid base64 string? data = form.cleaned_data['data'].decode('base64') zk.set(path, data, form.cleaned_data['version']) return tree(request, id, path) else: form = EditZNodeForm(dict(\ data=node.get('data64', ''), version=node.get('version', '-1'))) return render('edit.mako', request, {'cluster': cluster, 'path': path, 'form': form, 'clusters': CLUSTERS.get(),})