def getDIRACGOCDictionary(): """ Create a dictionary containing DIRAC site names and GOCDB site names using a configuration provided by CS. :return: A dictionary of DIRAC site names (key) and GOCDB site names (value). """ log = gLogger.getSubLogger("getDIRACGOCDictionary") log.debug("Begin function ...") result = gConfig.getConfigurationTree("/Resources/Sites", "Name") if not result["OK"]: log.error("getConfigurationTree() failed with message: %s" % result["Message"]) return S_ERROR("Configuration is corrupted") siteNamesTree = result["Value"] dictionary = dict() PATHELEMENTS = 6 # site names have 6 elements in the path, i.e.: # /Resource/Sites/<GRID NAME>/<DIRAC SITE NAME>/Name # [0]/[1] /[2] /[3] /[4] /[5] for path, gocdbSiteName in siteNamesTree.items(): # can be an iterator elements = path.split("/") if len(elements) != PATHELEMENTS: continue diracSiteName = elements[PATHELEMENTS - 2] dictionary[diracSiteName] = gocdbSiteName log.debug("End function.") return S_OK(dictionary)
def getDIRACGOCDictionary(): """ Create a dictionary containing DIRAC site names and GOCDB site names using a configuration provided by CS. :return: A dictionary of DIRAC site names (key) and GOCDB site names (value). """ log = gLogger.getSubLogger( 'getDIRACGOCDictionary' ) log.debug( 'Begin function ...' ) result = gConfig.getConfigurationTree( '/Resources/Sites', 'Name' ) if not result['OK']: log.error( "getConfigurationTree() failed with message: %s" % result['Message'] ) return S_ERROR( 'Configuration is corrupted' ) siteNamesTree = result['Value'] dictionary = dict() PATHELEMENTS = 6 # site names have 6 elements in the path, i.e.: # /Resource/Sites/<GRID NAME>/<DIRAC SITE NAME>/Name # [0]/[1] /[2] /[3] /[4] /[5] for path, gocdbSiteName in siteNamesTree.iteritems(): elements = path.split( '/' ) if len( elements ) <> PATHELEMENTS: continue diracSiteName = elements[PATHELEMENTS - 2] dictionary[diracSiteName] = gocdbSiteName log.debug( 'End function.' ) return S_OK( dictionary )
def getDIRACGOCDictionary(): """ Create a dictionary containing DIRAC site names and GOCDB site names using a configuration provided by CS. :return: A dictionary of DIRAC site names (key) and GOCDB site names (value). """ log = gLogger.getSubLogger('getDIRACGOCDictionary') log.debug('Begin function ...') result = gConfig.getConfigurationTree('/Resources/Sites', 'Name') if not result['OK']: log.error("getConfigurationTree() failed with message: %s" % result['Message']) return S_ERROR('Configuration is corrupted') siteNamesTree = result['Value'] dictionary = dict() PATHELEMENTS = 6 # site names have 6 elements in the path, i.e.: # /Resource/Sites/<GRID NAME>/<DIRAC SITE NAME>/Name # [0]/[1] /[2] /[3] /[4] /[5] for path, gocdbSiteName in siteNamesTree.iteritems(): elements = path.split('/') if len(elements) != PATHELEMENTS: continue diracSiteName = elements[PATHELEMENTS - 2] dictionary[diracSiteName] = gocdbSiteName log.debug('End function.') return S_OK(dictionary)
def getMQParamsFromCS(mqURI): """Function gets parameters of a MQ destination (queue/topic) from the CS. Args: mqURI(str):Pseudo URI identifing the MQ service. It has the following format: mqConnection::DestinationType::DestinationName e.g. blabla.cern.ch::Queues::MyQueue1 mType(str): 'consumer' or 'producer' Returns: S_OK(param_dicts) or S_ERROR """ # API initialization is required to get an up-to-date configuration from the CS csAPI = CSAPI() csAPI.initialize() try: mqService, mqType, mqName = mqURI.split("::") except ValueError: return S_ERROR("Bad format of mqURI address:%s" % (mqURI)) result = gConfig.getConfigurationTree("/Resources/MQServices", mqService, mqType, mqName) if not result["OK"] or not result["Value"]: return S_ERROR( "Requested destination not found in the CS: %s::%s::%s" % (mqService, mqType, mqName)) mqDestinationPath = None for path, value in result["Value"].items(): if not value and path.endswith(mqName): mqDestinationPath = path # set-up internal parameter depending on the destination type tmp = mqDestinationPath.split("Queues")[0].split("Topics") servicePath = tmp[0] serviceDict = {} if len(tmp) > 1: serviceDict["Topic"] = mqName else: serviceDict["Queue"] = mqName result = gConfig.getOptionsDict(servicePath) if not result["OK"]: return result serviceDict.update(result["Value"]) result = gConfig.getOptionsDict(mqDestinationPath) if not result["OK"]: return result serviceDict.update(result["Value"]) return S_OK(serviceDict)
def getInfoAboutProviders(of=None, providerName=None, option='', section=''): """ Get the information about providers :param str of: provider of what(Id, Proxy or etc.) need to look, None, "all" to get list of instance of what this providers :param str providerName: provider name, None, "all" to get list of providers names :param str option: option name that need to get, None, "all" to get all options in a section :param str section: section path in root section of provider, "all" to get options in all sections :return: S_OK()/S_ERROR() """ if not of or of == "all": result = gConfig.getSections(gBaseResourcesSection) if not result['OK']: return result return S_OK([i.replace('Providers', '') for i in result['Value']]) if not providerName or providerName == "all": return gConfig.getSections('%s/%sProviders' % (gBaseResourcesSection, of)) if not option or option == 'all': if not section: return gConfig.getOptionsDict( "%s/%sProviders/%s" % (gBaseResourcesSection, of, providerName)) elif section == "all": resDict = {} relPath = "%s/%sProviders/%s/" % (gBaseResourcesSection, of, providerName) result = gConfig.getConfigurationTree(relPath) if not result['OK']: return result for key, value in result['Value'].items(): # can be an iterator if value: resDict[key.replace(relPath, '')] = value return S_OK(resDict) else: return gConfig.getSections( '%s/%sProviders/%s/%s/' % (gBaseResourcesSection, of, providerName, section)) else: return S_OK( gConfig.getValue( '%s/%sProviders/%s/%s/%s' % (gBaseResourcesSection, of, providerName, section, option)))
def getMQParamsFromCS( mqURI ): """ Function gets parameters of a MQ destination (queue/topic) from the CS. Args: mqURI(str):Pseudo URI identifing the MQ service. It has the following format: mqConnection::DestinationType::DestinationName e.g. blabla.cern.ch::Queue::MyQueue1 mType(str): 'consumer' or 'producer' Returns: S_OK(param_dicts)/S_ERROR: """ # API initialization is required to get an up-to-date configuration from the CS csAPI = CSAPI() csAPI.initialize() try : mqService, mqType, mqName = mqURI.split( "::" ) except ValueError: return S_ERROR( 'Bad format of mqURI address:%s' % ( mqURI ) ) result = gConfig.getConfigurationTree( '/Resources/MQServices', mqService, mqType, mqName ) if not result['OK'] or len( result['Value'] ) == 0: return S_ERROR( 'Requested destination not found in the CS: %s::%s::%s' % ( mqService, mqType, mqName ) ) mqDestinationPath = None for path, value in result['Value'].iteritems(): if not value and path.endswith( mqName ): mqDestinationPath = path # set-up internal parameter depending on the destination type tmp = mqDestinationPath.split( 'Queue' )[0].split( 'Topic' ) servicePath = tmp[0] serviceDict = {} if len( tmp ) > 1: serviceDict['Topic'] = mqName else: serviceDict['Queue'] = mqName result = gConfig.getOptionsDict( servicePath ) if not result['OK']: return result serviceDict.update( result['Value'] ) result = gConfig.getOptionsDict( mqDestinationPath ) if not result['OK']: return result serviceDict.update( result['Value'] ) return S_OK( serviceDict )
result = nAuth.getProxyWithToken(aToken) if not result['OK']: return result result = Script.enableCS() if not result['OK']: return S_ERROR("Cannot contact CS to get user list") threading.Thread(target=self.checkCAs).start() gConfig.forceRefresh(fromMaster=True) return S_OK(self.__piParams.proxyLoc) if __name__ == "__main__": piParams = Params() piParams.registerCLISwitches() Script.disableCS() Script.parseCommandLine(ignoreErrors=True) DIRAC.gConfig.setOptionValue("/DIRAC/Security/UseServerCertificate", "False") pI = ProxyInit(piParams) gLogger.info(gConfig.getConfigurationTree()) resultDoMagic = pI.doOAuthMagic() if not resultDoMagic['OK']: gLogger.fatal(resultDoMagic['Message']) sys.exit(1) pI.printInfo() sys.exit(0)