def getUserDict(username): """ Get full information from user section :param str username: DIRAC user name :return: S_OK()/S_ERROR() """ resDict = {} relPath = '%s/Users/%s/' % (gBaseRegistrySection, username) result = gConfig.getConfigurationTree(relPath) if not result['OK']: return result for key, value in result['Value'].items(): if value: resDict[key.replace(relPath, '')] = value return S_OK(resDict)
def __createProducer(self): """ This method is used to create an MQ producer. Returns: MQProducer or None: """ mqProducer = None result = gConfig.getConfigurationTree('/Resources/MQServices') if result['OK']: result = createProducer("Monitoring::Queues::%s" % self.__failoverQueueName) if not result['OK']: gLogger.error("Fail to create Producer:", result['Message']) else: mqProducer = result['Value'] else: gLogger.warn("No MQ setup for Monitoring in CS. You are running Monitoring without failover:", result['Message']) return mqProducer
def updateNameDictionary(self): """ Update the internal host-to-dirac name dictionary. """ result = gConfig.getConfigurationTree("/Resources/Sites", "Network/", "/Enabled") if not result["OK"]: self.log.error("getConfigurationTree() failed with message: %s" % result["Message"]) return S_ERROR("Unable to fetch perfSONAR endpoints from CS.") tmpDict = {} for path, value in result["Value"].items(): if value == "True": elements = path.split("/") diracName = elements[4] hostName = elements[6] tmpDict[hostName] = diracName self.nameDictionary = tmpDict
def updateNameDictionary(self): ''' Update the internal host-to-dirac name dictionary. ''' result = gConfig.getConfigurationTree('/Resources/Sites', 'Network/', '/Enabled') if not result['OK']: self.log.error("getConfigurationTree() failed with message: %s" % result['Message']) return S_ERROR('Unable to fetch perfSONAR endpoints from CS.') tmpDict = {} for path, value in result['Value'].iteritems(): if value == 'True': elements = path.split('/') diracName = elements[4] hostName = elements[6] tmpDict[hostName] = diracName self.nameDictionary = tmpDict
def __preparePerfSONARConfiguration(self, endpointList): """ Prepare a dictionary with a new CS configuration of perfSONAR endpoints. :return: Dictionary where keys are configuration paths (options and sections) and values are values of corresponding options or None in case of a path pointing to a section. """ log = self.log.getSubLogger('__preparePerfSONARConfiguration') log.debug('Begin function ...') # static elements of a path rootPath = '/Resources/Sites' extPath = 'Network' baseOptionName = 'Enabled' options = {baseOptionName: 'True', 'ServiceType': 'perfSONAR'} # enable GOCDB endpoints in configuration newConfiguration = {} for endpoint in endpointList: if endpoint['DIRACSITENAME'] is None: continue split = endpoint['DIRACSITENAME'].split('.') path = cfgPath(rootPath, split[0], endpoint['DIRACSITENAME'], extPath, endpoint['HOSTNAME']) for name, defaultValue in options.iteritems(): newConfiguration[cfgPath(path, name)] = defaultValue # get current configuration currentConfiguration = {} for option in options.iterkeys(): result = gConfig.getConfigurationTree(rootPath, extPath + '/', '/' + option) if not result['OK']: log.error("getConfigurationTree() failed with message: %s" % result['Message']) return S_ERROR('Unable to fetch perfSONAR endpoints from CS.') currentConfiguration.update(result['Value']) # disable endpoints that disappeared in GOCDB removedElements = set(currentConfiguration) - set(newConfiguration) newElements = set(newConfiguration) - set(currentConfiguration) addedEndpoints = len(newElements) / len(options) disabledEndpoints = 0 for path in removedElements: if baseOptionName in path: newConfiguration[path] = 'False' if currentConfiguration[path] != 'False': disabledEndpoints = disabledEndpoints + 1 # inform what will be changed if addedEndpoints > 0: self.log.info( "%s new perfSONAR endpoints will be added to the configuration" % addedEndpoints) if disabledEndpoints > 0: self.log.info( "%s old perfSONAR endpoints will be disable in the configuration" % disabledEndpoints) if addedEndpoints == 0 and disabledEndpoints == 0: self.log.info("perfSONAR configuration is up-to-date") log.debug('End function.') return S_OK(newConfiguration)
def __preparePerfSONARConfiguration(self, endpointList): """ Prepare a dictionary with a new CS configuration of perfSONAR endpoints. :return: Dictionary where keys are configuration paths (options and sections) and values are values of corresponding options or None in case of a path pointing to a section. """ log = self.log.getSubLogger('__preparePerfSONARConfiguration') log.debug('Begin function ...') # static elements of a path rootPath = '/Resources/Sites' extPath = 'Network' baseOptionName = 'Enabled' options = {baseOptionName: 'True', 'ServiceType': 'perfSONAR'} # enable GOCDB endpoints in configuration newConfiguration = {} for endpoint in endpointList: if endpoint['DIRACSITENAME'] is None: continue split = endpoint['DIRACSITENAME'].split('.') path = cfgPath(rootPath, split[0], endpoint['DIRACSITENAME'], extPath, endpoint['HOSTNAME']) for name, defaultValue in options.iteritems(): newConfiguration[cfgPath(path, name)] = defaultValue # get current configuration currentConfiguration = {} for option in options.iterkeys(): result = gConfig.getConfigurationTree(rootPath, extPath + '/', '/' + option) if not result['OK']: log.error("getConfigurationTree() failed with message: %s" % result['Message']) return S_ERROR('Unable to fetch perfSONAR endpoints from CS.') currentConfiguration.update(result['Value']) # disable endpoints that disappeared in GOCDB removedElements = set(currentConfiguration) - set(newConfiguration) newElements = set(newConfiguration) - set(currentConfiguration) addedEndpoints = len(newElements) / len(options) disabledEndpoints = 0 for path in removedElements: if baseOptionName in path: newConfiguration[path] = 'False' if currentConfiguration[path] != 'False': disabledEndpoints = disabledEndpoints + 1 # inform what will be changed if addedEndpoints > 0: self.log.info("%s new perfSONAR endpoints will be added to the configuration" % addedEndpoints) if disabledEndpoints > 0: self.log.info("%s old perfSONAR endpoints will be disable in the configuration" % disabledEndpoints) if addedEndpoints == 0 and disabledEndpoints == 0: self.log.info("perfSONAR configuration is up-to-date") log.debug('End function.') return S_OK(newConfiguration)
def __preparePerfSONARConfiguration(self, endpointList): """ Prepare a dictionary with a new CS configuration of perfSONAR endpoints. :return: Dictionary where keys are configuration paths (options and sections) and values are values of corresponding options or None in case of a path pointing to a section. """ log = self.log.getSubLogger("__preparePerfSONARConfiguration") log.debug("Begin function ...") # static elements of a path rootPath = "/Resources/Sites" extPath = "Network" baseOptionName = "Enabled" options = {baseOptionName: "True", "ServiceType": "perfSONAR"} # enable GOCDB endpoints in configuration newConfiguration = {} for endpoint in endpointList: if endpoint["DIRACSITENAME"] is None: continue split = endpoint["DIRACSITENAME"].split(".") path = cfgPath(rootPath, split[0], endpoint["DIRACSITENAME"], extPath, endpoint["HOSTNAME"]) for name, defaultValue in options.items(): newConfiguration[cfgPath(path, name)] = defaultValue # get current configuration currentConfiguration = {} for option in options: result = gConfig.getConfigurationTree(rootPath, extPath + "/", "/" + option) if not result["OK"]: log.error("getConfigurationTree() failed with message: %s" % result["Message"]) return S_ERROR("Unable to fetch perfSONAR endpoints from CS.") currentConfiguration.update(result["Value"]) # disable endpoints that disappeared in GOCDB removedElements = set(currentConfiguration) - set(newConfiguration) newElements = set(newConfiguration) - set(currentConfiguration) addedEndpoints = int(len(newElements) / len(options)) disabledEndpoints = 0 for path in removedElements: if baseOptionName in path: newConfiguration[path] = "False" if currentConfiguration[path] != "False": disabledEndpoints = disabledEndpoints + 1 # inform what will be changed if addedEndpoints > 0: self.log.info( "%s new perfSONAR endpoints will be added to the configuration" % addedEndpoints) if disabledEndpoints > 0: self.log.info( "%s old perfSONAR endpoints will be disable in the configuration" % disabledEndpoints) if addedEndpoints == 0 and disabledEndpoints == 0: self.log.info("perfSONAR configuration is up-to-date") log.debug("End function.") return S_OK(newConfiguration)