def test_remove_members(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) res = client.remove_members(2, [1, 2]) print(res)
def user_permission(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } project_id = kwargs['pid'] client = Communicator(cookies=request.COOKIES) context['project'] = client.get_project(project_id=project_id) all_users = client.list_users() selected_users = client.list_members(project_id=project_id) left_users = [] for user in all_users: user_id = user['id'] flag = False for item in selected_users: if item['id'] == user_id: flag = True break if not flag: left_users.append(user) context['left_users'] = left_users context['selected_users'] = selected_users return render(request, 'website/user_permission.html', context, RequestContext(request))
def test_get_application_username(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) res = client.get_application_username(project_id=2, application_id=5) print(res)
def list_apps(request, *args, **kwargs): project_id = request.GET['project'] client = Communicator(cookies=request.COOKIES) apps = client.list_apps_for_project(project_id=project_id) data = [{'id': app['id'], 'name': app['name']} for app in apps] return JsonResponse(data, safe=False)
def logout(request): """ Logout view. """ client = Communicator(cookies=request.COOKIES) client.logout() return HttpResponseRedirect(reverse('index'))
def test_get_application_username(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) res = client.get_application_username(project_id=2, application_id=5) print(res)
def test_get_pod_logs(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) res = client.get_pod_logs(1, "project0-nginx-test-n9oky", 20) print(res)
def create_resource_module(request, *args, **kwargs): if not kwargs['is_staff']: return JsonResponse({"error": "no permission"}) # Check validation form = ResourceModuleForm(request.POST) if not form.is_valid(): return JsonResponse({"error": "data invalid"}) data = { 'name': form.cleaned_data['name'], 'cpu': form.cleaned_data['cpu'], 'cpu_unit': form.cleaned_data['cpu_unit'], 'memory': form.cleaned_data['memory'], 'memory_unit': form.cleaned_data['memory_unit'] } logger.debug(data) client = Communicator(cookies=request.COOKIES) ok = client.create_resource_module(data) if ok: return JsonResponse({"success": "success"}) else: return JsonResponse({"error": "failed"})
def test_get_image(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) res = client.get_image(project_id=2, image_id=12) print(res)
def test_get_image(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) res = client.get_image(project_id=2, image_id=12) print(res)
def test_delete_resource_module(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) res = client.delete_resource_module(2) print(res)
def show_image_detail(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } project_id = kwargs['pid'] image_id = kwargs['iid'] client = Communicator(cookies=request.COOKIES) context['project'] = client.get_project(project_id=project_id) context['image'] = client.get_image(project_id=project_id, image_id=image_id) context['resource_limits'] = client.get_resourcelimits() volumes = client.volume_lists(project_id=project_id) simple_volumes = [] for volume in volumes: if volume.get('app'): continue simple_volume = {} simple_volume['id'] = volume['id'] simple_volume['name'] = volume['name'] simple_volumes.append(simple_volume) context['volumes'] = json.dumps(simple_volumes) return render(request, 'website/image_detail.html', context, RequestContext(request))
def test_delete_resource_module(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) res = client.delete_resource_module(2) print(res)
def create_volume(request, *args, **kwargs): project_id = kwargs['pid'] #TODO: Check validation form = VolumeForm(request.POST) if not form.is_valid(): return JsonResponse({"error": "data invalid"}) data = { 'project': int(project_id), 'name': form.cleaned_data['name'], 'desc': form.cleaned_data['desc'], 'capacity': int(form.cleaned_data['capacity']), 'capacity_unit': form.cleaned_data['capacity_unit'] } logger.debug(data) client = Communicator(cookies=request.COOKIES) ok = client.create_volume(project_id, data) if ok: return JsonResponse({"success": "success"}) else: return JsonResponse({"error": "failed"})
def test_upload_to_volume(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) files = "/home/wangtao/hummer-test/buildfiles/myubuntu/myubuntu.tar" client.upload_to_volume(1, 5, files)
def test_get_pod_logs(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) res = client.get_pod_logs(1, "project0-nginx-test-n9oky", 20) print(res)
def test_remove_members(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) res = client.remove_members(2, [1, 2]) print(res)
def delete_user(request, *args, **kwargs): """ Delete user only for admin user. """ uid = kwargs['uid'] client = Communicator(cookies=request.COOKIES) client.delete_user(user_id=uid) return HttpResponseRedirect(reverse('user-management'))
def list_projects(request, *args, **kwargs): user_id = request.GET['user'] client = Communicator(cookies=request.COOKIES) projects = client.list_projects_for_user(user_id=user_id) data = [{'id': project['id'], 'name': project['name']} for project in projects] return JsonResponse(data, safe=False)
def test_login(self): client = Communicator() data = { 'username': '******', 'password': '******' } cookies = client.login(data) print(cookies)
def delete_project(request, *args, **kwargs): project_id = kwargs['pid'] client = Communicator(cookies=request.COOKIES) ok = client.delete_project(project_id) if ok: return HttpResponseRedirect(reverse('dashboard')) return HttpResponseRedirect(reverse('dashboard'))
def test_delete_image(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) client.delete_image(1, 2)
def test_clone_public_image(self): client = Communicator() data = {"username": "******", "password": "******"} client.login(data) data = {"pid": 1, "name": "myubuntu", "version": "14.04"} res = client.clone_public_image(12, data) print(res)
def test_clone_public_image(self): client = Communicator() data = {'username': '******', 'password': '******'} client.login(data) data = {'pid': 1, 'name': 'myubuntu', 'version': '14.04'} res = client.clone_public_image(12, data) print(res)
def is_authenticated(request): """ Check that the user is authenticated, return is_login and username if necessary. """ cookies = {'sessionid': request.COOKIES.get('sessionid', None)} client = Communicator(cookies=cookies) ok, username, is_staff = client.is_authenticated() return ok, username, is_staff
def get_logs_of_pod(request, *args, **kwargs): project_id = kwargs['pid'] pod = kwargs['pod'] tail = int(request.GET.get('tail', 20)) client = Communicator(cookies=request.COOKIES) response = client.get_pod_logs(project_id=project_id, pod_name=pod, tail=tail) return JsonResponse('\n'.join(response), safe=False)
def is_authenticated(request): """ Check that the user is authenticated, return is_login and username if necessary. """ cookies = {'sessionid': request.COOKIES.get('sessionid', None)} client = Communicator(cookies=cookies) ok, username, is_staff= client.is_authenticated() return ok, username, is_staff
def test_project_lists(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) projects = client.project_lists() print(projects)
def test_clear_volume(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) client.clear_volume(1, 5)
def test_remove_members(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) res = client.remove_members(2, [1, 2]) print(res)
def test_delete_resource_module(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) res = client.delete_resource_module(2) print(res)
def test_get_pod_logs(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) res = client.get_pod_logs(1, "project0-nginx-test-n9oky", 20) print(res)
def test_get_image(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) res = client.get_image(project_id=2, image_id=12) print(res)
def test_get_application_username(self): client = Communicator() data = { 'username': '******', 'password': '******' } client.login(data) res = client.get_application_username(project_id=2, application_id=5) print(res)
def remove_memebers(request, *args, **kwargs): """ Remove members from project. """ project_id = kwargs['pid'] users = request.REQUEST.getlist('users') client = Communicator(cookies=request.COOKIES) client.remove_members(project_id=project_id, users=users) return JsonResponse({})
def list_publics(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } client = Communicator(cookies=request.COOKIES) context['publics'] = client.get_public_images() return render(request, 'website/public_images.html', context, RequestContext(request))
def delete_volume(request, *args, **kwargs): project_id = kwargs['pid'] volume_id = kwargs['vid'] client = Communicator(cookies=request.COOKIES) ok = client.delete_volume(project_id=project_id, volume_id=volume_id) if ok: return HttpResponseRedirect( reverse('list-volumes', kwargs={'pid': project_id})) return HttpResponseRedirect( reverse('list-volumes', kwargs={'pid': project_id}))
def delete_resource_module(request, *args, **kwargs): module_id = kwargs['mid'] if not kwargs['is_staff']: return HttpResponseRedirect(reverse('dashboard')) client = Communicator(cookies=request.COOKIES) ok = client.delete_resource_module(module_id=module_id) if ok: return HttpResponseRedirect(reverse('resource-module')) return HttpResponseRedirect(reverse('resource-module'))
def delete_image(request, *args, **kwargs): project_id = kwargs['pid'] image_id = kwargs['iid'] client = Communicator(cookies=request.COOKIES) ok = client.delete_image(project_id=project_id, image_id=image_id) if ok: return HttpResponseRedirect(reverse('list-images', kwargs={'pid': project_id})) return HttpResponseRedirect(reverse('list-images', kwargs={'pid': project_id}))
def test_registry(self): data = { 'username': '******', 'password': '******', 'email': '*****@*****.**', 'is_staff': False, 'is_active': True } client = Communicator() cookies = client.registry(data) print(cookies)
def delete_application(request, *args, **kwargs): project_id = kwargs['pid'] application_id = kwargs['aid'] client = Communicator(cookies=request.COOKIES) ok = client.delete_application(project_id=project_id, application_id=application_id) if ok: return HttpResponseRedirect( reverse('list-applications', kwargs={'pid': project_id})) return HttpResponseRedirect( reverse('list-applications', kwargs={'pid': project_id}))
def list_volumes(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } project_id = kwargs['pid'] client = Communicator(cookies=request.COOKIES) context['project'] = client.get_project(project_id=project_id) context['volumes'] = client.volume_lists(project_id=project_id) return render(request, 'website/volumes.html', context, RequestContext(request))
def project_intro(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } project_id = kwargs['pid'] client = Communicator(cookies=request.COOKIES) context['project'] = client.get_project(project_id=project_id) context['members'] = client.list_members(project_id=project_id) return render(request, 'website/project_intro.html', context, RequestContext(request))
def clear_volume(request, *args, **kwargs): """ Clear data of volume. """ pid = kwargs['pid'] vid = kwargs['vid'] client = Communicator(cookies=request.COOKIES) ok = client.clear_volume(pid, vid) if ok: return JsonResponse({"success": "success"}) else: return JsonResponse({"error": "failed"})
def show_public_detail(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } public_id = kwargs['puid'] client = Communicator(cookies=request.COOKIES) context['projects'] = client.project_lists() context['image'] = client.get_public_image(public_id=public_id) return render(request, 'website/public_image_details.html', context, RequestContext(request))
def upload_volume(request, *args, **kwargs): """ Upload data into volume. """ pid = kwargs['pid'] vid = kwargs['vid'] client = Communicator(cookies=request.COOKIES) ok = client.upload_to_volume(pid, vid, request.FILES['file']) if ok: return JsonResponse({"success": "success"}) else: return JsonResponse({"error": "failed"})
def resource_module(request, *args, **kwargs): context = { 'username': kwargs.get('username'), 'is_staff': kwargs.get('is_staff') } if not context['is_staff']: return HttpResponseRedirect(reverse('dashboard')) client = Communicator(cookies=request.COOKIES) context['modules'] = client.list_resource_modules() return render(request, 'website/resource_module.html', context, RequestContext(request))