Revision 6aa9924d snf-cyclades-app/synnefo/quotas/management/commands/enforce-resources-cyclades.py
b/snf-cyclades-app/synnefo/quotas/management/commands/enforce-resources-cyclades.py | ||
---|---|---|
35 | 35 |
from optparse import make_option |
36 | 36 |
from django.db import transaction |
37 | 37 |
|
38 |
from synnefo.lib.ordereddict import OrderedDict |
|
38 | 39 |
from synnefo.quotas import util |
39 | 40 |
from synnefo.quotas import enforce |
40 | 41 |
from synnefo.quotas import errors |
... | ... | |
52 | 53 |
help = """Check and fix quota violations for Cyclades resources. |
53 | 54 |
""" |
54 | 55 |
option_list = SynnefoCommand.option_list + ( |
56 |
make_option("--max-operations", |
|
57 |
help="Limit operations per backend."), |
|
55 | 58 |
make_option("--users", dest="users", |
56 | 59 |
help=("Enforce resources only for the specified list " |
57 | 60 |
"of users, e.g uuid1,uuid2")), |
... | ... | |
100 | 103 |
write = self.stderr.write |
101 | 104 |
fix = options["fix"] |
102 | 105 |
force = options["force"] |
106 |
maxops = options["max_operations"] |
|
107 |
if maxops is not None: |
|
108 |
try: |
|
109 |
maxops = int(maxops) |
|
110 |
except ValueError: |
|
111 |
m = "Expected integer max operations." |
|
112 |
raise CommandError(m) |
|
103 | 113 |
|
104 | 114 |
users = options['users'] |
105 | 115 |
if users is not None: |
... | ... | |
111 | 121 |
except errors.AstakosClientException as e: |
112 | 122 |
raise CommandError(e) |
113 | 123 |
|
124 |
qh_holdings = sorted(qh_holdings.items()) |
|
114 | 125 |
resources = set(h[0] for h in handlers) |
115 | 126 |
dangerous = bool(resources.difference(DEFAULT_RESOURCES)) |
116 | 127 |
|
... | ... | |
119 | 130 |
viol_id = 0 |
120 | 131 |
for resource, handle_resource, resource_type in handlers: |
121 | 132 |
if resource_type not in actions: |
122 |
actions[resource_type] = {}
|
|
133 |
actions[resource_type] = OrderedDict()
|
|
123 | 134 |
actual_resources = enforce.get_actual_resources(resource_type, |
124 | 135 |
users) |
125 |
for user, user_quota in qh_holdings.iteritems():
|
|
136 |
for user, user_quota in qh_holdings: |
|
126 | 137 |
for source, source_quota in user_quota.iteritems(): |
127 | 138 |
try: |
128 | 139 |
qh = util.transform_quotas(source_quota) |
... | ... | |
163 | 174 |
self.confirm() |
164 | 175 |
write("Applying actions. Please wait...\n") |
165 | 176 |
title = "Applied Actions" if fix else "Suggested Actions" |
166 |
log = enforce.perform_actions(actions, fix=fix) |
|
167 |
headers = ("Type", "ID", "State", "Action", "Violation") |
|
177 |
log = enforce.perform_actions(actions, maxops=maxops, fix=fix)
|
|
178 |
headers = ("Type", "ID", "State", "Backend", "Action", "Violation")
|
|
168 | 179 |
if fix: |
169 | 180 |
headers += ("Result",) |
170 | 181 |
pprint_table(self.stderr, log, headers, |
Also available in: Unified diff