Commit 023c8e93 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

pithos: change reconcile-resources-pithos command

This command syncronizes the astakos quota with the pithos db.
However, if there was an account in the astakos database but there
was not the relative path in the pithos db (new pithos database)
the account quotas were not synced.
This commit fixes this.

Also, sync all the registed resources defined for the service
(the resource to be synced used to be hardcoded before)
parent c5621ab1
......@@ -36,8 +36,11 @@ from django.core.management.base import NoArgsCommand, CommandError
from optparse import make_option
from pithos.api.util import get_backend
from pithos.api.resources import resources
from pithos.backends.modular import CLUSTER_NORMAL, DEFAULT_SOURCE
from synnefo.webproject.management import utils
from astakosclient.errors import QuotaLimit
backend = get_backend()
......@@ -61,12 +64,15 @@ class Command(NoArgsCommand):
make_option("--force",
default=False,
action="store_true",
help="Override Astakos quotas. Force Astakos to impose"
" the Pithos quota, independently of their value.")
help="Override Astakos quotas. Force Astakos to impose "
"the Pithos quota, independently of their value.")
)
def handle_noargs(self, **options):
try:
qh_result = backend.astakosclient.service_get_quotas(
backend.service_token)
users = (options['userid'],) if options['userid'] else None
account_nodes = backend.node.node_accounts(users)
if not account_nodes:
......@@ -77,17 +83,14 @@ class Command(NoArgsCommand):
size = backend.node.node_account_usage(node, CLUSTER_NORMAL)
db_usage[path] = size or 0
qh_result = backend.astakosclient.service_get_quotas(
backend.service_token,
users
)
users = set(qh_result.keys())
users.update(db_usage.keys())
resource = 'pithos.diskspace'
pending_exists = False
unknown_user_exists = False
unsynced = []
for uuid in db_usage.keys():
db_value = db_usage[uuid]
for uuid in users:
db_value = db_usage.get(uuid, 0)
try:
qh_all = qh_result[uuid]
except KeyError:
......@@ -98,27 +101,29 @@ class Command(NoArgsCommand):
continue
else:
qh = qh_all.get(DEFAULT_SOURCE, {})
try:
qh_resource = qh[resource]
except KeyError:
self.stdout.write(
"Resource '%s' does not exist in Quotaholder"
" for user '%s'!\n" % (resource, uuid))
continue
if qh_resource['pending']:
self.stdout.write(
"Pending commission. User '%s', resource '%s'.\n" %
(uuid, resource)
)
pending_exists = True
continue
for resource in [r['name'] for r in resources]:
try:
qh_resource = qh[resource]
except KeyError:
self.stdout.write(
"Resource '%s' does not exist in Quotaholder "
"for user '%s'!\n" % (resource, uuid))
continue
if qh_resource['pending']:
self.stdout.write(
"Pending commission. "
"User '%s', resource '%s'.\n" %
(uuid, resource)
)
pending_exists = True
continue
qh_value = qh_resource['usage']
qh_value = qh_resource['usage']
if db_value != qh_value:
data = (uuid, resource, db_value, qh_value)
unsynced.append(data)
if db_value != qh_value:
data = (uuid, resource, db_value, qh_value)
unsynced.append(data)
if unsynced:
headers = ("User", "Resource", "Database", "Quotaholder")
......@@ -131,15 +136,13 @@ class Command(NoArgsCommand):
request['provisions'] = map(create_provision, unsynced)
try:
backend.astakosclient.issue_commission(
backend.service_token, request
)
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:
self.stdout.write(
"Found pending commissions. Run 'snf-manage"
......
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