Revision a53ec93b snf-astakos-app/astakos/im/management/commands/project-show.py
b/snf-astakos-app/astakos/im/management/commands/project-show.py | ||
---|---|---|
38 | 38 |
from snf_django.management.commands import SynnefoCommand |
39 | 39 |
from snf_django.management import utils |
40 | 40 |
from astakos.im.models import ProjectApplication, Project |
41 |
from astakos.im import quotas |
|
41 | 42 |
from ._common import show_resource_value, style_options, check_style |
42 | 43 |
from synnefo.util import units |
43 | 44 |
|
... | ... | |
60 | 61 |
default=False, |
61 | 62 |
help=("Show a list of project memberships") |
62 | 63 |
), |
64 |
make_option('--quota', |
|
65 |
action='store_true', |
|
66 |
dest='list_quotas', |
|
67 |
default=False, |
|
68 |
help="List project quota"), |
|
63 | 69 |
make_option('--unit-style', |
64 | 70 |
default='mb', |
65 | 71 |
help=("Specify display unit for resource values " |
... | ... | |
81 | 87 |
id_ = args[0] |
82 | 88 |
if True: |
83 | 89 |
project = get_chain_state(id_) |
84 |
self.print_project(project) |
|
90 |
self.print_project(project, show_quota)
|
|
85 | 91 |
if show_members and project is not None: |
86 | 92 |
self.stdout.write("\n") |
87 | 93 |
fields, labels = members_fields(project) |
... | ... | |
105 | 111 |
self.pprint_dict(app_info) |
106 | 112 |
self.print_app_resources(app) |
107 | 113 |
|
108 |
def print_project(self, project): |
|
114 |
def print_project(self, project, show_quota=False):
|
|
109 | 115 |
self.pprint_dict(project_fields(project)) |
110 |
self.print_resources(project) |
|
116 |
quota = (quotas.get_project_quota(project) |
|
117 |
if show_quota else None) |
|
118 |
self.print_resources(project, quota=quota) |
|
111 | 119 |
|
112 |
def print_resources(self, project): |
|
120 |
def print_resources(self, project, quota=None):
|
|
113 | 121 |
policies = project.projectresourcequota_set.all() |
114 |
fields, labels = resource_fields(policies, self.unit_style) |
|
122 |
fields, labels = resource_fields(policies, quota, self.unit_style)
|
|
115 | 123 |
if fields: |
116 | 124 |
self.stdout.write("\n") |
117 | 125 |
self.pprint_table(fields, labels, title="Resource limits") |
... | ... | |
131 | 139 |
raise CommandError("Project with id %s not found." % project_id) |
132 | 140 |
|
133 | 141 |
|
134 |
def resource_fields(policies, style): |
|
135 |
labels = ('name', 'description', 'max per member') |
|
142 |
def resource_fields(policies, quota, style): |
|
143 |
labels = ('name', 'max per member', 'max per project') |
|
144 |
if quota: |
|
145 |
labels += ('usage',) |
|
136 | 146 |
collect = [] |
137 | 147 |
for policy in policies: |
138 | 148 |
name = policy.resource.name |
139 |
desc = policy.resource.desc |
|
140 | 149 |
capacity = policy.member_capacity |
141 |
collect.append((name, desc, |
|
142 |
show_resource_value(capacity, name, style))) |
|
150 |
p_capacity = policy.project_capacity |
|
151 |
row = (name, |
|
152 |
show_resource_value(capacity, name, style), |
|
153 |
show_resource_value(p_capacity, name, style)) |
|
154 |
if quota: |
|
155 |
r_quota = quota.get(name) |
|
156 |
usage = r_quota.get('project_usage') |
|
157 |
row += (show_resource_value(usage, name, style),) |
|
158 |
collect.append(row) |
|
143 | 159 |
return collect, labels |
144 | 160 |
|
145 | 161 |
|
Also available in: Unified diff