Exemplo n.º 1
0
    def __init__(self,
                 vo_id,
                 storage=None,
                 rest_client=None,
                 host_institute=GENT):
        """Initialise"""
        super(VscTier2AccountpageVo, self).__init__(vo_id, rest_client)

        self.vo_id = vo_id
        self.vsc = VSC()
        self.host_institute = host_institute

        if not storage:
            self.storage = VscStorage()
        else:
            self.storage = storage

        self.gpfs = GpfsOperations()
        self.posix = PosixOperations()

        self.dry_run = False

        self._vo_data_quota_cache = None
        self._vo_data_shared_quota_cache = None
        self._vo_scratch_quota_cache = None
        self._institute_quota_cache = None

        self._sharing_group_cache = None
Exemplo n.º 2
0
def process_user_quota(storage,
                       gpfs,
                       storage_name,
                       filesystem,
                       quota_map,
                       user_map,
                       client,
                       dry_run=False,
                       institute=GENT):
    """
    Wrapper around the new function to keep the old behaviour intact.
    """
    del filesystem
    del gpfs

    exceeding_users = []
    path_template = storage.path_templates[institute][storage_name]
    vsc = VSC()

    logging.info("Logging user quota to account page")
    logging.debug("Considering the following quota items for pushing: %s",
                  quota_map)

    with DjangoPusher(storage_name, client, QUOTA_USER_KIND,
                      dry_run) as pusher:
        for (user_id, quota) in quota_map.items():

            user_institute = vsc.user_id_to_institute(int(user_id))
            if user_institute != institute:
                continue

            user_name = user_map.get(int(user_id), None)
            if not user_name:
                try:
                    user_name = getpwuid(int(user_id)).pw_name
                except KeyError:
                    continue

            fileset_name = path_template['user'](user_name)[1]

            fileset_re = '^(vsc[1-4]|%s|%s|%s)' % (
                VO_PREFIX_BY_SITE[institute],
                VO_SHARED_PREFIX_BY_SITE[institute], fileset_name)

            for (fileset, quota_) in quota.quota_map.items():
                if re.search(fileset_re, fileset):
                    pusher.push_quota(user_name, fileset, quota_)

            if quota.exceeds():
                exceeding_users.append((user_name, quota))

    return exceeding_users
Exemplo n.º 3
0
    def __init__(self,
                 user_id,
                 storage=None,
                 pickle_storage=None,
                 rest_client=None,
                 account=None,
                 pubkeys=None,
                 host_institute=None,
                 use_user_cache=False):
        """
        Initialisation.
        @type vsc_user_id: string representing the user's VSC ID (vsc[0-9]{5})
        """
        super(VscTier2AccountpageUser,
              self).__init__(user_id,
                             rest_client,
                             account=account,
                             pubkeys=pubkeys,
                             use_user_cache=use_user_cache)

        # Move to vsc-config?
        default_pickle_storage = {
            GENT: VSC_SCRATCH_KYUKON,
            BRUSSEL: VSC_SCRATCH_THEIA,
        }

        if host_institute is None:
            host_institute = GENT
        self.host_institute = host_institute

        if pickle_storage is None:
            pickle_storage = default_pickle_storage[host_institute]

        self.pickle_storage = pickle_storage
        if storage is None:
            storage = VscStorage()

        self.institute_path_templates = storage.path_templates[
            self.host_institute]
        self.institute_storage = storage[self.host_institute]

        self.vsc = VSC()
        self.gpfs = GpfsOperations()  # Only used when needed
        self.posix = PosixOperations()
Exemplo n.º 4
0
    def __init__(self, user_id, storage=None, pickle_storage='VSC_SCRATCH_KYUKON', rest_client=None,
                 account=None, pubkeys=None, host_institute=None, use_user_cache=False):
        """
        Initialisation.
        @type vsc_user_id: string representing the user's VSC ID (vsc[0-9]{5})
        """
        super(VscTier2AccountpageUser, self).__init__(user_id, rest_client, account=account,
                                                      pubkeys=pubkeys, use_user_cache=use_user_cache)

        self.pickle_storage = pickle_storage
        if not storage:
            self.storage = VscStorage()
        else:
            self.storage = storage

        self.vsc = VSC()
        self.gpfs = GpfsOperations()  # Only used when needed
        self.posix = PosixOperations()
        self.host_institute = host_institute
Exemplo n.º 5
0
from ldap import LDAPError

from vsc.accountpage.wrappers import mkVscAccount, mkUserGroup, mkGroup, mkVo
from vsc.config.base import VSC, INSTITUTE_VOS_GENT
from vsc.ldap.entities import VscLdapUser, VscLdapGroup
from vsc.ldap.filters import CnFilter
from vsc.utils.py2vs3 import ensure_ascii_string

ACCOUNT_WITHOUT_PUBLIC_KEYS_MAGIC_STRING = "THIS ACCOUNT HAS NO VALID PUBLIC KEYS"

DONE = 'done'
NEW = 'new'
UPDATED = 'updated'
ERROR = 'error'

VSC_CONFIG = VSC()


class LdapSyncer(object):
    """
    This class implements a system for syncing changes from the accountpage api
    to the vsc ldap
    """
    def __init__(self, client):
        """
        Create an ldap syncer, requires a RestClient client to get the information from
        (typically AccountpageClient)
        """
        self.client = client
        self.now = datetime.utcnow().replace(tzinfo=timezone.utc)