def _modify_projects(projects, request): upds = {} for key in MODIFY_KEYS: value = request.get(key) if value is not None: upds[key] = value projects.update(**upds) changed_resources = set() pquotas = [] req_policies = request.get("resources", {}) req_policies = validate_resource_policies(req_policies, admin=True) for project in projects: for resource, m_capacity, p_capacity in req_policies: changed_resources.add(resource) pquotas.append( ProjectResourceQuota( project=project, resource=resource, member_capacity=m_capacity, project_capacity=p_capacity)) ProjectResourceQuota.objects.\ filter(project__in=projects, resource__in=changed_resources).delete() ProjectResourceQuota.objects.bulk_create(pquotas) quotas.qh_sync_projects(projects)
def _apply_modifications(project, application): FIELDS = [ ("owner", "owner"), ("name", "realname"), ("homepage", "homepage"), ("description", "description"), ("end_date", "end_date"), ("member_join_policy", "member_join_policy"), ("member_leave_policy", "member_leave_policy"), ("limit_on_members_number", "limit_on_members_number"), ("private", "private"), ] changed = False for appfield, projectfield in FIELDS: value = getattr(application, appfield) if value is not None: changed = True setattr(project, projectfield, value) if changed: project.save() grants = application.projectresourcegrant_set.all() pquotas = [] resources = [] for grant in grants: resources.append(grant.resource) pquotas.append( ProjectResourceQuota(project=project, resource=grant.resource, member_capacity=grant.member_capacity, project_capacity=grant.project_capacity)) ProjectResourceQuota.objects.\ filter(project=project, resource__in=resources).delete() ProjectResourceQuota.objects.bulk_create(pquotas)
def set_project_resources(project, policies): grants = [] for resource, m_capacity, p_capacity in policies: grants.append( ProjectResourceQuota(project=project, resource=resource, member_capacity=m_capacity, project_capacity=p_capacity)) ProjectResourceQuota.objects.bulk_create(grants)
def qh_sync_new_resource(resource): projects = Project.objects.filter(state__in=Project.INITIALIZED_STATES).\ select_for_update() entries = [] for project in projects: limit = pick_limit_scheme(project, resource) entries.append( ProjectResourceQuota(project=project, resource=resource, project_capacity=limit, member_capacity=limit)) ProjectResourceQuota.objects.bulk_create(entries) qh_sync_projects(projects, resource=resource.name)
def _fill_from_skeleton(project): current_resources = set( ProjectResourceQuota.objects.filter(project=project).values_list( "resource_id", flat=True)) resources = Resource.objects.all() new_quotas = [] for resource in resources: if resource.id not in current_resources: limit = quotas.pick_limit_scheme(project, resource) new_quotas.append( ProjectResourceQuota(project=project, resource=resource, member_capacity=limit, project_capacity=limit)) ProjectResourceQuota.objects.bulk_create(new_quotas)