Revision a53ec93b snf-astakos-app/astakos/im/management/commands/quota-list.py
b/snf-astakos-app/astakos/im/management/commands/quota-list.py | ||
---|---|---|
58 | 58 |
make_option('--overlimit', |
59 | 59 |
action='store_true', |
60 | 60 |
help="Show quota that is over limit"), |
61 |
make_option('--with-custom', |
|
62 |
metavar='True|False', |
|
63 |
help=("Filter quota different from the default or " |
|
64 |
"equal to it")), |
|
65 | 61 |
make_option('--filter-by', |
66 | 62 |
help="Filter by field; " |
67 | 63 |
"e.g. \"user=uuid,usage>=10M,base_quota<inf\""), |
... | ... | |
71 | 67 |
) |
72 | 68 |
|
73 | 69 |
QHFLT = { |
74 |
"total_quota": ("limit", filtering.parse_with_unit),
|
|
70 |
"limit": ("limit", filtering.parse_with_unit),
|
|
75 | 71 |
"usage": ("usage_max", filtering.parse_with_unit), |
76 | 72 |
"user": ("holder", lambda x: x), |
77 | 73 |
"resource": ("resource", lambda x: x), |
78 | 74 |
"source": ("source", lambda x: x), |
79 | 75 |
} |
80 | 76 |
|
81 |
INITFLT = { |
|
82 |
"base_quota": ("capacity", filtering.parse_with_unit), |
|
83 |
} |
|
84 |
|
|
85 | 77 |
@transaction.commit_on_success |
86 | 78 |
def handle(self, *args, **options): |
87 | 79 |
output_format = options["output_format"] |
... | ... | |
95 | 87 |
else: |
96 | 88 |
filters = [] |
97 | 89 |
|
98 |
QHQ, INITQ = Q(), Q()
|
|
90 |
QHQ = Q()
|
|
99 | 91 |
for flt in filters: |
100 | 92 |
q = filtering.make_query(flt, self.QHFLT) |
101 | 93 |
if q is not None: |
102 | 94 |
QHQ &= q |
103 |
q = filtering.make_query(flt, self.INITFLT) |
|
104 |
if q is not None: |
|
105 |
INITQ &= q |
|
106 | 95 |
|
107 | 96 |
overlimit = bool(options["overlimit"]) |
108 | 97 |
if overlimit: |
109 | 98 |
QHQ &= Q(usage_max__gt=F("limit")) |
110 | 99 |
|
111 |
with_custom = options["with_custom"] |
|
112 |
if with_custom is not None: |
|
113 |
qeq = Q(capacity=F("resource__uplimit")) |
|
114 |
try: |
|
115 |
INITQ &= ~qeq if utils.parse_bool(with_custom) else qeq |
|
116 |
except ValueError as e: |
|
117 |
raise CommandError(e) |
|
118 |
|
|
119 | 100 |
users = AstakosUser.objects.accepted() |
120 |
qh_quotas, astakos_i = list_user_quotas(
|
|
121 |
users, qhflt=QHQ, initflt=INITQ)
|
|
101 |
qh_quotas = list_user_quotas( |
|
102 |
users, qhflt=QHQ) |
|
122 | 103 |
|
123 | 104 |
if displayname: |
124 | 105 |
info = {} |
... | ... | |
128 | 109 |
info = None |
129 | 110 |
|
130 | 111 |
print_data, labels = common.show_quotas( |
131 |
qh_quotas, astakos_i, info, style=unit_style)
|
|
112 |
qh_quotas, info, style=unit_style) |
|
132 | 113 |
utils.pprint_table(self.stdout, print_data, labels, output_format) |
Also available in: Unified diff