Exemplo n.º 1
0
 def save(self, commit=True, **kwargs):
     data = dict(self.cleaned_data)
     data['precursor_id'] = self.instance.id
     is_new = self.instance.id is None
     data['owner'] = self.user if is_new else self.instance.owner
     data['resource_policies'] = self.cleaned_resource_policies()
     data['request_user'] = self.user
     submit_application(**data)
Exemplo n.º 2
0
 def save(self, commit=True):
     data = dict(self.cleaned_data)
     data['precursor_id'] = self.instance.id
     is_new = self.instance.id is None
     data['owner'] = self.user if is_new else self.instance.owner
     data['resource_policies'] = self.cleaned_resource_policies()
     data['request_user'] = self.user
     submit_application(**data)
Exemplo n.º 3
0
 def save(self, commit=True, **kwargs):
     data = dict(self.cleaned_data)
     is_new = self.instance.id is None
     data['project_id'] = self.instance.chain.id if not is_new else None
     data['owner'] = self.user if is_new else self.instance.owner
     data['resources'] = self.cleaned_resource_policies()
     data['request_user'] = self.user
     submit_application(**data)
Exemplo n.º 4
0
def submit(name, user_id, project_id=None):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    project = (Project.objects.get(
        id=project_id) if project_id is not None else None)
    ok, limit = check_pending_app_quota(owner, project=project)
    if not ok:
        raise ProjectForbidden('Limit %s reached', limit)

    resource_policies = {'cyclades.network.private': {'member_capacity': 5}}
    data = {
        'owner': owner,
        'name': name,
        'project_id': project_id,
        'end_date': datetime.now() + timedelta(days=1),
        'member_join_policy': 1,
        'member_leave_policy': 1,
        'resources': resource_policies,
        'request_user': owner
    }

    app = submit_application(**data)
    return app.id, app.chain_id
Exemplo n.º 5
0
def submit(name, user_id, project_id=None):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    project = (Project.objects.get(id=project_id) if project_id is not None
               else None)
    ok, limit = check_pending_app_quota(owner, project=project)
    if not ok:
        raise ProjectForbidden('Limit %s reached', limit)

    resource_policies = {'cyclades.network.private': {'member_capacity': 5,
                                                      'project_capacity': 10}}
    data = {'owner': owner,
            'name': name,
            'project_id': project_id,
            'end_date': datetime.now() + timedelta(days=1),
            'member_join_policy': 1,
            'member_leave_policy': 1,
            'resources': resource_policies,
            'request_user': owner
            }

    app = submit_application(**data)
    return app.id, app.chain_id
Exemplo n.º 6
0
def submit(name, user_id, prec):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    precursor = (ProjectApplication.objects.get(id=prec)
                 if prec is not None
                 else None)

    ok, limit = check_pending_app_quota(owner, precursor=precursor)
    if not ok:
        raise PermissionDenied('Limit %s reached', limit)

    resource_policies = [('cyclades.network.private', 5)]
    data = {'owner': owner,
            'name': name,
            'precursor_id': prec,
            'end_date': datetime.now() + timedelta(days=1),
            'member_join_policy': 1,
            'member_leave_policy': 1,
            'resource_policies': resource_policies,
            'request_user': owner
            }

    app = submit_application(**data)
    return app.id
Exemplo n.º 7
0
def submit(name, user_id, prec):
    try:
        owner = AstakosUser.objects.get(id=user_id)
    except AstakosUser.DoesNotExist:
        raise AttributeError('user does not exist')

    precursor = (ProjectApplication.objects.get(
        id=prec) if prec is not None else None)

    ok, limit = check_pending_app_quota(owner, precursor=precursor)
    if not ok:
        raise PermissionDenied('Limit %s reached', limit)

    resource_policies = [('cyclades.network.private', 5)]
    data = {
        'owner': owner,
        'name': name,
        'precursor_id': prec,
        'end_date': datetime.now() + timedelta(days=1),
        'member_join_policy': 1,
        'member_leave_policy': 1,
        'resource_policies': resource_policies,
        'request_user': owner
    }

    app = submit_application(**data)
    return app.id
Exemplo n.º 8
0
    def test_get_project_modifications(self):
        project = self.project
        t2 = project.end_date + timedelta(days=12)
        common_output = {
            'resources': [],
            'policies': [],
            'details': []
        }
        common_app_data = {
            'owner': self.user,
            'project_id': project.id,
            'request_user': self.user,
            'resources': {}
        }

        # test output for change in project details
        last_app_data1 = common_app_data.copy()
        last_app_data1.update({
            'name': 'test-new.gr',
            'description': u'δεσκρίπτιον2',
            'end_date': t2,
        })
        with transaction.atomic():
            last_app1 = submit_application(**last_app_data1)
        project = Project.objects.get(id=project.id)
        output_details = common_output.copy()
        output_details.update({
            'details': [{
                'label': 'name',
                'new': 'test-new.gr',
                'old': 'test.pr',
            }, {
                'label': 'description',
                'new': u'δεσκρίπτιον2',
                'old': u'δεσκρίπτιον',
            }, {
                'label': 'end date',
                'new': t2,
                'old': project.end_date,
                'diff': timedelta(days=12)
            }],
        })
        input_details = admin_tags.get_project_modifications(project)
        self.assertEqual(input_details, output_details)

        # test output for change in project policies
        last_app_data2 = common_app_data.copy()
        last_app_data2.update({
            'limit_on_members_number': 42
        })
        with transaction.atomic():
            last_app2 = submit_application(**last_app_data2)
        project = Project.objects.get(id=project.id)
        output_policies = common_output.copy()
        output_policies.update({
            'policies': [{
                'label': 'max members',
                'new': 42,
                'old': 5,
                'diff': 37,
            }],
        })
        input_policies = admin_tags.get_project_modifications(project)
        self.assertEqual(input_policies, output_policies)

        # test output for change in project resources
        last_app_data3 = common_app_data.copy()
        last_app_data3.update({
            'resources': {u"σέρβις1.ρίσορς11": {
                'project_capacity': 1025,
                'member_capacity': 511}}
        })
        with transaction.atomic():
            last_app3 = submit_application(**last_app_data3)
        project = Project.objects.get(id=project.id)
        output_resources = common_output.copy()
        output_resources.update({
            'resources': [{
                'label': u"σέρβις1.ρίσορς11s",
                'new_member': '511',
                'old_member': '512',
                'diff_member': '-1',
                'new_project': '1025',
                'old_project': '1024',
                'diff_project': '+1'
            }],
        })
        input_resources = admin_tags.get_project_modifications(project)
        self.assertEqual(input_resources, output_resources)