Revision 7e4cd6c0 snf-cyclades-app/synnefo/quotas/management/commands/enforce-resources-cyclades.py

b/snf-cyclades-app/synnefo/quotas/management/commands/enforce-resources-cyclades.py
173 173
        overlimit = []
174 174
        viol_id = 0
175 175

  
176
        for resource, handle_resource, resource_type in handlers:
177
            if resource_type not in actions:
178
                actions[resource_type] = OrderedDict()
179
            actual_resources = enforce.get_actual_resources(
180
                resource_type, projects=projects_to_check)
181
            for project, project_quota in qh_project_holdings:
182
                if enforce.skip_check(project, projects_to_check,
183
                                      excluded_projects):
184
                    continue
185
                try:
186
                    qh = util.transform_project_quotas(project_quota)
187
                    qh_value, qh_limit, qh_pending = qh[resource]
188
                except KeyError:
189
                    write("Resource '%s' does not exist in Quotaholder"
190
                          " for project '%s'!\n" %
191
                          (resource, project))
192
                    continue
193
                if qh_pending:
194
                    write("Pending commission for project '%s', "
195
                          "resource '%s'. Skipping\n" %
196
                          (project, resource))
197
                    continue
198
                diff = qh_value - qh_limit
199
                if diff > 0:
200
                    viol_id += 1
201
                    overlimit.append((viol_id, "project", project, "",
202
                                      resource, qh_limit, qh_value))
203
                    relevant_resources = enforce.pick_project_resources(
204
                        actual_resources[project], users=users_to_check,
205
                        excluded_users=excluded_users)
206
                    handle_resource(viol_id, resource, relevant_resources,
207
                                    diff, actions)
176
        if users_to_check is None:
177
            for resource, handle_resource, resource_type in handlers:
178
                if resource_type not in actions:
179
                    actions[resource_type] = OrderedDict()
180
                actual_resources = enforce.get_actual_resources(
181
                    resource_type, projects=projects_to_check)
182
                for project, project_quota in qh_project_holdings:
183
                    if enforce.skip_check(project, projects_to_check,
184
                                          excluded_projects):
185
                        continue
186
                    try:
187
                        qh = util.transform_project_quotas(project_quota)
188
                        qh_value, qh_limit, qh_pending = qh[resource]
189
                    except KeyError:
190
                        write("Resource '%s' does not exist in Quotaholder"
191
                              " for project '%s'!\n" %
192
                              (resource, project))
193
                        continue
194
                    if qh_pending:
195
                        write("Pending commission for project '%s', "
196
                              "resource '%s'. Skipping\n" %
197
                              (project, resource))
198
                        continue
199
                    diff = qh_value - qh_limit
200
                    if diff > 0:
201
                        viol_id += 1
202
                        overlimit.append((viol_id, "project", project, "",
203
                                          resource, qh_limit, qh_value))
204
                        relevant_resources = enforce.pick_project_resources(
205
                            actual_resources[project], users=users_to_check,
206
                            excluded_users=excluded_users)
207
                        handle_resource(viol_id, resource, relevant_resources,
208
                                        diff, actions)
208 209

  
209 210
        for resource, handle_resource, resource_type in handlers:
210 211
            if resource_type not in actions:

Also available in: Unified diff