Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set host institute specific quota #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/sync_django_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

from vsc.ldap.configuration import VscConfiguration
from vsc.ldap.utils import LdapQuery
from vsc.config.base import GENT
from vsc.utils import fancylogger
from vsc.utils.nagios import NAGIOS_EXIT_CRITICAL
from vsc.utils.script_tools import ExtendedSimpleOption
Expand All @@ -53,6 +54,7 @@ def main():
'start-timestamp': ("The timestamp form which to start, otherwise use the cached value", None, "store", None),
'access_token': ('OAuth2 token identifying the user with the accountpage', None, 'store', None),
'account_page_url': ('URL of the account page', None, 'store', None),
'host_institute': ('Name of the institute where this script is being run', str, 'store', GENT),
'start_timestamp': ('Timestamp to start the sync from', str, 'store', None),
'user': ('System user to run the sync', str, 'store', NONROOT_DEFAULT_USER),
}
Expand Down Expand Up @@ -99,7 +101,7 @@ def main():
logging.info("Now running as user %s (uid: %s)", child_user, os.geteuid())

client = AccountpageClient(token=opts.options.access_token, url=opts.options.account_page_url + '/api')
syncer = LdapSyncer(client)
syncer = LdapSyncer(client, opts.options.host_institute)
last = last_timestamp
altered_accounts = syncer.sync_altered_accounts(last, opts.options.dry_run)

Expand Down
7 changes: 6 additions & 1 deletion lib/vsc/administration/ldapsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ class LdapSyncer(object):
This class implements a system for syncing changes from the accountpage api
to the vsc ldap
"""
def __init__(self, client):
def __init__(self, client, host_institute):
"""
Create an ldap syncer, requires a RestClient client to get the information from
(typically AccountpageClient)
"""
self.client = client
self.host_institute = host_institute
self.now = datetime.utcnow().replace(tzinfo=timezone.utc)

def add_or_update(self, VscLdapKlass, cn, ldap_attributes, dry_run):
Expand Down Expand Up @@ -153,6 +154,10 @@ def sync_altered_accounts(self, last, dry_run=True):
logging.debug('fetching quota')
quotas = self.client.account[account.vsc_id].quota.get()[1]
for quota in quotas:
# Only update quota's for the host institute
if quota['storage']['institute'] != self.host_institute:
continue

for stype in ['home', 'data', 'scratch']:
# only gent sets filesets for vo's, so not gvo is user. (other institutes is empty or "None"
if quota['storage']['storage_type'] == stype and not quota['fileset'].startswith('gvo'):
Expand Down