Revision 6c0f4562 snf-astakos-app/astakos/api/quotas.py
b/snf-astakos-app/astakos/api/quotas.py | ||
---|---|---|
142 | 142 |
return serial |
143 | 143 |
|
144 | 144 |
|
145 |
def failed_to_cloudfault(failed): |
|
146 |
serial, reason = failed |
|
147 |
if reason == 'NOTFOUND': |
|
148 |
body = {"code": 404, |
|
149 |
"message": "serial %s does not exist" % serial, |
|
150 |
} |
|
151 |
cloudfault = {"itemNotFound": body} |
|
152 |
elif reason == 'CONFLICT': |
|
153 |
body = {"code": 400, |
|
154 |
"message": "cannot both accept and reject serial %s" % serial, |
|
155 |
} |
|
156 |
cloudfault = {"badRequest": body} |
|
157 |
else: |
|
158 |
raise InternalServerError('Unexpected error') |
|
159 |
return (serial, cloudfault) |
|
145 |
def notFoundCF(serial): |
|
146 |
body = {"code": 404, |
|
147 |
"message": "serial %s does not exist" % serial, |
|
148 |
} |
|
149 |
return {"itemNotFound": body} |
|
150 |
|
|
151 |
|
|
152 |
def conflictingCF(serial): |
|
153 |
body = {"code": 400, |
|
154 |
"message": "cannot both accept and reject serial %s" % serial, |
|
155 |
} |
|
156 |
return {"badRequest": body} |
|
160 | 157 |
|
161 | 158 |
|
162 | 159 |
@csrf_exempt |
... | ... | |
174 | 171 |
result = qh.resolve_pending_commissions(clientkey=client_key, |
175 | 172 |
accept_set=accept, |
176 | 173 |
reject_set=reject) |
177 |
accepted, rejected, failed = result |
|
178 |
cloudfaults = [failed_to_cloudfault(f) for f in failed] |
|
174 |
accepted, rejected, notFound, conflicting = result |
|
175 |
notFound = [(serial, notFoundCF(serial)) for serial in notFound] |
|
176 |
conflicting = [(serial, conflictingCF(serial)) for serial in conflicting] |
|
177 |
cloudfaults = notFound + conflicting |
|
179 | 178 |
data = {'accepted': accepted, |
180 | 179 |
'rejected': rejected, |
181 | 180 |
'failed': cloudfaults |
... | ... | |
217 | 216 |
if accept == reject: |
218 | 217 |
raise BadRequest('Specify either accept or reject action.') |
219 | 218 |
|
220 |
if accept: |
|
221 |
result = qh.accept_commission(clientkey=client_key, |
|
222 |
serial=serial) |
|
223 |
else: |
|
224 |
result = qh.reject_commission(clientkey=client_key, |
|
225 |
serial=serial) |
|
226 |
|
|
219 |
result = qh.resolve_pending_commission(clientkey=client_key, |
|
220 |
serial=serial, |
|
221 |
accept=accept) |
|
227 | 222 |
response = HttpResponse() |
228 | 223 |
if not result: |
229 | 224 |
response.status_code = 404 |
Also available in: Unified diff