Commit f12f72b1 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Catch QuotaLimit exception when reconciling resources

This can happen, if the actual usage registered by a service exceeds
the quota limit.
Advise the user to try the --force option.
parent fae79181
...@@ -41,6 +41,7 @@ from astakos.im.models import Service, AstakosUser ...@@ -41,6 +41,7 @@ from astakos.im.models import Service, AstakosUser
from astakos.im.quotas import service_get_quotas, SYSTEM from astakos.im.quotas import service_get_quotas, SYSTEM
from astakos.im.functions import count_pending_app from astakos.im.functions import count_pending_app
import astakos.quotaholder_app.callpoint as qh import astakos.quotaholder_app.callpoint as qh
import astakos.quotaholder_app.exception as qh_exception
class Command(BaseCommand): class Command(BaseCommand):
...@@ -129,8 +130,14 @@ class Command(BaseCommand): ...@@ -129,8 +130,14 @@ class Command(BaseCommand):
pprint_table(self.stderr, unsynced, headers) pprint_table(self.stderr, unsynced, headers)
if options["fix"]: if options["fix"]:
provisions = map(create_provision, unsynced) provisions = map(create_provision, unsynced)
s = qh.issue_commission('astakos', provisions, try:
name='RECONCILE', force=force) s = qh.issue_commission('astakos', provisions,
name='RECONCILE', force=force)
except qh_exception.NoCapacityError:
write("Reconciling failed because a limit has been "
"reached. Use --force to ignore the check.\n")
return
qh.resolve_pending_commission('astakos', s) qh.resolve_pending_commission('astakos', s)
write("Fixed unsynced resources\n") write("Fixed unsynced resources\n")
......
...@@ -125,7 +125,12 @@ class Command(BaseCommand): ...@@ -125,7 +125,12 @@ class Command(BaseCommand):
request["auto_accept"] = True request["auto_accept"] = True
request["name"] = "RECONCILE" request["name"] = "RECONCILE"
request["provisions"] = map(create_provision, unsynced) request["provisions"] = map(create_provision, unsynced)
qh.issue_commission(ASTAKOS_TOKEN, request) try:
qh.issue_commission(ASTAKOS_TOKEN, request)
except quotas.QuotaLimit:
write("Reconciling failed because a limit has been "
"reached. Use --force to ignore the check.\n")
return
write("Fixed unsynced resources\n") write("Fixed unsynced resources\n")
if pending_exists: if pending_exists:
......
...@@ -38,6 +38,7 @@ from optparse import make_option ...@@ -38,6 +38,7 @@ from optparse import make_option
from pithos.api.util import get_backend from pithos.api.util import get_backend
from pithos.backends.modular import CLUSTER_NORMAL, DEFAULT_SOURCE from pithos.backends.modular import CLUSTER_NORMAL, DEFAULT_SOURCE
from synnefo.webproject.management import utils from synnefo.webproject.management import utils
from astakosclient.errors import QuotaLimit
backend = get_backend() backend = get_backend()
...@@ -128,9 +129,16 @@ class Command(NoArgsCommand): ...@@ -128,9 +129,16 @@ class Command(NoArgsCommand):
request['auto_accept'] = True request['auto_accept'] = True
request['name'] = "RECONCILE" request['name'] = "RECONCILE"
request['provisions'] = map(create_provision, unsynced) request['provisions'] = map(create_provision, unsynced)
backend.astakosclient.issue_commission( try:
backend.service_token, request backend.astakosclient.issue_commission(
) backend.service_token, request
)
except QuotaLimit:
self.stdout.write(
"Reconciling failed because a limit has been "
"reached. Use --force to ignore the check.\n")
return
if pending_exists: if pending_exists:
self.stdout.write( self.stdout.write(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment