Ejemplo n.º 1
0
    def test_remove_members(self):
        client = Communicator()
        data = {'username': '******', 'password': '******'}
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 5
0
def logout(request):
    """
    Logout view.
    """
    client = Communicator(cookies=request.COOKIES)
    client.logout()
    return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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"})
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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"})
Ejemplo n.º 12
0
def logout(request):
    """
    Logout view.
    """
    client = Communicator(cookies=request.COOKIES)
    client.logout()
    return HttpResponseRedirect(reverse('index'))
Ejemplo n.º 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)
Ejemplo n.º 14
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {"username": "******", "password": "******"}
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Ejemplo n.º 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))
Ejemplo n.º 16
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {'username': '******', 'password': '******'}
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Ejemplo n.º 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"})
Ejemplo n.º 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)
Ejemplo n.º 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"})
Ejemplo n.º 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)
Ejemplo n.º 21
0
    def test_remove_members(self):
        client = Communicator()
        data = {"username": "******", "password": "******"}
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Ejemplo n.º 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'))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 25
0
 def test_login(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     cookies = client.login(data)
     print(cookies)
Ejemplo n.º 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'))
Ejemplo n.º 27
0
 def test_login(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     cookies = client.login(data)
     print(cookies)
Ejemplo n.º 28
0
 def test_delete_image(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     client.delete_image(1, 2)
Ejemplo n.º 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)
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 38
0
 def test_project_lists(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     projects = client.project_lists()
     print(projects)
Ejemplo n.º 39
0
    def test_clear_volume(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        client.clear_volume(1, 5)
Ejemplo n.º 40
0
 def test_project_lists(self):
     client = Communicator()
     data = {
         'username': '******',
         'password': '******'
     }
     client.login(data)
     projects = client.project_lists()
     print(projects)
Ejemplo n.º 41
0
    def test_remove_members(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        res = client.remove_members(2, [1, 2])
        print(res)
Ejemplo n.º 42
0
    def test_delete_resource_module(self):
        client = Communicator()
        data = {
            'username': '******',
            'password': '******'
        }
        client.login(data)

        res = client.delete_resource_module(2)
        print(res)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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({})
Ejemplo n.º 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))
Ejemplo n.º 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}))
Ejemplo n.º 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'))
Ejemplo n.º 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}))
Ejemplo n.º 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'))
Ejemplo n.º 52
0
 def test_registry(self):
     data = {
         'username': '******',
         'password': '******',
         'email': '*****@*****.**',
         'is_staff': False,
         'is_active': True
     }
     client = Communicator()
     cookies = client.registry(data)
     print(cookies)
Ejemplo n.º 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))
Ejemplo n.º 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}))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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"})
Ejemplo n.º 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))
Ejemplo n.º 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"})
Ejemplo n.º 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))