예제 #1
0
class SiteDB(object):
    def __init__(self, url='https://cmsweb.cern.ch/sitedb/data/prod/'):
        self._proxy_path = os.environ.get('X509_USER_PROXY', '')
        if not os.path.exists(self._proxy_path):
            raise UserError('VOMS proxy needed to query SiteDB! Environment variable X509_USER_PROXY is "%s"'
                            % self._proxy_path)

        self.rest_client = RestClient(cert=self._proxy_path)
        self._url = url

    def _people(self, username=None):
        if username:
            response = self.rest_client.get(self._url, api='people', params=dict(match=username))
        else:
            response = self.rest_client.get(self._url, api='people')
        return unflatten_json(parseJSON(response))

    def _site_names(self, site_name=None):
        if site_name:
            response = self.rest_client.get(self._url, api='site-names', params=dict(match=site_name))
        else:
            response = self.rest_client.get(self._url, api='site-names')
        return unflatten_json(parseJSON(response))

    def _site_resources(self):
        response = self.rest_client.get(self._url, api='site-resources')
        return unflatten_json(parseJSON(response))

    def cms_name_to_se(self, cms_name):
        cms_name = cms_name.replace('*', '.*')
        cms_name = cms_name.replace('%', '.*')
        cms_name_regex = re.compile(cms_name)

        psn_site_names = filter(lambda site: site['type'] == 'psn' and cms_name_regex.match(site[u'alias']),
                                self._site_names())
        site_names = set(map(lambda x: x['site_name'], psn_site_names))
        site_resources = filter(lambda x: x['site_name'] in site_names, self._site_resources())
        host_list = filter(lambda x: x['type'] == 'SE', site_resources)
        host_list = map(lambda x: x['fqdn'], host_list)
        return host_list

    def se_to_cms_name(self, se):
        site_resources = filter(lambda resources: resources['fqdn'] == se, self._site_resources())
        site_names = []
        for site_resource in site_resources:
            site_names.extend(self._site_names(site_name=site_resource['site_name']))
        return [site_name['alias'] for site_name in filter(lambda site: site['type'] == 'cms', site_names)]

    def dn_to_username(self, dn):
        user_info = filter(lambda this_user: this_user['dn'] == dn, self._people())
        for user in user_info:
            return user['username']

    def username_to_dn(self, username):
        user_info = self._people(username=username)
        for user in user_info:
            return user['dn']
예제 #2
0
    def __init__(self, url='https://cmsweb.cern.ch/sitedb/data/prod/'):
        self._proxy_path = os.environ.get('X509_USER_PROXY', '')
        if not os.path.exists(self._proxy_path):
            raise UserError('VOMS proxy needed to query SiteDB! Environment variable X509_USER_PROXY is "%s"'
                            % self._proxy_path)

        self.rest_client = RestClient(cert=self._proxy_path)
        self._url = url
    def __init__(self, url):
        self._reader_url = '%s/%s' % (url, 'DBSReader')
        self._writer_url = '%s/%s' % (url, 'DBSWriter')
        self._migrate_url = '%s/%s' % (url, 'DBSMigrate')

        self._proxy_path = os.environ.get('X509_USER_PROXY', '')
        if not os.path.exists(self._proxy_path):
            raise UserError('VOMS proxy needed to query DBS3! Environment variable X509_USER_PROXY is "%s"'
                            % self._proxy_path)

        self.rest_client = RestClient(cert=self._proxy_path)
class DBS3LiteClient(object):
    def __init__(self, url):
        self._reader_url = '%s/%s' % (url, 'DBSReader')
        self._writer_url = '%s/%s' % (url, 'DBSWriter')
        self._migrate_url = '%s/%s' % (url, 'DBSMigrate')

        self._proxy_path = os.environ.get('X509_USER_PROXY', '')
        if not os.path.exists(self._proxy_path):
            raise UserError('VOMS proxy needed to query DBS3! Environment variable X509_USER_PROXY is "%s"'
                            % self._proxy_path)

        self.rest_client = RestClient(cert=self._proxy_path)

    def insertBulkBlock(self, data):
        response = self.rest_client.post(url=self._writer_url, api='bulkblocks', data=json.dumps(data))
        return parseJSON(response)

    def listBlocks(self, **kwargs):
        response = self.rest_client.get(url=self._reader_url, api='blocks', params=kwargs)
        return parseJSON(response)

    def listFiles(self, **kwargs):
        response = self.rest_client.get(url=self._reader_url, api='files', params=kwargs)
        return parseJSON(response)

    def listFileParents(self, **kwargs):
        response = self.rest_client.get(url=self._reader_url, api='fileparents', params=kwargs)
        return parseJSON(response)

    def migrateSubmit(self, data):
        response = self.rest_client.post(url=self._migrate_url, api='submit', data=json.dumps(data))
        return parseJSON(response)

    def migrateStatus(self, **kwargs):
        response = self.rest_client.get(url=self._migrate_url, api='status', params=kwargs)
        return parseJSON(response)