Пример #1
0
    def test_remove_members(self):
        client = Communicator()
        data = {'username': '******', 'password': '******'}
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Пример #2
0
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))
Пример #3
0
    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)
Пример #4
0
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)
Пример #5
0
def logout(request):
    """
    Logout view.
    """
    client = Communicator(cookies=request.COOKIES)
    client.logout()
    return HttpResponseRedirect(reverse('index'))
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
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"})
Пример #9
0
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))
Пример #10
0
    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)
Пример #11
0
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"})
Пример #12
0
def logout(request):
    """
    Logout view.
    """
    client = Communicator(cookies=request.COOKIES)
    client.logout()
    return HttpResponseRedirect(reverse('index'))
Пример #13
0
    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)
Пример #14
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {"username": "******", "password": "******"}
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Пример #15
0
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))
Пример #16
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {'username': '******', 'password': '******'}
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Пример #17
0
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"})
Пример #18
0
    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)
Пример #19
0
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"})
Пример #20
0
    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)
Пример #21
0
    def test_remove_members(self):
        client = Communicator()
        data = {"username": "******", "password": "******"}
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Пример #22
0
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'))
Пример #23
0
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)
Пример #24
0
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)
Пример #25
0
 def test_login(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     cookies = client.login(data)
     print(cookies)
Пример #26
0
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'))
Пример #27
0
 def test_login(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     cookies = client.login(data)
     print(cookies)
Пример #28
0
 def test_delete_image(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     client.delete_image(1, 2)
Пример #29
0
    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)
Пример #30
0
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'))
Пример #31
0
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'))
Пример #32
0
    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)
Пример #33
0
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)
Пример #34
0
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
Пример #35
0
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)
Пример #36
0
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)
Пример #37
0
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
Пример #38
0
 def test_project_lists(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     projects = client.project_lists()
     print(projects)
Пример #39
0
    def test_clear_volume(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        client.clear_volume(1, 5)
Пример #40
0
 def test_project_lists(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     projects = client.project_lists()
     print(projects)
Пример #41
0
    def test_remove_members(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Пример #42
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Пример #43
0
    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)
Пример #44
0
    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)
Пример #45
0
    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)
Пример #46
0
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({})
Пример #47
0
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))
Пример #48
0
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}))
Пример #49
0
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'))
Пример #50
0
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}))
Пример #51
0
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'))
Пример #52
0
 def test_registry(self):
     data = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**',
         'is_staff': False,
         'is_active': True
     }
     client = Communicator()
     cookies = client.registry(data)
     print(cookies)
Пример #53
0
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))
Пример #54
0
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}))
Пример #55
0
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))
Пример #56
0
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))
Пример #57
0
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"})
Пример #58
0
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))
Пример #59
0
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"})
Пример #60
0
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))