def getDescription(self): """ Get CE description as a dictionary """ ceDict = {} for option, value in self.ceParameters.items(): if type(value) == type([]): ceDict[option] = value elif type(value) == type(" "): tmpInt = self.__getInt(value) if tmpInt is not None: self.log.debug("Found CE integer attribute: %s = %s" % (option, tmpInt)) ceDict[option] = tmpInt else: self.log.debug("Found string attribute: %s = %s" % (option, value)) ceDict[option] = value elif type(value) == type(1) or type(value) == type(1.0): self.log.debug("Found integer attribute: %s = %s" % (option, value)) ceDict[option] = value else: self.log.warn("Type of option %s = %s not determined" % (option, value)) release = gConfig.getValue("/LocalSite/ReleaseVersion", version) ceDict["DIRACVersion"] = release ceDict["ReleaseVersion"] = release project = gConfig.getValue("/LocalSite/ReleaseProject", "") if project: ceDict["ReleaseProject"] = project return S_OK(ceDict)
def getJDL( self ): """Returns CE JDL as a string. """ # Add the CE parameters for option, value in self.ceParameters.items(): if type( option ) == type( [] ): self.classAd.insertAttributeVectorString( option, value.split( ', ' ) ) elif type( value ) == type( ' ' ): jdlInt = self.__getInt( value ) if type( jdlInt ) == type( 1 ): self.log.debug( 'Found JDL integer attribute: %s = %s' % ( option, jdlInt ) ) self.classAd.insertAttributeInt( option, jdlInt ) else: self.log.debug( 'Found string attribute: %s = %s' % ( option, value ) ) self.classAd.insertAttributeString( option, value ) elif type( value ) == type( 1 ): self.log.debug( 'Found integer attribute: %s = %s' % ( option, value ) ) self.classAd.insertAttributeInt( option, value ) else: self.log.warn( 'Type of option %s = %s not determined' % ( option, value ) ) # Add the CE requirements if any requirements = '' for option, value in self.ceRequirementDict.items(): if type( value ) == type( ' ' ): jdlInt = self.__getInt( value ) if type( jdlInt ) == type( 1 ): requirements += ' other.' + option + ' == %d &&' % ( jdlInt ) self.log.debug( 'Found JDL reqt integer attribute: %s = %s' % ( option, jdlInt ) ) self.classAd.insertAttributeInt( option, jdlInt ) else: requirements += ' other.' + option + ' == "%s" &&' % ( value ) self.log.debug( 'Found string reqt attribute: %s = %s' % ( option, value ) ) self.classAd.insertAttributeString( option, value ) elif type( value ) == type( 1 ): requirements += ' other.' + option + ' == %d &&' % ( value ) self.log.debug( 'Found integer reqt attribute: %s = %s' % ( option, value ) ) self.classAd.insertAttributeInt( option, value ) else: self.log.warn( 'Could not determine type of: %s = %s' % ( option, value ) ) if requirements: if re.search( '&&$', requirements ): requirements = requirements[:-3] self.classAd.set_expression( 'Requirements', requirements ) else: self.classAd.set_expression( 'Requirements', 'True' ) release = gConfig.getValue( '/LocalSite/ReleaseVersion', version ) self.classAd.insertAttributeString( 'DIRACVersion', release ) self.classAd.insertAttributeString( 'ReleaseVersion', release ) project = gConfig.getValue( "/LocalSite/ReleaseProject", "" ) if project: self.classAd.insertAttributeString( 'ReleaseProject', project ) if self.classAd.isOK(): jdl = self.classAd.asJDL() return S_OK( jdl ) else: return S_ERROR( 'ClassAd job is not valid' )
def getDescription(self): """ Get CE description as a dictionary """ ceDict = {} for option, value in self.ceParameters.iteritems(): if isinstance(value, list): ceDict[option] = value elif isinstance(value, basestring): try: ceDict[option] = int(value) except ValueError: ceDict[option] = value elif isinstance(value, (int, long, float)): ceDict[option] = value else: self.log.warn('Type of option %s = %s not determined' % (option, value)) release = gConfig.getValue('/LocalSite/ReleaseVersion', version) ceDict['DIRACVersion'] = release ceDict['ReleaseVersion'] = release project = gConfig.getValue("/LocalSite/ReleaseProject", "") if project: ceDict['ReleaseProject'] = project result = self.getCEStatus() if result['OK']: if 'AvailableProcessors' in result: cores = result['AvailableProcessors'] ceDict['NumberOfProcessors'] = cores return S_OK(ceDict)
def getDescription( self ): """ Get CE description as a dictionary """ ceDict = {} for option, value in self.ceParameters.items(): if type( value ) == type( [] ): ceDict[option] = value elif type( value ) == type( ' ' ): tmpInt = self.__getInt( value ) if tmpInt is not None: self.log.debug( 'Found CE integer attribute: %s = %s' % ( option, tmpInt ) ) ceDict[option] = tmpInt else: self.log.debug( 'Found string attribute: %s = %s' % ( option, value ) ) ceDict[option] = value elif type( value ) == type( 1 ) or type( value ) == type( 1. ): self.log.debug( 'Found integer attribute: %s = %s' % ( option, value ) ) ceDict[option] = value else: self.log.warn( 'Type of option %s = %s not determined' % ( option, value ) ) release = gConfig.getValue( '/LocalSite/ReleaseVersion', version ) ceDict['DIRACVersion'] = release ceDict['ReleaseVersion'] = release project = gConfig.getValue( "/LocalSite/ReleaseProject", "" ) if project: ceDict['ReleaseProject'] = project return S_OK( ceDict )
def __init__(self, ceName): """Standard constructor""" self.log = gLogger.getSubLogger(ceName) self.ceName = ceName self.ceParameters = {} self.proxy = "" self.valid = None self.mandatoryParameters = [] self.batchSystem = None self.taskResults = {} self.minProxyTime = gConfig.getValue("/Registry/MinProxyLifeTime", 10800) # secs self.defaultProxyTime = gConfig.getValue( "/Registry/DefaultProxyLifeTime", 43200) # secs self.proxyCheckPeriod = gConfig.getValue( "/Registry/ProxyCheckingPeriod", 3600) # secs clsName = self.__class__.__name__ if clsName.endswith("ComputingElement"): self.ceType = clsName[:-len("ComputingElement")] else: self.log.warning("%s should end with 'ComputingElement'!" % clsName) self.ceType = clsName self.initializeParameters() self.log.debug("CE parameters", self.ceParameters)
def getValidPropertiesForMethod(self, method, defaultProperties=False): """ Get all authorized groups for calling a method :type method: string :param method: Method to test :return: List containing the allowed groups """ authProps = gConfig.getValue("%s/%s" % (self.authSection, method), []) if authProps: return authProps if defaultProperties: self.__authLogger.debug( "Using hardcoded properties for method %s : %s" % (method, defaultProperties)) if not isinstance(defaultProperties, (list, tuple)): return List.fromChar(defaultProperties) return defaultProperties defaultPath = "%s/Default" % "/".join(method.split("/")[:-1]) authProps = gConfig.getValue("%s/%s" % (self.authSection, defaultPath), []) if authProps: self.__authLogger.debug( "Method %s has no properties defined using %s" % (method, defaultPath)) return authProps self.__authLogger.debug( "Method %s has no authorization rules defined. Allowing no properties" % method) return []
def initializeStorageElementHandler(serviceInfo): """ Initialize Storage Element global settings """ global base_path global use_tokens_flag global max_storage_size cfgPath = serviceInfo['serviceSectionPath'] base_path = gConfig.getValue("%s/BasePath" % cfgPath, base_path) if not base_path: gLogger.error('Failed to get the base path') return S_ERROR('Failed to get the base path') if not os.path.exists(base_path): os.makedirs(base_path) use_tokens_flag = gConfig.getValue("%s/UseTokens" % cfgPath, use_tokens_flag) max_storage_size = gConfig.getValue("%s/MaxStorageSize" % cfgPath, max_storage_size) gLogger.info('Starting DIRAC Storage Element') gLogger.info('Base Path: %s' % base_path) gLogger.info('Max size: %d MB' % max_storage_size) gLogger.info('Use access control tokens: ' + str(use_tokens_flag)) return S_OK()
def getDescription(self): """ Get CE description as a dictionary """ ceDict = {} for option, value in self.ceParameters.items(): if isinstance(value, list): ceDict[option] = value elif isinstance(value, basestring): try: ceDict[option] = int(value) except ValueError: ceDict[option] = value elif isinstance(value, (int, long, float)): ceDict[option] = value else: self.log.warn('Type of option %s = %s not determined' % (option, value)) release = gConfig.getValue('/LocalSite/ReleaseVersion', version) ceDict['DIRACVersion'] = release ceDict['ReleaseVersion'] = release project = gConfig.getValue("/LocalSite/ReleaseProject", "") if project: ceDict['ReleaseProject'] = project result = self.getCEStatus() if result['OK']: if 'AvailableProcessors' in result: cores = result['AvailableProcessors'] ceDict['NumberOfProcessors'] = cores return S_OK(ceDict)
def initialize(self, systemName, cfgPath): if self.__initialized: return self.__initialized = True from DIRAC.ConfigurationSystem.Client.Config import gConfig from os import getpid #self.__printDebug( "The configuration path is %s" % cfgPath ) #Get the options for the different output backends retDict = gConfig.getOptionsDict("%s/BackendsOptions" % cfgPath) #self.__printDebug( retDict ) if not retDict['OK']: cfgBackOptsDict = { 'FileName': 'Dirac-log_%s.log' % getpid(), 'Interactive': True, 'SleepTime': 150 } else: cfgBackOptsDict = retDict['Value'] self.__backendOptions.update(cfgBackOptsDict) if not self.__backendOptions.has_key('Filename'): self.__backendOptions['FileName'] = 'Dirac-log_%s.log' % getpid() sleepTime = 150 try: sleepTime = int(self.__backendOptions['SleepTime']) except: pass self.__backendOptions['SleepTime'] = sleepTime self.__backendOptions['Interactive'] = gConfig.getValue( "%s/BackendsOptions/Interactive" % cfgPath, True) self.__backendOptions['Site'] = DIRAC.siteName() #Configure outputs desiredBackends = gConfig.getValue("%s/LogBackends" % cfgPath, 'stdout') self.registerBackends(List.fromChar(desiredBackends)) #Configure verbosity defaultLevel = Logger.defaultLogLevel if "Scripts" in cfgPath: defaultLevel = gConfig.getValue('/Systems/Scripts/LogLevel', Logger.defaultLogLevel) self.setLevel(gConfig.getValue("%s/LogLevel" % cfgPath, defaultLevel)) #Configure framing self._showCallingFrame = gConfig.getValue("%s/LogShowLine" % cfgPath, self._showCallingFrame) #Get system name self._systemName = str(systemName) if not self.__backendOptions['Interactive']: ExitCallback.registerExitCallback(self.flushAllMessages)
def initialize( self, systemName, cfgPath ): if self.__initialized: return self.__initialized = True from DIRAC.ConfigurationSystem.Client.Config import gConfig from os import getpid #self.__printDebug( "The configuration path is %s" % cfgPath ) #Get the options for the different output backends retDict = gConfig.getOptionsDict( "%s/BackendsOptions" % cfgPath ) #self.__printDebug( retDict ) if not retDict[ 'OK' ]: cfgBackOptsDict = { 'FileName': 'Dirac-log_%s.log' % getpid(), 'Interactive': True, 'SleepTime': 150 } else: cfgBackOptsDict = retDict[ 'Value' ] self.__backendOptions.update( cfgBackOptsDict ) if not self.__backendOptions.has_key( 'Filename' ): self.__backendOptions[ 'FileName' ] = 'Dirac-log_%s.log' % getpid() sleepTime = 150 try: sleepTime = int ( self.__backendOptions[ 'SleepTime' ] ) except: pass self.__backendOptions[ 'SleepTime' ] = sleepTime self.__backendOptions[ 'Interactive' ] = gConfig.getValue( "%s/BackendsOptions/Interactive" % cfgPath, True ) self.__backendOptions[ 'Site' ] = DIRAC.siteName() #Configure outputs desiredBackends = gConfig.getValue( "%s/LogBackends" % cfgPath, 'stdout' ) self.registerBackends( List.fromChar( desiredBackends ) ) #Configure verbosity defaultLevel = Logger.defaultLogLevel if "Scripts" in cfgPath: defaultLevel = gConfig.getValue( '/Systems/Scripts/LogLevel', Logger.defaultLogLevel ) self.setLevel( gConfig.getValue( "%s/LogLevel" % cfgPath, defaultLevel ) ) #Configure framing self._showCallingFrame = gConfig.getValue( "%s/LogShowLine" % cfgPath, self._showCallingFrame ) #Get system name self._systemName = str( systemName ) if not self.__backendOptions['Interactive']: ExitCallback.registerExitCallback( self.flushAllMessages )
def display(self): if request.params.has_key( "site" ) and len( request.params[ "site" ] ) > 0: if str( request.params[ "site" ] ) != "All": c.select = str( request.params[ "site" ] ) else: c.select = gConfig.getValue( "/Website/DefaultExternalURL", "http://diracgrid.org" ) return render( "web/External.mako" )
def __discoverVO( self ): #Which setup to use? if self.KW_VO in self.kwargs and self.kwargs[ self.KW_VO ]: self.vo = str( self.kwargs[ self.KW_VO ] ) else: self.vo = gConfig.getValue( "/DIRAC/VirtualOrganization", "unknown" ) return S_OK()
def getVO(defaultVO=""): """ Return VO from configuration """ from DIRAC import gConfig return gConfig.getValue("/DIRAC/VirtualOrganization", defaultVO)
def getResourceDict(ceName=None): """Look into LocalSite for Resource Requirements """ from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments ret = gConfig.getOptionsDict("/LocalSite/ResourceDict") if not ret["OK"]: resourceDict = {} else: # FIXME: es mejor copiar el diccionario? resourceDict = dict(ret["Value"]) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict("/LocalSite/%s/ResourceDict" % ceName) if ret["OK"]: resourceDict.update(dict(ret["Value"])) # now add some defaults resourceDict["Setup"] = gConfig.getValue("/DIRAC/Setup", "None") if not "CPUTime" in resourceDict: resourceDict["CPUTime"] = maxCPUSegments[-1] if not "PilotType" in resourceDict: # FIXME: this is a test, we need the list of available types resourceDict["PilotType"] = "private" return resourceDict
def __discoverSetup(self): #Which setup to use? if self.KW_SETUP in self.kwargs and self.kwargs[self.KW_SETUP]: self.setup = str(self.kwargs[self.KW_SETUP]) else: self.setup = gConfig.getValue("/DIRAC/Setup", "Test") return S_OK()
def getDefaultVOMSVO(): """ Get default VOMS VO :return: str """ return gConfig.getValue("%s/DefaultVOMSVO" % gBaseRegistrySection, "") or getVO()
def __discoverSetup( self ): #Which setup to use? if self.KW_SETUP in self.kwargs and self.kwargs[ self.KW_SETUP ]: self.setup = str( self.kwargs[ self.KW_SETUP ] ) else: self.setup = gConfig.getValue( "/DIRAC/Setup", "Test" ) return S_OK()
def __init__(self, name='Monitoring/MonitoringDB', readOnly=False): section = getDatabaseSection("Monitoring/MonitoringDB") indexPrefix = gConfig.getValue("%s/IndexPrefix" % section, CSGlobals.getSetup()).lower() super(MonitoringDB, self).__init__('MonitoringDB', name, indexPrefix) self.__readonly = readOnly self.__documents = {} self.__loadIndexes()
def getDefaultVOMSAttribute(): """ Get default VOMS attribute :return: str """ return gConfig.getValue("%s/DefaultVOMSAttribute" % gBaseRegistrySection, "")
def getResourceDict( ceName = None ): """Look into LocalSite for Resource Requirements """ from DIRAC.WorkloadManagementSystem.private.Queues import maxCPUSegments ret = gConfig.getOptionsDict( '/LocalSite/ResourceDict' ) if not ret['OK']: resourceDict = {} else: # FIXME: es mejor copiar el diccionario? resourceDict = dict( ret['Value'] ) # if a CE Name is given, check the corresponding section if ceName: ret = gConfig.getOptionsDict( '/LocalSite/%s/ResourceDict' % ceName ) if ret['OK']: resourceDict.update( dict( ret['Value'] ) ) # now add some defaults resourceDict['Setup'] = gConfig.getValue( '/DIRAC/Setup', 'None' ) if not 'CPUTime' in resourceDict: resourceDict['CPUTime'] = maxCPUSegments[-1] if not 'PilotType' in resourceDict: # FIXME: this is a test, we need the list of available types resourceDict['PilotType'] = 'private' return resourceDict
def display(self): if request.params.has_key("site") and len(request.params["site"]) > 0: if str(request.params["site"]) != "All": c.select = str(request.params["site"]) else: c.select = gConfig.getValue( "/Website/DefaultExternalURL", "google.com" ) return render("info/External.mako")
def siteName(): """ Determine and return DIRAC name for current site """ global __siteName if not __siteName: __siteName = gConfig.getValue('/LocalSite/Site', _siteName) return __siteName
def __getModificator(self): rpcClient = getRPCClient( gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server")) commiter = "%s@%s - %s" % ( credentials.getUsername(), credentials.getSelectedGroup(), Time.dateTime().strftime("%Y-%m-%d %H:%M:%S")) return Modificator(rpcClient, commiter)
def getCSOption( self, optionName, defaultValue = False ): """ Get an option from the CS section of the services @return : Value for serviceSection/optionName in the CS being defaultValue the default """ return gConfig.getValue( "%s/%s" % ( self.serviceInfoDict[ 'serviceSectionPath' ], optionName ), defaultValue )
def getSiteTier( sites ): if isinstance(sites, basestring): sites = [sites] tiers = [] for site in sites: t = gConfig.getValue("%s/Sites/LCG/%s/MoUTierLevel" %( g_BaseResourcesSection, site ) ) tiers = tiers + [t] return S_OK(tiers)
def getMailForUser( users ): if isinstance(users, basestring): users = [users] mails = [] for user in users: mail = gConfig.getValue("%s/Users/%s/Email" %(g_BaseRegistrySection, user)) mails.append(mail) return S_OK(mails)
def __init__( self, ceName ): """ Standard constructor """ self.log = gLogger.getSubLogger( ceName ) self.ceName = ceName self.ceType = '' self.ceParameters = {} self.proxy = '' self.valid = None self.mandatoryParameters = [] self.batch = None self.minProxyTime = gConfig.getValue( '/Registry/MinProxyLifeTime', 10800 ) #secs self.defaultProxyTime = gConfig.getValue( '/Registry/DefaultProxyLifeTime', 86400 ) #secs self.proxyCheckPeriod = gConfig.getValue( '/Registry/ProxyCheckingPeriod', 3600 ) #secs self.initializeParameters()
def display(self): if request.params.has_key("site") and len(request.params["site"]) > 0: if str(request.params["site"]) != "All": c.select = str(request.params["site"]) else: c.select = gConfig.getValue("/Website/DefaultExternalURL", "http://diracgrid.org") return render("web/External.mako")
def __getModificator(self): rpcClient = getRPCClient(gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server")) commiter = "%s@%s - %s" % ( credentials.getUsername(), credentials.getSelectedGroup(), Time.dateTime().strftime("%Y-%m-%d %H:%M:%S"), ) return Modificator(rpcClient, commiter)
def siteName(): """ Determine and return DIRAC name for current site """ global __siteName if not __siteName: __siteName = gConfig.getValue( '/LocalSite/Site', _siteName ) return __siteName
def getVOMSVOForGroup(group): vomsVO = gConfig.getValue( "%s/Groups/%s/VOMSVO" % (gBaseRegistrySection, group), getDefaultVOMSVO()) if not vomsVO: vo = getVOForGroup(group) vomsVO = getVOOption(vo, 'VOMSName', '') return vomsVO
def getVOForGroup(group): """ Search VO name for group :param str group: group name :return: str """ return getVO() or gConfig.getValue( "%s/Groups/%s/VO" % (gBaseRegistrySection, group), "")
def getHostnameForDN( dn ): retVal = gConfig.getSections( "%s/Hosts" % gBaseSecuritySection ) if not retVal[ 'OK' ]: return retVal hostList = retVal[ 'Value' ] for hostname in hostList: if dn in gConfig.getValue( "%s/Hosts/%s/DN" % ( gBaseSecuritySection, hostname ), [] ): return S_OK( hostname ) return S_ERROR( "No hostname found for dn %s" % dn )
def getGroupsWithVOMSAttribute( vomsAttr ): retVal = gConfig.getSections( "%s/Groups" % ( gBaseSecuritySection ) ) if not retVal[ 'OK' ]: return [] groups = [] for group in retVal[ 'Value' ]: if vomsAttr == gConfig.getValue( "%s/Groups/%s/VOMSRole" % ( gBaseSecuritySection, group ), "" ): groups.append( group ) return groups
def getSENodes( SE ): if isinstance(SE, basestring): SE = [SE] node = [] for se in SE: n = gConfig.getValue("%s/StorageElements/%s/AccessProtocol.1/Host" %( g_BaseResourcesSection, se ) ) node = node + [n] return S_OK(node)
def getSENodes(SE): if isinstance(SE, basestring): SE = [SE] node = [] for se in SE: n = gConfig.getValue("%s/StorageElements/%s/AccessProtocol.1/Host" % (g_BaseResourcesSection, se)) node = node + [n] return S_OK(node)
def getMailForUser(users): if isinstance(users, basestring): users = [users] mails = [] for user in users: mail = gConfig.getValue("%s/Users/%s/Email" % (g_BaseRegistrySection, user)) mails.append(mail) return S_OK(mails)
def __init__( self, ceName ): """ Standard constructor """ self.log = gLogger.getSubLogger( ceName ) self.ceName = ceName self.ceType = '' #self.log.setLevel('debug') #temporary for debugging self.ceParameters = {} self.proxy = '' self.valid = None self.mandatoryParameters = [] self.minProxyTime = gConfig.getValue( '/Registry/MinProxyLifeTime', 10800 ) #secs self.defaultProxyTime = gConfig.getValue( '/Registry/DefaultProxyLifeTime', 86400 ) #secs self.proxyCheckPeriod = gConfig.getValue( '/Registry/ProxyCheckingPeriod', 3600 ) #secs self.ceConfigDict = getLocalCEConfigDict( ceName ) self.initializeParameters()
def __init__(self, ceName): """ Standard constructor """ self.log = gLogger.getSubLogger(ceName) self.ceName = ceName self.ceType = "" # self.log.setLevel('debug') #temporary for debugging self.ceParameters = {} self.proxy = "" self.valid = None self.mandatoryParameters = [] self.minProxyTime = gConfig.getValue("/Registry/MinProxyLifeTime", 10800) # secs self.defaultProxyTime = gConfig.getValue("/Registry/DefaultProxyLifeTime", 86400) # secs self.proxyCheckPeriod = gConfig.getValue("/Registry/ProxyCheckingPeriod", 3600) # secs self.ceConfigDict = getLocalCEConfigDict(ceName) self.initializeParameters()
def getSiteTier(sites): if isinstance(sites, basestring): sites = [sites] tiers = [] for site in sites: t = gConfig.getValue("%s/Sites/LCG/%s/MoUTierLevel" % (g_BaseResourcesSection, site)) tiers = tiers + [t] return S_OK(tiers)
def getDescription(self): """ Get CE description as a dictionary """ ceDict = {} for option, value in self.ceParameters.items(): if type(value) == type([]): ceDict[option] = value elif type(value) == type(' '): tmpInt = self.__getInt(value) if tmpInt is not None: self.log.debug('Found CE integer attribute: %s = %s' % (option, tmpInt)) ceDict[option] = tmpInt else: self.log.debug('Found string attribute: %s = %s' % (option, value)) ceDict[option] = value elif type(value) == type(1) or type(value) == type(1.): self.log.debug('Found integer attribute: %s = %s' % (option, value)) ceDict[option] = value else: self.log.warn('Type of option %s = %s not determined' % (option, value)) release = gConfig.getValue('/LocalSite/ReleaseVersion', version) ceDict['DIRACVersion'] = release ceDict['ReleaseVersion'] = release project = gConfig.getValue("/LocalSite/ReleaseProject", "") if project: ceDict['ReleaseProject'] = project result = self.getCEStatus() if result['OK']: if 'AvailableCores' in result: cores = result['AvailableCores'] if cores > 1: tagList = [] for i in range(2, cores + 1): tagList.append('%dCore' % i) ceDict['Tag'] = tagList return S_OK(ceDict)
def findDefaultGroupForUser(userName): defGroups = gConfig.getValue("/%s/DefaultGroup" % gBaseSecuritySection, ["user"]) result = getGroupsForUser(userName) if not result["OK"]: return result userGroups = result["Value"] for group in defGroups: if group in userGroups: return S_OK(group) return S_OK(False)
def getUsernameForID(ID, usersList=False): if not usersList: retVal = gConfig.getSections("%s/Users" % gBaseRegistrySection) if not retVal['OK']: return retVal usersList = retVal['Value'] for username in usersList: if ID in gConfig.getValue("%s/Users/%s/ID" % (gBaseRegistrySection, username), []): return S_OK(username) return S_ERROR("No username found for ID %s" % ID)
def getServiceOption( serviceInfo, optionName, defaultValue ): """ Get service option resolving default values from the master service """ if optionName[0] == "/": return gConfig.getValue( optionName, defaultValue ) for csPath in serviceInfo[ 'csPaths' ]: result = gConfig.getOption( "%s/%s" % ( csPath, optionName, ), defaultValue ) if result[ 'OK' ]: return result[ 'Value' ] return defaultValue
def getUsernameForDN( dn, usersList = False ): if not usersList: retVal = gConfig.getSections( "%s/Users" % gBaseSecuritySection ) if not retVal[ 'OK' ]: return retVal usersList = retVal[ 'Value' ] for username in usersList: if dn in gConfig.getValue( "%s/Users/%s/DN" % ( gBaseSecuritySection, username ), [] ): return S_OK( username ) return S_ERROR( "No username found for dn %s" % dn )
def __init__( self, ceName ): """ Standard constructor """ self.log = gLogger.getSubLogger( ceName ) self.ceName = ceName self.ceType = '' #self.log.setLevel('debug') #temporary for debugging self.classAd = ClassAd( '[]' ) self.ceRequirementDict = {} self.ceParameters = {} self.proxy = '' self.valid = None self.minProxyTime = gConfig.getValue( '/Registry/MinProxyLifeTime', 10800 ) #secs self.defaultProxyTime = gConfig.getValue( '/Registry/DefaultProxyLifeTime', 86400 ) #secs self.proxyCheckPeriod = gConfig.getValue( '/Registry/ProxyCheckingPeriod', 3600 ) #secs self.ceConfigDict = getLocalCEConfigDict( ceName ) self.initializeParameters()
def __getRemoteConfiguration(self): rpcClient = getRPCClient(gConfig.getValue("/DIRAC/Configuration/MasterServer", "Configuration/Server")) modCfg = Modificator(rpcClient) retVal = modCfg.loadFromRemote() if retVal["OK"]: session["cfgData"] = str(modCfg) session["csName"] = "%s Configuration" % (modCfg.getValue("/DIRAC/VirtualOrganization")) session.save() c.cfgData = modCfg.cfgData c.csName = session["csName"] return retVal
def getCSExtensions( self ): if not self.__csExt: from DIRAC.ConfigurationSystem.Client.Config import gConfig exts = gConfig.getValue( '/DIRAC/Extensions', [] ) for iP in range( len( exts ) ): ext = exts[ iP ] if ext.endswith( "DIRAC" ): ext = ext[:-5] exts[ iP ] = ext self.__csExt = exts return self.__csExt
def initialize(self): credDict = self.getRemoteCredentials() self.ownerDN = credDict['DN'] self.ownerGroup = credDict['group'] self.userProperties = credDict[ 'properties' ] self.owner = credDict[ 'username' ] self.peerUsesLimitedProxy = credDict[ 'isLimitedProxy' ] self.diracSetup = self.serviceInfoDict['clientSetup'] serviceSectionPath = self.serviceInfoDict['serviceSectionPath'] self.maxParametricJobs = gConfig.getValue('%s/MaxParametricJobs'%serviceSectionPath,MAX_PARAMETRIC_JOBS) self.jobPolicy = JobPolicy( self.ownerDN, self.ownerGroup, self.userProperties )
def getShortcutsForGroup( self, group ): groupSection = "%s/Shortcuts/%s" % ( self.webSection, group ) retVal = gConfig.getOptions( groupSection, listOrdered = True ) if retVal[ 'OK' ]: names = retVal[ 'Value' ] else: names = [] entries = [] for entryName in names: actionPath = gConfig.getValue( "%s/%s" % ( groupSection, entryName ) ) entries.append( ( entryName, actionPath ) ) return entries
def findDefaultGroupForUser( userName ): defGroups = gConfig.getValue( "/%s/DefaultGroup" % gBaseSecuritySection, [ "user" ] ) result = getGroupsForUser( userName ) if not result[ 'OK' ]: return result userGroups = result[ 'Value' ] for group in defGroups: if group in userGroups: return S_OK( group ) if userGroups: return S_OK( userGroups[0] ) return S_ERROR( "User %s has no groups" % userName )