def display_resource_usage_for_project(resource, project): usage_map = presentation.USAGE_TAG_MAP quota = quotas.get_project_quota(project).get(resource.name, None) if not quota: return "No usage" cls = '' usage = quota['project_usage'] limit = quota['project_limit'] if limit == 0 and usage == 0: return "--" usage_perc = "%d" % ((float(usage) / limit) * 100) if limit else "100" _keys = usage_map.keys() _keys.reverse() closest = filter(lambda x: int(x) <= int(usage_perc), _keys)[0] cls = usage_map[closest] usage_display = units.show(usage, resource.unit) usage_perc_display = "%s%%" % usage_perc resp = """<span class="%s policy-diff">%s (%s)</span>""" % \ (cls, usage_perc_display, usage_display) return mark_safe(resp)
def get_policies(inst, quota_dict = None): policies = inst.projectresourcequota_set.all().prefetch_related('resource') policy_list = [] for p in policies: r = p.resource if not quota_dict: quota_dict = get_project_quota(inst) if not quota_dict: usage = 0 else: usage = quota_dict[r.name]['project_usage'] if not is_resource_useful(r, p.project_capacity, usage): continue policy_list.append(p) return policy_list
def get_project_usage(inst): """Return requested project quota type. Accepted stats are: 'project_limit', 'project_pending', 'project_usage'. Note that the output is sanitized, meaning that stats that correspond to infinite or zero limits will not be returned. """ resource_list = [] quota_dict = get_project_quota(inst) if not quota_dict: return [] policies = get_policies(inst, quota_dict) for p in policies: r = p.resource value = units.show(quota_dict[r.name]['project_usage'], r.unit) resource_list.append((r.report_desc, value)) return resource_list
def get_project_usage(inst): """Return requested project quota type. Accepted stats are: 'project_limit', 'project_pending', 'project_usage'. Note that the output is sanitized, meaning that stats that correspond to infinite or zero limits will not be returned. """ resource_list = [] quota_dict = get_project_quota(inst) if not quota_dict: return [] policies = get_policies(inst) for p in policies: r = p.resource value = units.show(quota_dict[r.name]['project_usage'], r.unit) resource_list.append((r.report_desc, value)) return resource_list
def print_project(self, project, show_quota=False): self.pprint_dict(project_fields(project)) quota = (quotas.get_project_quota(project) if show_quota else None) self.print_resources(project, quota=quota)