def vomsInfoAvailable( self ): """ Is voms info available? """ if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -h' result = shellCall( self._secCmdTimeout, cmd ) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ if not Os.which("voms-proxy-info"): return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = 'voms-proxy-info -h' result = shellCall(self._secCmdTimeout, cmd) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ vpInfoCmd = '' for vpInfo in ('voms-proxy-info', 'voms-proxy-info2'): if Os.which(vpInfo): vpInfoCmd = vpInfo if not vpInfoCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = '%s -h' % vpInfoCmd result = shellCall(self._secCmdTimeout, cmd) if not result['OK']: return False status, _output, _error = result['Value'] if status: return False return True
def vomsInfoAvailable(self): """ Is voms info available? """ vpInfoCmd = "" for vpInfo in ("voms-proxy-info", "voms-proxy-info2"): if Os.which(vpInfo): vpInfoCmd = vpInfo if not vpInfoCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-info") cmd = "%s -h" % vpInfoCmd result = shellCall(self._secCmdTimeout, cmd) if not result["OK"]: return False status, _output, _error = result["Value"] if status: return False return True
def __readHostInfo(): """ Get host current loads, memory, etc """ result = dict() # Memory info re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB') for line in open('/proc/meminfo'): match = re_parser.match(line) if not match: continue key, value = match.groups(['key', 'value']) result[key] = int(value) for mtype in ['Mem', 'Swap']: memory = int(result.get(mtype + 'Total')) mfree = int(result.get(mtype + 'Free')) if memory > 0: percentage = float(memory - mfree) / float(memory) * 100. else: percentage = 0 name = 'Memory' if mtype == "Swap": name = 'Swap' result[name] = '%.1f%%/%.1fMB' % (percentage, memory / 1024.) # Loads l1, l5, l15 = (str(lx) for lx in os.getloadavg()) result['Load1'] = l1 result['Load5'] = l5 result['Load15'] = l15 result['Load'] = '/'.join([l1, l5, l15]) # CPU info with open('/proc/cpuinfo', 'r') as fd: lines = fd.readlines() processors = 0 physCores = {} for line in lines: if line.strip(): parameter, value = line.split(':') parameter = parameter.strip() value = value.strip() if parameter.startswith('processor'): processors += 1 if parameter.startswith('physical id'): physCores[value] = parameter if parameter.startswith('model name'): result['CPUModel'] = value if parameter.startswith('cpu MHz'): result['CPUClock'] = value result['Cores'] = processors result['PhysicalCores'] = len(physCores) # Disk occupancy summary = '' _status, output = commands.getstatusoutput('df') lines = output.split('\n') for i in xrange(len(lines)): if lines[i].startswith('/dev'): fields = lines[i].split() if len(fields) == 1: fields += lines[i + 1].split() _disk = fields[0].replace('/dev/sd', '') partition = fields[5] occupancy = fields[4] summary += ",%s:%s" % (partition, occupancy) result['DiskOccupancy'] = summary[1:] result['RootDiskSpace'] = Os.getDiskSpace(rootPath) # Open files puser = getpass.getuser() _status, output = commands.getstatusoutput('lsof') pipes = 0 files = 0 sockets = 0 lines = output.split('\n') for line in lines: fType = line.split()[4] user = line.split()[2] if user == puser: if fType in ['REG']: files += 1 elif fType in ['unix', 'IPv4']: sockets += 1 elif fType in ['FIFO']: pipes += 1 result['OpenSockets'] = sockets result['OpenFiles'] = files result['OpenPipes'] = pipes infoResult = gComponentInstaller.getInfo() if infoResult['OK']: result.update(infoResult['Value']) # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string result.update({ "Extensions": ";".join([ "%s:%s" % (key, value) for (key, value) in infoResult["Value"].get('Extensions').iteritems() ]) }) # Host certificate properties certFile, _keyFile = getHostCertificateAndKeyLocation() chain = X509Chain() chain.loadChainFromFile(certFile) resultCert = chain.getCredentials() if resultCert['OK']: result['SecondsLeft'] = resultCert['Value']['secondsLeft'] result['CertificateValidity'] = str( timedelta(seconds=resultCert['Value']['secondsLeft'])) result['CertificateDN'] = resultCert['Value']['subject'] result['HostProperties'] = resultCert['Value']['groupProperties'] result['CertificateIssuer'] = resultCert['Value']['issuer'] # Host uptime result['Uptime'] = str( timedelta(seconds=(time.time() - psutil.boot_time()))) return S_OK(result)
def setVOMSAttributes(self, proxy, attribute=None, vo=None): """ Sets voms attributes to a proxy """ if not vo: return S_ERROR(DErrno.EVOMS, "No vo specified, and can't get default in the configuration") retVal = multiProxyArgument(proxy) if not retVal['OK']: return retVal proxyDict = retVal['Value'] chain = proxyDict['chain'] proxyLocation = proxyDict['file'] secs = chain.getRemainingSecs()['Value'] - 300 if secs < 0: return S_ERROR(DErrno.EVOMS, "Proxy length is less that 300 secs") hours = int(secs / 3600) mins = int((secs - hours * 3600) / 60) retVal = self._generateTemporalFile() if not retVal['OK']: deleteMultiProxy(proxyDict) return retVal newProxyLocation = retVal['Value'] cmdArgs = [] if chain.isLimitedProxy()['Value']: cmdArgs.append('-limited') cmdArgs.append('-cert "%s"' % proxyLocation) cmdArgs.append('-key "%s"' % proxyLocation) cmdArgs.append('-out "%s"' % newProxyLocation) if attribute and attribute != 'NoRole': cmdArgs.append('-voms "%s:%s"' % (vo, attribute)) else: cmdArgs.append('-voms "%s"' % vo) cmdArgs.append('-valid "%s:%s"' % (hours, mins)) tmpDir = False vomsesPath = self.getVOMSESLocation() if vomsesPath: cmdArgs.append('-vomses "%s"' % vomsesPath) if chain.isRFC().get('Value'): cmdArgs.append("-r") cmdArgs.append('-timeout %u' % self._servTimeout) vpInitCmd = '' for vpInit in ('voms-proxy-init', 'voms-proxy-init2'): if Os.which(vpInit): vpInitCmd = vpInit if not vpInitCmd: return S_ERROR(DErrno.EVOMS, "Missing voms-proxy-init") cmd = '%s %s' % (vpInitCmd, " ".join(cmdArgs)) result = shellCall(self._secCmdTimeout, cmd) if tmpDir: shutil.rmtree(tmpDir) deleteMultiProxy(proxyDict) if not result['OK']: self._unlinkFiles(newProxyLocation) return S_ERROR(DErrno.EVOMS, 'Failed to call voms-proxy-init: %s' % result['Message']) status, output, error = result['Value'] if status: self._unlinkFiles(newProxyLocation) return S_ERROR( DErrno.EVOMS, 'Failed to set VOMS attributes. Command: %s; StdOut: %s; StdErr: %s' % (cmd, output, error)) newChain = X509Chain() retVal = newChain.loadProxyFromFile(newProxyLocation) self._unlinkFiles(newProxyLocation) if not retVal['OK']: return S_ERROR(DErrno.EVOMS, "Can't load new proxy: %s" % retVal['Message']) return S_OK(newChain)
def export_getHostInfo(self): """ Get host current loads, memory, etc """ result = dict() # Memory info re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB' ) for line in open('/proc/meminfo'): match = re_parser.match(line) if not match: continue key, value = match.groups(['key', 'value']) result[key] = int(value) for mtype in ['Mem','Swap']: memory = int(result.get(mtype+'Total')) mfree = int(result.get(mtype+'Free')) if memory > 0: percentage = float(memory-mfree)/float(memory)*100. else: percentage = 0 name = 'Memory' if mtype == "Swap": name = 'Swap' result[name] = '%.1f%%/%.1fMB' % (percentage,memory/1024.) # Loads line = open('/proc/loadavg').read() l1,l5,l15,d1,d2 = line.split() result['Load1'] = l1 result['Load5'] = l5 result['Load15'] = l15 result['Load'] = '/'.join([l1,l5,l15]) # CPU info lines = open( '/proc/cpuinfo', 'r' ).readlines() processors = 0 physCores = {} for line in lines: if line.strip(): parameter, value = line.split(':') parameter = parameter.strip() value = value.strip() if parameter.startswith('processor'): processors += 1 if parameter.startswith('physical id'): physCores[value] = parameter if parameter.startswith('model name'): result['CPUModel'] = value if parameter.startswith('cpu MHz'): result['CPUClock'] = value result['Cores'] = processors result['PhysicalCores'] = len(physCores) # Disk occupancy summary = '' status,output = commands.getstatusoutput('df') lines = output.split('\n') for i in range( len( lines ) ): if lines[i].startswith('/dev'): fields = lines[i].split() if len( fields ) == 1: fields += lines[i+1].split() disk = fields[0].replace('/dev/sd','') partition = fields[5] occupancy = fields[4] summary += ",%s:%s" % (partition,occupancy) result['DiskOccupancy'] = summary[1:] result['RootDiskSpace'] = Os.getDiskSpace( DIRAC.rootPath ) # Open files puser= getpass.getuser() status,output = commands.getstatusoutput('lsof') pipes = 0 files = 0 sockets = 0 lines = output.split('\n') for line in lines: fType = line.split()[4] user = line.split()[2] if user == puser: if fType in ['REG']: files += 1 elif fType in ['unix','IPv4']: sockets += 1 elif fType in ['FIFO']: pipes += 1 result['OpenSockets'] = sockets result['OpenFiles'] = files result['OpenPipes'] = pipes infoResult = InstallTools.getInfo( getCSExtensions() ) if infoResult['OK']: result.update( infoResult['Value'] ) # Host certificate properties certFile,keyFile = getHostCertificateAndKeyLocation() chain = X509Chain() chain.loadChainFromFile( certFile ) resultCert = chain.getCredentials() if resultCert['OK']: result['SecondsLeft'] = resultCert['Value']['secondsLeft'] result['CertificateValidity'] = str( timedelta( seconds = resultCert['Value']['secondsLeft'] ) ) result['CertificateDN'] = resultCert['Value']['subject'] result['HostProperties'] = ','.join( resultCert['Value']['groupProperties'] ) result['CertificateIssuer'] = resultCert['Value']['issuer'] # Host uptime try: upFile = open('/proc/uptime', 'r') uptime_seconds = float(upFile.readline().split()[0]) upFile.close() result['Uptime'] = str(timedelta(seconds = uptime_seconds)) except: pass return S_OK(result)
#!/usr/bin/env python """ Determine number of processors and memory for the worker node """ from DIRAC.Core.Base import Script from DIRAC import gLogger from DIRAC.Core.Utilities import Os from DIRAC.WorkloadManagementSystem.Utilities import JobMemory __RCSID__ = "$Id$" Script.setUsageMessage( '\n'.join( ['Get the Tag of a CE', 'Usage:', '%s [option]... [cfgfile]' % Script.scriptName, 'Arguments:', ' cfgfile: DIRAC Cfg with description of the configuration (optional)'] ) ) Script.parseCommandLine( ignoreErrors = True ) NumberOfProcessor = Os.getNumberOfCores() MaxRAM = JobMemory.getMemoryFromMJF() if not MaxRAM: MaxRAM = JobMemory.getMemoryFromProc() gLogger.notice( NumberOfProcessor, MaxRAM )
def __readHostInfo(): """Get host current loads, memory, etc""" result = dict() # Memory info re_parser = re.compile(r"^(?P<key>\S*):\s*(?P<value>\d*)\s*kB") for line in open("/proc/meminfo"): match = re_parser.match(line) if not match: continue key, value = match.groups(["key", "value"]) result[key] = int(value) for mtype in ["Mem", "Swap"]: memory = int(result.get(mtype + "Total")) mfree = int(result.get(mtype + "Free")) if memory > 0: percentage = float(memory - mfree) / float(memory) * 100.0 else: percentage = 0 name = "Memory" if mtype == "Swap": name = "Swap" result[name] = "%.1f%%/%.1fMB" % (percentage, memory / 1024.0) # Loads l1, l5, l15 = (str(lx) for lx in os.getloadavg()) result["Load1"] = l1 result["Load5"] = l5 result["Load15"] = l15 result["Load"] = "/".join([l1, l5, l15]) # CPU info with open("/proc/cpuinfo", "r") as fd: lines = fd.readlines() processors = 0 physCores = {} for line in lines: if line.strip(): parameter, value = line.split(":") parameter = parameter.strip() value = value.strip() if parameter.startswith("processor"): processors += 1 if parameter.startswith("physical id"): physCores[value] = parameter if parameter.startswith("model name"): result["CPUModel"] = value if parameter.startswith("cpu MHz"): result["CPUClock"] = value result["Cores"] = processors result["PhysicalCores"] = len(physCores) # Disk occupancy summary = "" _status, output = commands.getstatusoutput("df") lines = output.split("\n") for i in range(len(lines)): if lines[i].startswith("/dev"): fields = lines[i].split() if len(fields) == 1: fields += lines[i + 1].split() partition = fields[5] occupancy = fields[4] summary += ",%s:%s" % (partition, occupancy) result["DiskOccupancy"] = summary[1:] result["RootDiskSpace"] = Os.getDiskSpace(rootPath) # Open files puser = getpass.getuser() _status, output = commands.getstatusoutput("lsof") pipes = 0 files = 0 sockets = 0 lines = output.split("\n") for line in lines: fType = line.split()[4] user = line.split()[2] if user == puser: if fType in ["REG"]: files += 1 elif fType in ["unix", "IPv4"]: sockets += 1 elif fType in ["FIFO"]: pipes += 1 result["OpenSockets"] = sockets result["OpenFiles"] = files result["OpenPipes"] = pipes infoResult = gComponentInstaller.getInfo() if infoResult["OK"]: result.update(infoResult["Value"]) # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string result.update({ "Extensions": ";".join([ "%s:%s" % (key, value) for (key, value ) in infoResult["Value"].get("Extensions").items() ]) }) # Host certificate properties certFile, _keyFile = getHostCertificateAndKeyLocation() chain = X509Chain() chain.loadChainFromFile(certFile) resultCert = chain.getCredentials() if resultCert["OK"]: result["SecondsLeft"] = resultCert["Value"]["secondsLeft"] result["CertificateValidity"] = str( timedelta(seconds=resultCert["Value"]["secondsLeft"])) result["CertificateDN"] = resultCert["Value"]["subject"] result["CertificateIssuer"] = resultCert["Value"]["issuer"] # Host uptime result["Uptime"] = str( timedelta(seconds=(time.time() - psutil.boot_time()))) return S_OK(result)
def export_getHostInfo(self): """ Get host current loads, memory, etc """ result = dict() # Memory info re_parser = re.compile(r"^(?P<key>\S*):\s*(?P<value>\d*)\s*kB") for line in open("/proc/meminfo"): match = re_parser.match(line) if not match: continue key, value = match.groups(["key", "value"]) result[key] = int(value) for mtype in ["Mem", "Swap"]: memory = int(result.get(mtype + "Total")) mfree = int(result.get(mtype + "Free")) if memory > 0: percentage = float(memory - mfree) / float(memory) * 100.0 else: percentage = 0 name = "Memory" if mtype == "Swap": name = "Swap" result[name] = "%.1f%%/%.1fMB" % (percentage, memory / 1024.0) # Loads line = open("/proc/loadavg").read() l1, l5, l15, d1, d2 = line.split() result["Load1"] = l1 result["Load5"] = l5 result["Load15"] = l15 result["Load"] = "/".join([l1, l5, l15]) # CPU info lines = open("/proc/cpuinfo", "r").readlines() processors = 0 physCores = {} for line in lines: if line.strip(): parameter, value = line.split(":") parameter = parameter.strip() value = value.strip() if parameter.startswith("processor"): processors += 1 if parameter.startswith("physical id"): physCores[value] = parameter if parameter.startswith("model name"): result["CPUModel"] = value if parameter.startswith("cpu MHz"): result["CPUClock"] = value result["Cores"] = processors result["PhysicalCores"] = len(physCores) # Disk occupancy summary = "" status, output = commands.getstatusoutput("df") lines = output.split("\n") for i in range(len(lines)): if lines[i].startswith("/dev"): fields = lines[i].split() if len(fields) == 1: fields += lines[i + 1].split() disk = fields[0].replace("/dev/sd", "") partition = fields[5] occupancy = fields[4] summary += ",%s:%s" % (partition, occupancy) result["DiskOccupancy"] = summary[1:] result["RootDiskSpace"] = Os.getDiskSpace(DIRAC.rootPath) # Open files puser = getpass.getuser() status, output = commands.getstatusoutput("lsof") pipes = 0 files = 0 sockets = 0 lines = output.split("\n") for line in lines: fType = line.split()[4] user = line.split()[2] if user == puser: if fType in ["REG"]: files += 1 elif fType in ["unix", "IPv4"]: sockets += 1 elif fType in ["FIFO"]: pipes += 1 result["OpenSockets"] = sockets result["OpenFiles"] = files result["OpenPipes"] = pipes infoResult = InstallTools.getInfo(getCSExtensions()) if infoResult["OK"]: result.update(infoResult["Value"]) # Host certificate properties certFile, keyFile = getHostCertificateAndKeyLocation() chain = X509Chain() chain.loadChainFromFile(certFile) resultCert = chain.getCredentials() if resultCert["OK"]: result["SecondsLeft"] = resultCert["Value"]["secondsLeft"] result["CertificateValidity"] = str(timedelta(seconds=resultCert["Value"]["secondsLeft"])) result["CertificateDN"] = resultCert["Value"]["subject"] result["HostProperties"] = ",".join(resultCert["Value"]["groupProperties"]) result["CertificateIssuer"] = resultCert["Value"]["issuer"] # Host uptime try: upFile = open("/proc/uptime", "r") uptime_seconds = float(upFile.readline().split()[0]) upFile.close() result["Uptime"] = str(timedelta(seconds=uptime_seconds)) except: pass return S_OK(result)
def export_getHostInfo(self): """ Get host current loads, memory, etc """ result = dict() # Memory info re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB') for line in open('/proc/meminfo'): match = re_parser.match(line) if not match: continue key, value = match.groups(['key', 'value']) result[key] = int(value) for mtype in ['Mem', 'Swap']: memory = int(result.get(mtype + 'Total')) mfree = int(result.get(mtype + 'Free')) if memory > 0: percentage = float(memory - mfree) / float(memory) * 100. else: percentage = 0 name = 'Memory' if mtype == "Swap": name = 'Swap' result[name] = '%.1f%%/%.1fMB' % (percentage, memory / 1024.) # Loads line = open('/proc/loadavg').read() l1, l5, l15, d1, d2 = line.split() result['Load1'] = l1 result['Load5'] = l5 result['Load15'] = l15 result['Load'] = '/'.join([l1, l5, l15]) # CPU info lines = open('/proc/cpuinfo', 'r').readlines() processors = 0 physCores = {} for line in lines: if line.strip(): parameter, value = line.split(':') parameter = parameter.strip() value = value.strip() if parameter.startswith('processor'): processors += 1 if parameter.startswith('physical id'): physCores[value] = parameter if parameter.startswith('model name'): result['CPUModel'] = value if parameter.startswith('cpu MHz'): result['CPUClock'] = value result['Cores'] = processors result['PhysicalCores'] = len(physCores) # Disk occupancy summary = '' status, output = commands.getstatusoutput('df') lines = output.split('\n') for i in range(len(lines)): if lines[i].startswith('/dev'): fields = lines[i].split() if len(fields) == 1: fields += lines[i + 1].split() disk = fields[0].replace('/dev/sd', '') partition = fields[5] occupancy = fields[4] summary += ",%s:%s" % (partition, occupancy) result['DiskOccupancy'] = summary[1:] result['RootDiskSpace'] = Os.getDiskSpace(DIRAC.rootPath) # Open files puser = getpass.getuser() status, output = commands.getstatusoutput('lsof') pipes = 0 files = 0 sockets = 0 lines = output.split('\n') for line in lines: fType = line.split()[4] user = line.split()[2] if user == puser: if fType in ['REG']: files += 1 elif fType in ['unix', 'IPv4']: sockets += 1 elif fType in ['FIFO']: pipes += 1 result['OpenSockets'] = sockets result['OpenFiles'] = files result['OpenPipes'] = pipes infoResult = InstallTools.getInfo(getCSExtensions()) if infoResult['OK']: result.update(infoResult['Value']) # Host certificate properties certFile, keyFile = getHostCertificateAndKeyLocation() chain = X509Chain() chain.loadChainFromFile(certFile) resultCert = chain.getCredentials() if resultCert['OK']: result['SecondsLeft'] = resultCert['Value']['secondsLeft'] result['CertificateValidity'] = str( timedelta(seconds=resultCert['Value']['secondsLeft'])) result['CertificateDN'] = resultCert['Value']['subject'] result['HostProperties'] = ','.join( resultCert['Value']['groupProperties']) result['CertificateIssuer'] = resultCert['Value']['issuer'] # Host uptime try: upFile = open('/proc/uptime', 'r') uptime_seconds = float(upFile.readline().split()[0]) upFile.close() result['Uptime'] = str(timedelta(seconds=uptime_seconds)) except: pass return S_OK(result)
#!/usr/bin/env python """ Determine number of processors and memory for the worker node """ from DIRAC.Core.Base import Script from DIRAC import gLogger from DIRAC.Core.Utilities import Os from DIRAC.WorkloadManagementSystem.Utilities import JobMemory __RCSID__ = "$Id$" Script.setUsageMessage('\n'.join([ 'Get the Tag of a CE', 'Usage:', '%s [option]... [cfgfile]' % Script.scriptName, 'Arguments:', ' cfgfile: DIRAC Cfg with description of the configuration (optional)' ])) Script.parseCommandLine(ignoreErrors=True) NumberOfProcessor = Os.getNumberOfCores() MaxRAM = JobMemory.getMemoryFromMJF() if not MaxRAM: MaxRAM = JobMemory.getMemoryFromProc() gLogger.notice(NumberOfProcessor, MaxRAM)
def getVOMSProxyInfo( self, proxy, option = False ): """ Returns information about a proxy certificate (both grid and voms). Available information is: 1. Full (grid)voms-proxy-info output 2. Proxy Certificate Timeleft in seconds (the output is an int) 3. DN 4. voms group (if any) @type proxy: a string @param proxy: the proxy certificate location. @type option: a string @param option: None is the default value. Other option available are: - timeleft - actimeleft - identity - fqan - all @rtype: tuple @return: status, output, error, pyerror. """ validOptions = ['actimeleft', 'timeleft', 'identity', 'fqan', 'all'] if option: if option not in validOptions: S_ERROR( 'Non valid option %s' % option ) retVal = File.multiProxyArgument( proxy ) if not retVal[ 'OK' ]: return retVal proxyDict = retVal[ 'Value' ] # chain = proxyDict[ 'chain' ] proxyLocation = proxyDict[ 'file' ] if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -file %s' % proxyLocation if option: cmd += ' -%s' % option result = shellCall( self._secCmdTimeout, cmd ) if proxyDict[ 'tempFile' ]: self._unlinkFiles( proxyLocation ) if not result['OK']: return S_ERROR( 'Failed to call voms-proxy-info' ) status, output, error = result['Value'] # FIXME: if the local copy of the voms server certificate is not up to date the command returns 0. # the stdout needs to be parsed. if status: gLogger.warn( 'Failed to execute:', cmd ) gLogger.warn( 'Exit code:', status ) gLogger.warn( 'StdOut' , output ) gLogger.warn( 'StdErr' , error ) if error.find( 'VOMS extension not found' ) == -1 and \ not error.find( 'WARNING: Unable to verify signature! Server certificate possibly not installed.' ) == 0: return S_ERROR( 'Failed to get proxy info. Command: %s; StdOut: %s; StdErr: %s' % ( cmd, output, error ) ) if option == 'fqan': if output: output = output.split( '/Role' )[0] else: output = '/lhcb' return S_OK( output )
def getVOMSProxyInfo(self, proxy, option=False): """ Returns information about a proxy certificate (both grid and voms). Available information is: 1. Full (grid)voms-proxy-info output 2. Proxy Certificate Timeleft in seconds (the output is an int) 3. DN 4. voms group (if any) @type proxy: a string @param proxy: the proxy certificate location. @type option: a string @param option: None is the default value. Other option available are: - timeleft - actimeleft - identity - fqan - all @rtype: tuple @return: status, output, error, pyerror. """ validOptions = ['actimeleft', 'timeleft', 'identity', 'fqan', 'all'] if option: if option not in validOptions: S_ERROR('Non valid option %s' % option) retVal = File.multiProxyArgument(proxy) if not retVal['OK']: return retVal proxyDict = retVal['Value'] # chain = proxyDict[ 'chain' ] proxyLocation = proxyDict['file'] if not Os.which("voms-proxy-info"): return S_ERROR("Missing voms-proxy-info") cmd = 'voms-proxy-info -file %s' % proxyLocation if option: cmd += ' -%s' % option result = shellCall(self._secCmdTimeout, cmd) if proxyDict['tempFile']: self._unlinkFiles(proxyLocation) if not result['OK']: return S_ERROR('Failed to call voms-proxy-info') status, output, error = result['Value'] # FIXME: if the local copy of the voms server certificate is not up to date the command returns 0. # the stdout needs to be parsed. if status: gLogger.warn('Failed to execute:', cmd) gLogger.warn('Exit code:', status) gLogger.warn('StdOut', output) gLogger.warn('StdErr', error) if error.find( 'VOMS extension not found' ) == -1 and \ not error.find( 'WARNING: Unable to verify signature! Server certificate possibly not installed.' ) == 0: return S_ERROR( 'Failed to get proxy info. Command: %s; StdOut: %s; StdErr: %s' % (cmd, output, error)) if option == 'fqan': if output: output = output.split('/Role')[0] else: output = '/lhcb' return S_OK(output)