def main(): Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient prodClient = ProductionClient() res = prodClient.getProductions() fields = [ 'ProductionName', 'Status', 'ProductionID', 'CreationDate', 'LastUpdate', 'AuthorDN', 'AuthorGroup' ] records = [] if res['OK']: prodList = res['Value'] if not isinstance(res['Value'], list): prodList = [res['Value']] for prod in prodList: records.append([ str(prod['ProductionName']), str(prod['Status']), str(prod['ProductionID']), str(prod['CreationDate']), str(prod['LastUpdate']), str(prod['AuthorDN']), str(prod['AuthorGroup']) ]) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) printTable(fields, records) DIRAC.exit(0)
def main(): Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient prodClient = ProductionClient() res = prodClient.getProductions() fields = ["ProductionName", "Status", "ProductionID", "CreationDate", "LastUpdate", "AuthorDN", "AuthorGroup"] records = [] if res["OK"]: prodList = res["Value"] if not isinstance(res["Value"], list): prodList = [res["Value"]] for prod in prodList: records.append( [ str(prod["ProductionName"]), str(prod["Status"]), str(prod["ProductionID"]), str(prod["CreationDate"]), str(prod["LastUpdate"]), str(prod["AuthorDN"]), str(prod["AuthorGroup"]), ] ) else: DIRAC.gLogger.error(res["Message"]) DIRAC.exit(-1) printTable(fields, records) DIRAC.exit(0)
def do_sites(self, args): """ List available cloud sites """ result = getVMTypes() print result siteDict = result['Value'] records = [] for site in siteDict: ceStart = True for ce in siteDict[site]: vmStart = True for vmType in siteDict[site][ce]['VMTypes']: flavor = siteDict[site][ce]['VMTypes'][vmType].get( 'FlavorName', 'Unknown') image = siteDict[site][ce]['VMTypes'][vmType].get( 'Image', siteDict[site][ce]['VMTypes'][vmType].get( 'ImageID', 'Unknown')) if ceStart and vmStart: records.append([site, ce, vmType, flavor, image]) elif ceStart: records.append(['', '', vmType, flavor, image]) else: records.append(['', ce, vmType, flavor, image]) vmStart = False ceStart = False fields = ['Site', 'Endpoint', 'VM Type', "Flavor", "Image"] printTable(fields, records)
def do_sites(self, args): """List available cloud sites""" result = getVMTypes() print(result) siteDict = result["Value"] records = [] for site in siteDict: ceStart = True for ce in siteDict[site]: vmStart = True for vmType in siteDict[site][ce]["VMTypes"]: flavor = siteDict[site][ce]["VMTypes"][vmType].get( "FlavorName", "Unknown") image = siteDict[site][ce]["VMTypes"][vmType].get( "Image", siteDict[site][ce]["VMTypes"][vmType].get( "ImageID", "Unknown")) if ceStart and vmStart: records.append([site, ce, vmType, flavor, image]) elif ceStart: records.append(["", "", vmType, flavor, image]) else: records.append(["", ce, vmType, flavor, image]) vmStart = False ceStart = False fields = ["Site", "Endpoint", "VM Type", "Flavor", "Image"] printTable(fields, records)
def _printVersions(): """Print the ILCDIRAC and DIRAC versions and other information.""" fields, records = getInfo() records.insert(0, ("ILCDirac Version:", ILCDIRAC.version)) records.insert(1, ("DIRAC version:", DIRAC.version)) printTable(fields, records, numbering=False)
def printPilotsLogging(logs): """ Print results using printTable from PrettyPrint """ content = [] labels = ['pilotUUID', 'timestamp', 'source', 'phase', 'status', 'messageContent'] for log in logs: content.append([log[label] for label in labels]) printTable(labels, content, numbering=False, columnSeparator=' | ')
def main(): Script.setUsageMessage("\n".join([ "Get VM nodes information", "Usage:", "%s [option]... [cfgfile]" % Script.scriptName, "Arguments:", " cfgfile: DIRAC Cfg with description of the configuration (optional)", ])) Script.registerSwitch("S:", "Site=", "Site Name", setSite) Script.registerSwitch("C:", "CE=", "Cloud Endpoint Name ", setCE) Script.registerSwitch("I:", "Image=", "Image Name", setImage) Script.registerSwitch("v:", "vo=", "VO name", setVO) Script.parseCommandLine(ignoreErrors=True) args = Script.getExtraCLICFGFiles() from DIRAC.WorkloadManagementSystem.Client.VMClient import VMClient from DIRAC.Core.Security.ProxyInfo import getVOfromProxyGroup from DIRAC.Core.Utilities.PrettyPrint import printTable siteList = None if site is not None: siteList = [s.strip() for s in site.split(",")] ceList = None if ce is not None: ceList = [c.strip() for c in ce.split(",")] voName = vo if voName is None: result = getVOfromProxyGroup() if result["OK"]: voName = result["Value"] records = [] vmClient = VMClient() result = vmClient.getCEInstances(siteList, ceList, voName) if not result["OK"]: gLogger.error(result["Message"]) DIRACExit(-1) for nodeID in result["Value"]: nodeDict = result["Value"][nodeID] record = [ nodeDict["Site"], nodeDict["CEName"], nodeID, nodeDict["NodeName"], nodeDict["PublicIP"], nodeDict["State"], ] records.append(record) fields = ["Site", "Endpoint", "ID", "Name", "PublicIP", "State"] printTable(fields, records) DIRACExit(0)
def printPilotsLogging(logs): """ Print results using printTable from PrettyPrint """ content = [] labels = [ 'pilotUUID', 'timestamp', 'source', 'phase', 'status', 'messageContent' ] for log in logs: content.append([log[label] for label in labels]) printTable(labels, content, numbering=False, columnSeparator=' | ')
def main(): Script.parseCommandLine() from DIRAC.Core.Utilities.PrettyPrint import printTable from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient prodClient = ProductionClient() # get arguments args = Script.getPositionalArgs() if len(args) < 1: Script.showHelp(exitCode=1) else: prodID = args[0] res = prodClient.getProduction(prodID) fields = [ 'ProductionName', 'Status', 'ProductionID', 'CreationDate', 'LastUpdate', 'AuthorDN', 'AuthorGroup'] records = [] if res['OK']: prodList = res['Value'] if not isinstance(res['Value'], list): prodList = [res['Value']] for prod in prodList: records.append( [ str( prod['ProductionName']), str( prod['Status']), str( prod['ProductionID']), str( prod['CreationDate']), str( prod['LastUpdate']), str( prod['AuthorDN']), str( prod['AuthorGroup'])]) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) printTable(fields, records) DIRAC.exit(0)
def sendNotification(self): """Send email notification about changes done in the last cycle.""" if not(self.errors or self.accounting): return S_OK() emailBody = "" rows = [] for instanceName, val in self.accounting.iteritems(): rows.append([[instanceName], [val.get('Treatment', 'No Treatment')], [str(val.get('LogAge', 'Not Relevant'))]]) if rows: columns = ["Instance", "Treatment", "Log File Age (Minutes)"] emailBody += printTable(columns, rows, printOut=False, numbering=False, columnSeparator=' | ') if self.errors: emailBody += "\n\nErrors:" emailBody += "\n".join(self.errors) self.log.notice("Sending Email:\n" + emailBody) for address in self.addressTo: res = self.nClient.sendMail(address, self.emailSubject, emailBody, self.addressFrom, localAttempt=False) if not res['OK']: self.log.error("Failure to send Email notification to ", address) continue self.errors = [] self.accounting.clear() return S_OK()
def printSEInfo(voName): fields = ("SE", "Status", "Protocols", "Aliases") records = [] for se in DMSHelpers(voName).getStorageElements( ): # this will get the full list of SEs, not only the vo's ones. seObject = StorageElement(se) if not (seObject.vo and voName in seObject.vo.strip().split(",") or not seObject.voName): continue result = seObject.status() status = [] for statusType in ["Write", "Read"]: if result[statusType]: status.append(statusType) if status: status = "/".join(status) else: status = "InActive" records.append((se, status, ",".join([ seProtocol["Protocol"] for seProtocol in seObject.protocolOptions ]))) gLogger.notice( printTable(fields, records, printOut=False, columnSeparator=" ")) return S_OK()
def tabularPrint(elementsList): ''' Prints the list of elements on a tabular ''' LJUST = 25 subLogger.notice('') subLogger.notice('Selection parameters:') subLogger.notice(' %s: %s' % ('element'.ljust(15), switchDict['element'])) titles = [] for key in ('Name', 'StatusType', 'Status', 'ElementType', 'TokenOwner'): #Transforms from upper lower case to lower upper case keyT = key[0].lower() + key[1:] if switchDict[keyT] is None: titles.append(key) else: subLogger.notice(' %s: %s' % (key.ljust(15), switchDict[keyT])) subLogger.notice('') subLogger.notice( printTable(titles, elementsList, printOut=False, numbering=False, columnSeparator=' | '))
def printSEInfo(voName): result = Resources.getStorageElements(vo=voName) if not result['OK']: gLogger.error('Failed to get SE information') DIRACExit(-1) seDict = result['Value'] fields = ('SE', 'Status', 'Protocols', 'Aliases') records = [] for se in seDict: seObject = StorageElement(se) result = seObject.status() status = [] for statusType in ['Write', 'Read']: if result[statusType]: status.append(statusType) if status: status = '/'.join(status) else: status = "InActive" records.append((se, status, ",".join(seDict[se]["Protocols"]), ",".join(seDict[se]["Aliases"]))) gLogger.notice( printTable(fields, records, printOut=False, columnSeparator=' ')) return S_OK()
def tabularPrint(elementsList): """ Prints the list of elements on a tabular """ subLogger.notice("") subLogger.notice("Selection parameters:") subLogger.notice(" %s: %s" % ("element".ljust(15), switchDict["element"])) titles = [] for key in ("Name", "StatusType", "Status", "ElementType", "TokenOwner"): # Transforms from upper lower case to lower upper case keyT = key[0].lower() + key[1:] if switchDict[keyT] is None: titles.append(key) else: subLogger.notice(" %s: %s" % (key.ljust(15), switchDict[keyT])) subLogger.notice("") subLogger.notice( printTable(titles, elementsList, printOut=False, numbering=False, columnSeparator=" | "))
def getVOUserReport(self, vo): """ :param str vo: VO name :return: report string """ result = self.getVOUserData(vo, refreshFlag=True) if not result['OK']: return result userDict = result['Value'] # Get DIRAC group vs VOMS Role Mappings result = getVOMSRoleGroupMapping(vo) if not result['OK']: return result diracVOMSMapping = result['Value']['DIRACVOMS'] records = [] groupDict = defaultdict(int) multiDNUsers = {} suspendedUsers = [] for user in userDict: for group in userDict[user]['Groups']: groupDict[group] += 1 dnList = fromChar(userDict[user]['DN']) if len(dnList) > 1: multiDNUsers[user] = dnList if userDict[user].get('Status', 'Active') == 'Suspended': suspendedUsers.append(user) for group in diracVOMSMapping: records.append( (group, str(groupDict[group]), diracVOMSMapping.get(group, ''))) fields = ['Group', 'Number of users', 'VOMS Role'] output = printTable(fields, records, sortField='Group', printOut=False, numbering=False) if multiDNUsers: output += '\nUsers with multiple DNs:\n' for user in multiDNUsers: output += ' %s:\n' % user for dn in multiDNUsers[user]: output += ' %s\n' % dn if suspendedUsers: output += '\n%d suspended users:\n' % len(suspendedUsers) output += ' %s' % ','.join(suspendedUsers) return S_OK(output)
def getErrors(self, argss): """ Get and print out errors from the logs of specified components """ component = '' if len(argss) < 1: component = '*' else: system = argss[0] if system == "*": component = '*' else: if len(argss) < 2: print print self.do_show.__doc__ return comp = argss[1] component = '/'.join([system, comp]) client = SystemAdministratorClient(self.host, self.port) result = client.checkComponentLog(component) if not result['OK']: self.__errMsg(result['Message']) else: fields = [ 'System', 'Component', 'Last hour', 'Last day', 'Last error' ] records = [] for cname in result['Value']: system, component = cname.split('/') errors_1 = result['Value'][cname]['ErrorsHour'] errors_24 = result['Value'][cname]['ErrorsDay'] lastError = result['Value'][cname]['LastError'] lastError.strip() if len(lastError) > 80: lastError = lastError[:80] + '...' records.append([ system, component, str(errors_1), str(errors_24), lastError ]) records.sort() printTable(fields, records)
def main(): # Registering arguments will automatically add their description to the help menu Script.registerArgument("prodID: Production ID") _, args = Script.parseCommandLine() from DIRAC.Core.Utilities.PrettyPrint import printTable from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient prodClient = ProductionClient() # get arguments prodID = args[0] res = prodClient.getProduction(prodID) fields = [ "ProductionName", "Status", "ProductionID", "CreationDate", "LastUpdate", "AuthorDN", "AuthorGroup" ] records = [] if res["OK"]: prodList = res["Value"] if not isinstance(res["Value"], list): prodList = [res["Value"]] for prod in prodList: records.append([ str(prod["ProductionName"]), str(prod["Status"]), str(prod["ProductionID"]), str(prod["CreationDate"]), str(prod["LastUpdate"]), str(prod["AuthorDN"]), str(prod["AuthorGroup"]), ]) else: DIRAC.gLogger.error(res["Message"]) DIRAC.exit(-1) printTable(fields, records) DIRAC.exit(0)
def getVOUserReport( self, vo ): """ :param str vo: VO name :return: report string """ result = self.getVOUserData( vo, refreshFlag = True ) if not result['OK']: return result userDict = result['Value'] # Get DIRAC group vs VOMS Role Mappings result = getVOMSRoleGroupMapping( vo ) if not result['OK']: return result diracVOMSMapping = result['Value']['DIRACVOMS'] records = [] groupDict = defaultdict( int ) multiDNUsers = {} suspendedUsers = [] for user in userDict: for group in userDict[user]['Groups']: groupDict[group] += 1 dnList = fromChar( userDict[user]['DN'] ) if len( dnList ) > 1: multiDNUsers[user] = dnList if userDict[user].get( 'Status', 'Active' ) == 'Suspended': suspendedUsers.append( user ) for group in diracVOMSMapping: records.append( ( group, str( groupDict[group] ), diracVOMSMapping.get( group, '' ) ) ) fields = [ 'Group', 'Number of users', 'VOMS Role' ] output = printTable( fields, records, sortField = 'Group', printOut = False, numbering = False ) if multiDNUsers: output += '\nUsers with multiple DNs:\n' for user in multiDNUsers: output += ' %s:\n' % user for dn in multiDNUsers[user]: output += ' %s\n' % dn if suspendedUsers: output += '\n%d suspended users:\n' % len( suspendedUsers ) output += ' %s' % ','.join( suspendedUsers ) return S_OK( output )
def getVOUserReport(self): """Get a report string with the current status of the DIRAC Registry for the Virtual Organization :return: S_OK with the report string as Value """ result = self.getVOUserData(refreshFlag=True) if not result["OK"]: return result userDict = result["Value"] # Get DIRAC group vs VOMS Role Mappings result = getVOMSRoleGroupMapping(self.vo) if not result["OK"]: return result diracVOMSMapping = result["Value"]["DIRACVOMS"] records = [] groupDict = defaultdict(int) multiDNUsers = {} suspendedUsers = [] for user in userDict: for group in userDict[user]["Groups"]: groupDict[group] += 1 dnList = fromChar(userDict[user]["DN"]) if len(dnList) > 1: multiDNUsers[user] = dnList if userDict[user].get("Status", "Active") == "Suspended": suspendedUsers.append(user) for group in diracVOMSMapping: records.append((group, str(groupDict[group]), diracVOMSMapping.get(group, ""))) fields = ["Group", "Number of users", "VOMS Role"] output = printTable(fields, records, sortField="Group", printOut=False, numbering=False) if multiDNUsers: output += "\nUsers with multiple DNs:\n" for user in multiDNUsers: output += " %s:\n" % user for dn in multiDNUsers[user]: output += " %s\n" % dn if suspendedUsers: output += "\n%d suspended users:\n" % len(suspendedUsers) output += " %s" % ",".join(suspendedUsers) return S_OK(output)
def getErrors( self, argss ): """ Get and print out errors from the logs of specified components """ component = '' if len( argss ) < 1: component = '*' else: system = argss[0] if system == "*": component = '*' else: if len( argss ) < 2: print print self.do_show.__doc__ return comp = argss[1] component = '/'.join( [system, comp] ) client = SystemAdministratorClient( self.host, self.port ) result = client.checkComponentLog( component ) if not result['OK']: self.__errMsg( result['Message'] ) else: fields = ['System', 'Component', 'Last hour', 'Last day', 'Last error'] records = [] for cname in result['Value']: system, component = cname.split( '/' ) errors_1 = result['Value'][cname]['ErrorsHour'] errors_24 = result['Value'][cname]['ErrorsDay'] lastError = result['Value'][cname]['LastError'] lastError.strip() if len( lastError ) > 80: lastError = lastError[:80] + '...' records.append( [system, component, str( errors_1 ), str( errors_24 ), lastError] ) records.sort() printTable( fields, records )
def tabularPrint(table): columns_names = table[0].keys() records = [] for row in table: record = [] for k, v in row.items(): if type(v) == datetime.datetime: record.append(Time.toString(v)) elif v is None: record.append("") else: record.append(v) records.append(record) output = printTable(columns_names, records, numbering=False, columnSeparator=" | ", printOut=False) subLogger.notice(output)
def tabularPrint(table): columns_names = list(table[0]) records = [] for row in table: record = [] for k, v in row.items(): if isinstance(v, datetime.datetime): record.append(Time.toString(v)) elif v is None: record.append("") else: record.append(v) records.append(record) output = printTable(columns_names, records, numbering=False, columnSeparator=" | ", printOut=False) subLogger.notice(output)
def printCEInfo(voName): resultQueues = Resources.getQueues(community=voName) if not resultQueues['OK']: gLogger.error('Failed to get CE information') DIRACExit(-1) fields = ("Site", 'CE', 'CEType', 'Queue', 'Status') records = [] # get list of usable sites within this cycle resultMask = SiteStatus().getUsableSites() if not resultMask['OK']: return resultMask siteMaskList = resultMask.get('Value', []) rssClient = ResourceStatus() for site in resultQueues['Value']: siteStatus = "Active" if site in siteMaskList else "InActive" siteNew = True for ce in resultQueues['Value'][site]: ceStatus = siteStatus if rssClient.rssFlag: result = rssClient.getElementStatus(ce, "ComputingElement") if result['OK']: ceStatus = result['Value'][ce]['all'] ceNew = True for queue in resultQueues['Value'][site][ce]['Queues']: pSite = site if siteNew else '' pCE = '' ceType = '' if ceNew: pCE = ce ceType = resultQueues['Value'][site][ce]['CEType'] records.append((pSite, pCE, ceType, queue, ceStatus)) ceNew = False siteNew = False gLogger.notice( printTable(fields, records, printOut=False, columnSeparator=' ')) return S_OK()
def printCEInfo(voName): resultQueues = Resources.getQueues(community=voName) if not resultQueues["OK"]: gLogger.error("Failed to get CE information") DIRACExit(-1) fields = ("Site", "CE", "CEType", "Queue", "Status") records = [] # get list of usable sites within this cycle resultMask = SiteStatus().getUsableSites() if not resultMask["OK"]: return resultMask siteMaskList = resultMask.get("Value", []) rssClient = ResourceStatus() for site in resultQueues["Value"]: siteStatus = "Active" if site in siteMaskList else "InActive" siteNew = True for ce in resultQueues["Value"][site]: ceStatus = siteStatus if rssClient.rssFlag: result = rssClient.getElementStatus(ce, "ComputingElement") if result["OK"]: ceStatus = result["Value"][ce]["all"] ceNew = True for queue in resultQueues["Value"][site][ce]["Queues"]: pSite = site if siteNew else "" pCE = "" ceType = "" if ceNew: pCE = ce ceType = resultQueues["Value"][site][ce]["CEType"] records.append((pSite, pCE, ceType, queue, ceStatus)) ceNew = False siteNew = False gLogger.notice( printTable(fields, records, printOut=False, columnSeparator=" ")) return S_OK()
def sendNotification(self, transID, transType=None, sourceSEs=None, targetSEs=None): """ sends email notification about accounting information of a transformation """ if not(self.errors or self.accounting): return S_OK() emailBody = "Transformation ID: %s\n" % transID if transType: emailBody += "Transformation Type: %s\n" % transType if sourceSEs: emailBody += "Source SE: %s\n" % (" ".join(str(source) for source in sourceSEs)) if targetSEs: emailBody += "Target SE: %s\n\n" % (" ".join(str(target) for target in targetSEs)) rows = [] for action, transFiles in self.accounting.iteritems(): emailBody += "Total number of files with action %s: %s\n" % (action, len(transFiles)) for transFile in transFiles: rows.append([[transFile['LFN']], [str(transFile['AvailableOnSource'])], [str(transFile['AvailableOnTarget'])], [transFile['Status']], [action]]) if rows: columns = ["LFN", "Source", "Target", "Old Status", "Action"] emailBody += printTable(columns, rows, printOut=False, numbering=False, columnSeparator=' | ') if self.errors: emailBody += "\n\nErrors:" emailBody += "\n".join(self.errors) self.log.notice(emailBody) subject = "%s: %s" % (self.emailSubject, transID) for address in self.addressTo: res = self.nClient.sendMail(address, subject, emailBody, self.addressFrom, localAttempt=False) if not res['OK']: self.log.error("Failure to send Email notification to ", address) continue self.errors = [] self.accounting.clear() return S_OK()
def sendNotification(self): """Send email notification about changes done in the last cycle.""" if not (self.errors or self.accounting): return S_OK() emailBody = "" rows = [] for instanceName, val in self.accounting.items(): rows.append([[instanceName], [val.get("Treatment", "No Treatment")], [str(val.get("LogAge", "Not Relevant"))]]) if rows: columns = ["Instance", "Treatment", "Log File Age (Minutes)"] emailBody += printTable(columns, rows, printOut=False, numbering=False, columnSeparator=" | ") if self.errors: emailBody += "\n\nErrors:" emailBody += "\n".join(self.errors) self.log.notice("Sending Email:\n" + emailBody) for address in self.addressTo: res = self.nClient.sendMail(address, self.emailSubject, emailBody, self.addressFrom, localAttempt=False) if not res["OK"]: self.log.error("Failure to send Email notification to ", address) continue self.errors = [] self.accounting.clear() return S_OK()
def tabularPrint( elementsList ): ''' Prints the list of elements on a tabular ''' subLogger.notice( '' ) subLogger.notice( 'Selection parameters:' ) subLogger.notice( ' %s: %s' % ( 'element'.ljust( 15 ), switchDict[ 'element' ] ) ) titles = [] for key in ( 'Name', 'StatusType', 'Status', 'ElementType', 'TokenOwner' ): #Transforms from upper lower case to lower upper case keyT = key[0].lower() + key[1:] if switchDict[ keyT ] is None: titles.append( key ) else: subLogger.notice( ' %s: %s' % ( key.ljust( 15 ), switchDict[ keyT ] ) ) subLogger.notice( '' ) subLogger.notice( printTable( titles, elementsList, printOut = False, numbering = False, columnSeparator = ' | ' ) )
def tabularPrint(elementsList): """ Prints the list of elements on a tabular """ LJUST = 25 subLogger.notice("") subLogger.notice("Selection parameters:") subLogger.notice(" %s: %s" % ("element".ljust(15), switchDict["element"])) titles = [] for key in ("Name", "StatusType", "Status", "ElementType", "TokenOwner"): # Transforms from upper lower case to lower upper case keyT = key[0].lower() + key[1:] if switchDict[keyT] is None: titles.append(key) else: subLogger.notice(" %s: %s" % (key.ljust(15), switchDict[keyT])) subLogger.notice("") subLogger.notice(printTable(titles, elementsList, printOut=False, numbering=False, columnSeparator=" | "))
DIRAC.exit( 1 ) fields = ['SE','ReadAccess','WriteAccess','RemoveAccess','CheckAccess'] records = [] result = getVOfromProxyGroup() if not result['OK']: gLogger.error( 'Failed to determine the user VO' ) DIRAC.exit( -1 ) vo = result['Value'] for se, statusDict in res[ 'Value' ].items(): # Check if the SE is allowed for the user VO voList = gConfig.getValue( '/Resources/StorageElements/%s/VO' % se, [] ) if voList and not vo in voList: continue record = [se] for status in fields[1:]: value = statusDict.get( status, 'Unknown' ) record.append( value ) records.append( record ) printTable( fields, records, numbering=False, sortField = 'SE' ) DIRAC.exit( 0 ) ################################################################################ # EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
def do_show( self, args ): """ Show list of components with various related information usage: show software - show components for which software is available show installed - show components installed in the host with runit system show setup - show components set up for automatic running in the host show project - show project to install or upgrade show status - show status of the installed components show database - show status of the databases show mysql - show status of the MySQL server show log <system> <service|agent> [nlines] - show last <nlines> lines in the component log file show info - show version of software and setup show doc <type> <system> <name> - show documentation for a given service or agent show host - show host related parameters show hosts - show all available hosts show ports [host] - show all ports used by a host. If no host is given, the host currently connected to is used show installations [ list | current | -n <Name> | -h <Host> | -s <System> | -m <Module> | -t <Type> | -itb <InstallationTime before> | -ita <InstallationTime after> | -utb <UnInstallationTime before> | -uta <UnInstallationTime after> ]* - show all the installations of components that match the given parameters show profile <system> <component> [ -s <size> | -h <host> | -id <initial date DD/MM/YYYY> | -it <initial time hh:mm> | -ed <end date DD/MM/YYYY | -et <end time hh:mm> ]* - show <size> log lines of profiling information for a component in the machine <host> show errors [*|<system> <service|agent>] - show error count for the given component or all the components in the last hour and day """ argss = args.split() if not argss: gLogger.notice( self.do_show.__doc__ ) return option = argss[0] del argss[0] if option == 'software': client = SystemAdministratorClient( self.host, self.port ) result = client.getSoftwareComponents() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( "Current project is %s" % result[ 'Value' ] ) elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: self._errMsg( result['Message'] ) else: fields = ["System",'Name','Module','Type','Setup','Installed','Runit','Uptime','PID'] records = [] rDict = result['Value'] for compType in rDict: for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: record = [] if rDict[compType][system][component]['Installed']: module = str( rDict[compType][system][component]['Module'] ) record += [ system,component,module,compType.lower()[:-1]] if rDict[compType][system][component]['Setup']: record += ['Setup'] else: record += ['NotSetup'] if rDict[compType][system][component]['Installed']: record += ['Installed'] else: record += ['NotInstalled'] record += [str( rDict[compType][system][component]['RunitStatus'] )] record += [str( rDict[compType][system][component]['Timeup'] )] record += [str( rDict[compType][system][component]['PID'] )] records.append(record) printTable(fields,records) elif option == 'database' or option == 'databases': client = SystemAdministratorClient( self.host, self.port ) if not gComponentInstaller.mysqlPassword: gComponentInstaller.mysqlPassword = "******" gComponentInstaller.getMySQLPasswords() result = client.getDatabases( gComponentInstaller.mysqlRootPwd ) if not result['OK']: self._errMsg( result['Message'] ) return resultSW = client.getAvailableDatabases() if not resultSW['OK']: self._errMsg( resultSW['Message'] ) return sw = resultSW['Value'] installed = result['Value'] gLogger.notice( '' ) for db in sw: if db in installed: gLogger.notice( db.rjust( 25 ), ': Installed' ) else: gLogger.notice( db.rjust( 25 ), ': Not installed' ) if not sw: gLogger.notice( "No database found" ) elif option == 'mysql': client = SystemAdministratorClient( self.host, self.port ) result = client.getMySQLStatus() if not result['OK']: self._errMsg( result['Message'] ) elif result['Value']: gLogger.notice( '' ) for par, value in result['Value'].items(): gLogger.notice( ( par.rjust( 28 ), ':', value ) ) else: gLogger.notice( "No MySQL database found" ) elif option == "log": self.getLog( argss ) elif option == "info": client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Setup:", result['Value']['Setup'] ) gLogger.notice( "DIRAC version:", result['Value']['DIRAC'] ) if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): gLogger.notice( "%s version" % e, v ) gLogger.notice( '' ) elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Host info:" ) gLogger.notice( '' ) fields = ['Parameter','Value'] records = [] for parameter in result['Value'].iteritems(): if parameter[0] == 'Extension': extensions = parameter[1].split( ',' ) for extension in extensions: extensionName, extensionVersion = extension.split( ':' ) records.append( [ '%sVersion' % extensionName, str( extensionVersion ) ] ) else: records.append( [ parameter[0], str( parameter[1] ) ] ) printTable( fields, records ) elif option == "hosts": client = ComponentMonitoringClient() result = client.getHosts( {}, False, False ) if not result[ 'OK' ]: self._errMsg( 'Error retrieving the list of hosts: %s' % ( result[ 'Message' ] ) ) else: hostList = result[ 'Value' ] gLogger.notice( '' ) gLogger.notice( ' ' + 'Host'.center( 32 ) + ' ' + 'CPU'.center( 34 ) + ' ' ) gLogger.notice( ( '-' * 69 ) ) for element in hostList: gLogger.notice( '|' + element[ 'HostName' ].center( 32 ) + '|' + element[ 'CPU' ].center( 34 ) + '|' ) gLogger.notice( ( '-' * 69 ) ) gLogger.notice( '' ) elif option == "ports": if not argss: client = SystemAdministratorClient( self.host ) else: hostname = argss[0] del argss[0] client = ComponentMonitoringClient() result = client.hostExists( { 'HostName': hostname } ) if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return else: if not result[ 'Value' ]: self._errMsg( 'Given host does not exist' ) return client = SystemAdministratorClient( hostname ) result = client.getUsedPorts() if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return pprint.pprint( result[ 'Value' ] ) elif option == "errors": self.getErrors( argss ) elif option == "installations": self.getInstallations( argss ) elif option == "doc": if len( argss ) > 2: if argss[0] in [ 'service', 'agent' ]: compType = argss[0] compSystem = argss[1] compModule = argss[2] client = SystemAdministratorClient( self.host, self.port ) result = client.getComponentDocumentation( compType, compSystem, compModule ) if result[ 'OK' ]: gLogger.notice( result[ 'Value' ] ) else: self._errMsg( result[ 'Message' ] ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( self.do_show.__doc__ ) elif option == "profile": if len( argss ) > 1: system = argss[0] del argss[0] component = argss[0] del argss[0] component = '%s_%s' % ( system, component ) argDict = { '-s': None, '-h': self.host, '-id': None, '-it': '00:00', '-ed': None, '-et': '00:00' } key = None for arg in argss: if not key: key = arg else: argDict[ key ] = arg key = None size = None try: if argDict[ '-s' ]: size = int( argDict[ '-s' ] ) except ValueError as _ve: self._errMsg( 'Argument \'size\' must be an integer' ) return host = argDict[ '-h' ] initialDate = argDict[ '-id' ] initialTime = argDict[ '-it' ] endingDate = argDict[ '-ed' ] endingTime = argDict[ '-et' ] if initialDate: initialDate = '%s %s' % ( initialDate, initialTime ) else: initialDate = '' if endingDate: endingDate = '%s %s' % ( endingDate, endingTime ) else: endingDate = '' client = MonitoringClient() if size: result = client.getLimitedData( host, component, size ) else: result = client.getDataForAGivenPeriod( host, component, initialDate, endingDate ) if result[ 'OK' ]: text = '' headers = [result['Value'][0].keys()] for header in headers: text += str( header ).ljust( 15 ) gLogger.notice( text ) for record in result[ 'Value' ]: for metric in record.itervalues(): text += str( metric ).ljust( 15 ) gLogger.notice( text ) else: self._errMsg( result[ 'Message' ] ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( "Unknown option:", option )
def do_showall( self, args ): """ Show status of all the components in all the hosts Usage: showall [-snmth] [-ASE] [-N name] [-H host] - show status of components Options: -d extra debug printout Sorting options: -s system -n component name -m component module -t component type -h component host Selection options: -A select agents -S select services -E select executors -N <component pattern> select component with the name containing the pattern -H <host name> select the given host -T <setup name> select the given setup """ argss = args.split() sortOption = '' componentType = '' componentName = '' hostName = '' setupName = '' debug = False while len( argss ) > 0: option = argss[0] del argss[0] sortOption = '' if option == '-s': sortOption = "System" elif option == '-n': sortOption = "Name" elif option == '-m': sortOption = "Module" elif option == '-t': sortOption = "Type" elif option == '-h': sortOption = "Host" elif option == "-A": componentType = 'Agents' elif option == "-S": componentType = 'Services' elif option == "-E": componentType = 'Executors' elif option == "-d": debug = True elif option == "-N": componentName = argss[0] del argss[0] elif option == "-H": hostName = argss[0] del argss[0] elif option == "-T": setupName = argss[0] del argss[0] else: self.__errMsg( 'Invalid option %s' % option ) return client = SystemAdministratorIntegrator() resultAll = client.getOverallStatus() resultInfo = client.getInfo() if not resultAll['OK']: self.__errMsg( resultAll['Message'] ) else: fields = ["System",'Name','Module','Type','Setup','Host','Runit','Uptime'] records = [] for host in resultAll['Value']: if hostName and not hostName in host: continue result = resultAll['Value'][host] if not result['OK']: if debug: self.__errMsg( "Host %s: %s" % (host,result['Message']) ) continue rDict = result['Value'] for compType in rDict: if componentType and componentType != compType: continue for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: if componentName and not componentName in component: continue record = [] if rDict[compType][system][component]['Installed']: module = str( rDict[compType][system][component]['Module'] ) record += [ system,component,module,compType.lower()[:-1]] if resultInfo['OK'] and host in resultInfo['Value'] and resultInfo['Value'][host]['OK']: setup = resultInfo['Value'][host]['Value']['Setup'] else: setup = 'Unknown' if setupName and not setupName in setup: continue record += [setup] record += [host] record += [str( rDict[compType][system][component]['RunitStatus'] )] record += [str( rDict[compType][system][component]['Timeup'] )] records.append(record) printTable( fields, records, sortOption )
def do_show( self, args ): """ Show list of components with various related information usage: show software - show components for which software is available show installed - show components installed in the host with runit system show setup - show components set up for automatic running in the host show project - show project to install or upgrade show status - show status of the installed components show database - show status of the databases show mysql - show status of the MySQL server show log <system> <service|agent> [nlines] - show last <nlines> lines in the component log file show info - show version of software and setup show host - show host related parameters show hosts - show all available hosts show installations [ list | current | -n <Name> | -h <Host> | -s <System> | -m <Module> | -t <Type> | -itb <InstallationTime before> | -ita <InstallationTime after> | -utb <UnInstallationTime before> | -uta <UnInstallationTime after> ]* - show all the installations of components that match the given parameters show errors [*|<system> <service|agent>] - show error count for the given component or all the components in the last hour and day """ argss = args.split() if not argss: gLogger.notice( self.do_show.__doc__ ) return option = argss[0] del argss[0] if option == 'software': client = SystemAdministratorClient( self.host, self.port ) result = client.getSoftwareComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( "Current project is %s" % result[ 'Value' ] ) elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: self.__errMsg( result['Message'] ) else: fields = ["System",'Name','Module','Type','Setup','Installed','Runit','Uptime','PID'] records = [] rDict = result['Value'] for compType in rDict: for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: record = [] if rDict[compType][system][component]['Installed']: module = str( rDict[compType][system][component]['Module'] ) record += [ system,component,module,compType.lower()[:-1]] if rDict[compType][system][component]['Setup']: record += ['Setup'] else: record += ['NotSetup'] if rDict[compType][system][component]['Installed']: record += ['Installed'] else: record += ['NotInstalled'] record += [str( rDict[compType][system][component]['RunitStatus'] )] record += [str( rDict[compType][system][component]['Timeup'] )] record += [str( rDict[compType][system][component]['PID'] )] records.append(record) printTable(fields,records) elif option == 'database' or option == 'databases': client = SystemAdministratorClient( self.host, self.port ) if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = "******" InstallTools.getMySQLPasswords() result = client.getDatabases( InstallTools.mysqlRootPwd ) if not result['OK']: self.__errMsg( result['Message'] ) return resultSW = client.getAvailableDatabases() if not resultSW['OK']: self.__errMsg( resultSW['Message'] ) return sw = resultSW['Value'] installed = result['Value'] gLogger.notice( '' ) for db in sw: if db in installed: gLogger.notice( db.rjust( 25 ), ': Installed' ) else: gLogger.notice( db.rjust( 25 ), ': Not installed' ) if not sw: gLogger.notice( "No database found" ) elif option == 'mysql': client = SystemAdministratorClient( self.host, self.port ) result = client.getMySQLStatus() if not result['OK']: self.__errMsg( result['Message'] ) elif result['Value']: gLogger.notice( '' ) for par, value in result['Value'].items(): gLogger.notice( ( par.rjust( 28 ), ':', value ) ) else: gLogger.notice( "No MySQL database found" ) elif option == "log": self.getLog( argss ) elif option == "info": client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Setup:", result['Value']['Setup'] ) gLogger.notice( "DIRAC version:", result['Value']['DIRAC'] ) if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): gLogger.notice( "%s version" % e, v ) gLogger.notice( '' ) elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Host info:" ) gLogger.notice( '' ) fields = ['Parameter','Value'] records = [] for key, value in result['Value'].items(): records.append( [key, str( value ) ] ) printTable( fields, records ) elif option == "hosts": client = ComponentMonitoringClient() result = client.getHosts( {}, False, False ) if not result[ 'OK' ]: self.__errMsg( 'Error retrieving the list of hosts: %s' % ( result[ 'Message' ] ) ) else: hostList = result[ 'Value' ] gLogger.notice( '' ) gLogger.notice( ' ' + 'Host'.center( 32 ) + ' ' + 'CPU'.center( 34 ) + ' ' ) gLogger.notice( ( '-' * 69 ) ) for element in hostList: gLogger.notice( '|' + element[ 'HostName' ].center( 32 ) + '|' + element[ 'CPU' ].center( 34 ) + '|' ) gLogger.notice( ( '-' * 69 ) ) gLogger.notice( '' ) elif option == "errors": self.getErrors( argss ) elif option == "installations": self.getInstallations( argss ) else: gLogger.notice( "Unknown option:", option )
def do_show( self, args ): """ Show list of components with various related information usage: show software - show components for which software is available show installed - show components installed in the host with runit system show setup - show components set up for automatic running in the host show project - show project to install or upgrade show status - show status of the installed components show database - show status of the databases show mysql - show status of the MySQL server show log <system> <service|agent> [nlines] - show last <nlines> lines in the component log file show info - show version of software and setup show host - show host related parameters show errors [*|<system> <service|agent>] - show error count for the given component or all the components in the last hour and day """ argss = args.split() if not argss: print self.do_show.__doc__ return option = argss[0] del argss[0] if option == 'software': client = SystemAdministratorClient( self.host, self.port ) result = client.getSoftwareComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: print pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: print pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: print pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self.__errMsg( result['Message'] ) else: print "Current project is %s" % result[ 'Value' ] elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: self.__errMsg( result['Message'] ) else: fields = ["System",'Name','Module','Type','Setup','Installed','Runit','Uptime','PID'] records = [] rDict = result['Value'] for compType in rDict: for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: record = [] if rDict[compType][system][component]['Installed']: module = str( rDict[compType][system][component]['Module'] ) record += [ system,component,module,compType.lower()[:-1]] if rDict[compType][system][component]['Setup']: record += ['Setup'] else: record += ['NotSetup'] if rDict[compType][system][component]['Installed']: record += ['Installed'] else: record += ['NotInstalled'] record += [str( rDict[compType][system][component]['RunitStatus'] )] record += [str( rDict[compType][system][component]['Timeup'] )] record += [str( rDict[compType][system][component]['PID'] )] records.append(record) printTable(fields,records) elif option == 'database' or option == 'databases': client = SystemAdministratorClient( self.host, self.port ) if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = "******" InstallTools.getMySQLPasswords() result = client.getDatabases( InstallTools.mysqlRootPwd ) if not result['OK']: self.__errMsg( result['Message'] ) return resultSW = client.getAvailableDatabases() if not resultSW['OK']: self.__errMsg( resultSW['Message'] ) return sw = resultSW['Value'] installed = result['Value'] print for db in sw: if db in installed: print db.rjust( 25 ), ': Installed' else: print db.rjust( 25 ), ': Not installed' if not sw: print "No database found" elif option == 'mysql': client = SystemAdministratorClient( self.host, self.port ) result = client.getMySQLStatus() if not result['OK']: self.__errMsg( result['Message'] ) elif result['Value']: print for par, value in result['Value'].items(): print par.rjust( 28 ), ':', value else: print "No MySQL database found" elif option == "log": self.getLog( argss ) elif option == "info": client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: print print "Setup:", result['Value']['Setup'] print "DIRAC version:", result['Value']['DIRAC'] if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): print "%s version" % e, v print elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: print print "Host info:" print fields = ['Parameter','Value'] records = [] for key,value in result['Value'].items(): records.append( [key, str(value) ] ) printTable( fields, records ) elif option == "errors": self.getErrors( argss ) else: print "Unknown option:", option
if not result['OK']: value = 'Unknown' else: value = result['Value'] else: value = tqData.get( key, '-' ) if type( value ) == types.ListType: if len( value ) > 1: record.append( str( value[0] ) + '...' ) else: record.append( str( value[0] ) ) else: record.append( str( value ) ) records.append( record ) printTable( fields, records ) else: fields = ['Key','Value'] for tqId in sorted( tqDict ): if taskQueueID and tqId != taskQueueID: continue print "\n==> TQ %s" % tqId records = [] tqData = tqDict[ tqId ] for key in sorted( tqData ): value = tqData[ key ] if type( value ) == types.ListType: value = ",".join( value ) else: value = str( value ) records.append( [key, value] )
if not result['OK']: value = 'Unknown' else: value = result['Value'] else: value = tqData.get(key, '-') if isinstance(value, list): if len(value) > 1: record.append(str(value[0]) + '...') else: record.append(str(value[0])) else: record.append(str(value)) records.append(record) printTable(fields, records) else: fields = ['Key', 'Value'] for tqId in sorted(tqDict): if taskQueueID and tqId != taskQueueID: continue gLogger.notice("\n==> TQ %s" % tqId) records = [] tqData = tqDict[tqId] for key in sorted(tqData): value = tqData[key] if isinstance(value, list): records.append([key, {"Value": value, 'Just': 'L'}]) else: value = str(value) records.append([key, {"Value": value, 'Just': 'L'}])
def do_show( self, args ): """ Show list of components with various related information usage: show software - show components for which software is available show installed - show components installed in the host with runit system show setup - show components set up for automatic running in the host show project - show project to install or upgrade show status - show status of the installed components show database - show status of the databases show mysql - show status of the MySQL server show log <system> <service|agent> [nlines] - show last <nlines> lines in the component log file show info - show version of software and setup show doc <type> <system> <name> - show documentation for a given service or agent show host - show host related parameters show hosts - show all available hosts show installations [ list | current | -n <Name> | -h <Host> | -s <System> | -m <Module> | -t <Type> | -itb <InstallationTime before> | -ita <InstallationTime after> | -utb <UnInstallationTime before> | -uta <UnInstallationTime after> ]* - show all the installations of components that match the given parameters show errors [*|<system> <service|agent>] - show error count for the given component or all the components in the last hour and day """ argss = args.split() if not argss: gLogger.notice( self.do_show.__doc__ ) return option = argss[0] del argss[0] if option == 'software': client = SystemAdministratorClient( self.host, self.port ) result = client.getSoftwareComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( "Current project is %s" % result[ 'Value' ] ) elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: self.__errMsg( result['Message'] ) else: fields = ["System",'Name','Module','Type','Setup','Installed','Runit','Uptime','PID'] records = [] rDict = result['Value'] for compType in rDict: for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: record = [] if rDict[compType][system][component]['Installed']: module = str( rDict[compType][system][component]['Module'] ) record += [ system,component,module,compType.lower()[:-1]] if rDict[compType][system][component]['Setup']: record += ['Setup'] else: record += ['NotSetup'] if rDict[compType][system][component]['Installed']: record += ['Installed'] else: record += ['NotInstalled'] record += [str( rDict[compType][system][component]['RunitStatus'] )] record += [str( rDict[compType][system][component]['Timeup'] )] record += [str( rDict[compType][system][component]['PID'] )] records.append(record) printTable(fields,records) elif option == 'database' or option == 'databases': client = SystemAdministratorClient( self.host, self.port ) if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = "******" InstallTools.getMySQLPasswords() result = client.getDatabases( InstallTools.mysqlRootPwd ) if not result['OK']: self.__errMsg( result['Message'] ) return resultSW = client.getAvailableDatabases() if not resultSW['OK']: self.__errMsg( resultSW['Message'] ) return sw = resultSW['Value'] installed = result['Value'] gLogger.notice( '' ) for db in sw: if db in installed: gLogger.notice( db.rjust( 25 ), ': Installed' ) else: gLogger.notice( db.rjust( 25 ), ': Not installed' ) if not sw: gLogger.notice( "No database found" ) elif option == 'mysql': client = SystemAdministratorClient( self.host, self.port ) result = client.getMySQLStatus() if not result['OK']: self.__errMsg( result['Message'] ) elif result['Value']: gLogger.notice( '' ) for par, value in result['Value'].items(): gLogger.notice( ( par.rjust( 28 ), ':', value ) ) else: gLogger.notice( "No MySQL database found" ) elif option == "log": self.getLog( argss ) elif option == "info": client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Setup:", result['Value']['Setup'] ) gLogger.notice( "DIRAC version:", result['Value']['DIRAC'] ) if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): gLogger.notice( "%s version" % e, v ) gLogger.notice( '' ) elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Host info:" ) gLogger.notice( '' ) fields = ['Parameter','Value'] records = [] for key, value in result['Value'].items(): records.append( [key, str( value ) ] ) printTable( fields, records ) elif option == "hosts": client = ComponentMonitoringClient() result = client.getHosts( {}, False, False ) if not result[ 'OK' ]: self.__errMsg( 'Error retrieving the list of hosts: %s' % ( result[ 'Message' ] ) ) else: hostList = result[ 'Value' ] gLogger.notice( '' ) gLogger.notice( ' ' + 'Host'.center( 32 ) + ' ' + 'CPU'.center( 34 ) + ' ' ) gLogger.notice( ( '-' * 69 ) ) for element in hostList: gLogger.notice( '|' + element[ 'HostName' ].center( 32 ) + '|' + element[ 'CPU' ].center( 34 ) + '|' ) gLogger.notice( ( '-' * 69 ) ) gLogger.notice( '' ) elif option == "errors": self.getErrors( argss ) elif option == "installations": self.getInstallations( argss ) elif option == "doc": if len( argss ) > 2: if argss[0] in [ 'service', 'agent' ]: compType = argss[0] compSystem = argss[1] compModule = argss[2] client = SystemAdministratorClient( self.host, self.port ) result = client.getComponentDocumentation( compType, compSystem, compModule ) if result[ 'OK' ]: gLogger.notice( result[ 'Value' ] ) else: self.__errMsg( result[ 'Message' ] ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( "Unknown option:", option )
def execute( self ): """ General agent execution method """ # Get a "fresh" copy of the CS data result = self.csAPI.downloadCSData() if not result['OK']: self.log.warn( "Could not download a fresh copy of the CS data", result[ 'Message' ] ) # Execute command to retrieve storage usage information cmdTuple = ['lcg-infosites', '--vo', self.voName , 'se'] self.log.info( "Executing %s" % cmdTuple ) ret = systemCall( 0, cmdTuple, env = {'LCG_GFAL_INFOSYS':self.bdii} ) if not ret['OK']: return ret elif not ret['Value'][1] != '': self.log.error( "Error while executing %s" % cmdTuple ) return S_ERROR() # initialize sedict sedict = {} for SE in self.productionSEs: sedict[SE] = [] fields = ['SE', 'Available(TB)', 'Used(TB)', 'Total(TB)', 'Used(%)' ] records = [] fullSEList = [] for se in ret['Value'][1].split( '\n' ): if len( se.split() ) == 4: spacedict = {} SE = se.split()[3] if SE in self.productionSEs and se.split()[0] != 'n.a' and se.split()[1] != 'n.a': # ## convert into TB available = float( se.split()[0] ) / 1e9 used = float( se.split()[1] ) / 1e9 spacedict['Available'] = available spacedict['Used'] = used spacedict['Total'] = available + used sedict[SE].append(spacedict) for SE in self.productionSEs: for spacedict in sedict[SE]: available = '%.1f' % spacedict['Available'] used = '%.1f' % spacedict['Used'] total = '%.1f' % spacedict['Total'] fraction_used = spacedict['Used'] / spacedict['Total'] * 100 if fraction_used > 90.: fullSEList.append(SE) self.log.warn( "%s full at %.1f%%" % (SE, fraction_used) ) fraction_used = '%.1f' % fraction_used records.append( [SE, available, used, total, fraction_used] ) body = printTable( fields, records, printOut = False ) if len(fullSEList) > 0: self.subject = 'CRITICAL storage usage beyond 90%%: %s' % ( ', '.join( fullSEList ) ) if self.addressTo and self.addressFrom: notification = NotificationClient() result = notification.sendMail( self.addressTo, self.subject, body, self.addressFrom, localAttempt = False ) if not result['OK']: self.log.error( 'Can not send notification mail', result['Message'] ) return S_OK()
result = getVOfromProxyGroup() if not result['OK']: gLogger.error('Failed to determine the user VO') DIRAC.exit(-1) vo = result['Value'] print(allVOsFlag, noVOFlag, vo) for se, statusDict in res['Value'].items(): # Check if the SE is allowed for the user VO if not allVOsFlag: voList = gConfig.getValue('/Resources/StorageElements/%s/VO' % se, []) if noVOFlag and voList: continue if voList and vo not in voList: continue record = [se] for status in fields[1:]: value = statusDict.get(status, 'Unknown') record.append(value) records.append(record) printTable(fields, records, numbering=False, sortField='SE') DIRAC.exit(0) ################################################################################ # EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
gLogger.error( res[ 'Message' ] ) DIRAC.exit( -1 ) gLogger.info( "%s %s %s" % ( 'Storage Element'.ljust( 25 ), 'Read Status'.rjust( 15 ), 'Write Status'.rjust( 15 ) ) ) seList = sortList( res[ 'Value' ] ) resourceStatus = ResourceStatus() res = resourceStatus.getStorageElementStatus( seList ) if not res[ 'OK' ]: gLogger.error( "Failed to get StorageElement status for %s" % str( seList ) ) DIRAC.exit( 1 ) fields = ['SE','ReadAccess','WriteAccess','RemoveAccess','CheckAccess'] records = [] for se, statusDict in res[ 'Value' ].items(): record = [se] for status in fields[1:]: value = statusDict.get( status, 'Unknown' ) record.append( value ) records.append( record ) printTable( fields, records, numbering=False ) DIRAC.exit( 0 ) ################################################################################ # EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
def main(): global vo global noVOFlag global allVOsFlag Script.registerSwitch("V:", "vo=", "Virtual Organization", setVO) Script.registerSwitch("a", "all", "All Virtual Organizations flag", setAllVO) Script.registerSwitch("n", "noVO", "No Virtual Organizations assigned flag", setNoVO) Script.parseCommandLine() from DIRAC import gConfig, gLogger from DIRAC.ResourceStatusSystem.Client.ResourceStatus import ResourceStatus from DIRAC.Core.Utilities.PrettyPrint import printTable from DIRAC.Core.Security.ProxyInfo import getVOfromProxyGroup storageCFGBase = "/Resources/StorageElements" res = gConfig.getSections(storageCFGBase, True) if not res['OK']: gLogger.error('Failed to get storage element info') gLogger.error(res['Message']) DIRACexit(1) gLogger.info("%s %s %s" % ('Storage Element'.ljust(25), 'Read Status'.rjust(15), 'Write Status'.rjust(15))) seList = sorted(res['Value']) resourceStatus = ResourceStatus() res = resourceStatus.getElementStatus(seList, "StorageElement") if not res['OK']: gLogger.error("Failed to get StorageElement status for %s" % str(seList)) DIRACexit(1) fields = ['SE', 'ReadAccess', 'WriteAccess', 'RemoveAccess', 'CheckAccess'] records = [] if vo is None and not allVOsFlag: result = getVOfromProxyGroup() if not result['OK']: gLogger.error('Failed to determine the user VO') DIRACexit(1) vo = result['Value'] for se, statusDict in res['Value'].items(): # Check if the SE is allowed for the user VO if not allVOsFlag: voList = gConfig.getValue('/Resources/StorageElements/%s/VO' % se, []) if noVOFlag and voList: continue if voList and vo not in voList: continue record = [se] for status in fields[1:]: value = statusDict.get(status, 'Unknown') record.append(value) records.append(record) printTable(fields, records, numbering=False, sortField='SE') DIRACexit(0)
fields = ('Site', 'CE', 'Queue', 'Status', 'Match', 'Reason') records = [] for queue, queueInfo in queueDict.iteritems(): site = queueInfo['Site'] ce = queueInfo['CEName'] siteStatus = "Active" if site in siteMaskList else "InActive" ceStatus = siteStatus if rssClient.rssFlag: result = rssClient.getElementStatus(ce, "ComputingElement") if result['OK']: ceStatus = result['Value'][ce]['all'] result = matchQueue(jdl, queueInfo, fullMatch=fullMatch) if not result['OK']: gLogger.error('Failed in getting match data', result['Message']) DIRACExit(-1) status = "Active" if siteStatus is "Active" and ceStatus is "Active" else "Inactive" if result['Value']['Match']: records.append((site, ce, queueInfo['Queue'], status, 'Yes', '')) else: records.append((site, ce, queueInfo['Queue'], status, 'No', result['Value']['Reason'])) gLogger.notice( printTable(fields, records, sortField='Site', columnSeparator=' ', printOut=False))
def main(): Script.parseCommandLine() from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient args = Script.getPositionalArgs() if len(args) < 1: Script.showHelp(exitCode=1) # get arguments prodID = args[0] prodClient = ProductionClient() transClient = TransformationClient() res = prodClient.getProductionTransformations(prodID) transIDs = [] if res['OK']: transList = res['Value'] if not transList: DIRAC.gLogger.notice( 'No transformation associated with production %s' % prodID) DIRAC.exit(-1) for trans in transList: transIDs.append(trans['TransformationID']) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) fields = [ 'TransformationName', 'Status', 'F_Proc.', 'F_Proc.(%)', 'TransformationID', 'ProductionID', 'Prod_LastUpdate', 'Prod_InsertedTime' ] records = [] paramShowNames = [ 'TransformationID', 'TransformationName', 'Type', 'Status', 'Files_Total', 'Files_PercentProcessed', 'Files_Processed', 'Files_Unused', 'Jobs_TotalCreated', 'Jobs_Waiting', 'Jobs_Running', 'Jobs_Done', 'Jobs_Failed', 'Jobs_Stalled' ] resList = [] res = transClient.getTransformationSummaryWeb( {'TransformationID': transIDs}, [], 0, len(transIDs)) if not res['OK']: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) if res['Value']['TotalRecords'] > 0: paramNames = res['Value']['ParameterNames'] for paramValues in res['Value']['Records']: paramShowValues = map( lambda pname: paramValues[paramNames.index(pname)], paramShowNames) showDict = dict(zip(paramShowNames, paramShowValues)) resList.append(showDict) for res in resList: files_Processed = res['Files_Processed'] files_PercentProcessed = res['Files_PercentProcessed'] status = res['Status'] type = res['Type'] transName = res['TransformationName'] transID = res['TransformationID'] records.append([ transName, status, str(files_Processed), str(files_PercentProcessed), str(transID), str(prodID), str(trans['LastUpdate']), str(trans['InsertedTime']) ]) printTable(fields, records) DIRAC.exit(0)
def do_show(self, args): """ Show list of components with various related information usage: show software - show components for which software is available show installed - show components installed in the host with runit system show setup - show components set up for automatic running in the host show project - show project to install or upgrade show status - show status of the installed components show database - show status of the databases show mysql - show status of the MySQL server show log <system> <service|agent> [nlines] - show last <nlines> lines in the component log file show info - show version of software and setup show host - show host related parameters show errors [*|<system> <service|agent>] - show error count for the given component or all the components in the last hour and day """ argss = args.split() if not argss: print self.do_show.__doc__ return option = argss[0] del argss[0] if option == 'software': client = SystemAdministratorClient(self.host, self.port) result = client.getSoftwareComponents() if not result['OK']: self.__errMsg(result['Message']) else: print pprint.pprint(result['Value']) elif option == 'installed': client = SystemAdministratorClient(self.host, self.port) result = client.getInstalledComponents() if not result['OK']: self.__errMsg(result['Message']) else: print pprint.pprint(result['Value']) elif option == 'setup': client = SystemAdministratorClient(self.host, self.port) result = client.getSetupComponents() if not result['OK']: self.__errMsg(result['Message']) else: print pprint.pprint(result['Value']) elif option == 'project': result = SystemAdministratorClient(self.host, self.port).getProject() if not result['OK']: self.__errMsg(result['Message']) else: print "Current project is %s" % result['Value'] elif option == 'status': client = SystemAdministratorClient(self.host, self.port) result = client.getOverallStatus() if not result['OK']: self.__errMsg(result['Message']) else: fields = [ "System", 'Name', 'Module', 'Type', 'Setup', 'Installed', 'Runit', 'Uptime', 'PID' ] records = [] rDict = result['Value'] for compType in rDict: for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: record = [] if rDict[compType][system][component]['Installed']: module = str(rDict[compType][system][component] ['Module']) record += [ system, component, module, compType.lower()[:-1] ] if rDict[compType][system][component]['Setup']: record += ['Setup'] else: record += ['NotSetup'] if rDict[compType][system][component][ 'Installed']: record += ['Installed'] else: record += ['NotInstalled'] record += [ str(rDict[compType][system][component] ['RunitStatus']) ] record += [ str(rDict[compType][system][component] ['Timeup']) ] record += [ str(rDict[compType][system][component] ['PID']) ] records.append(record) printTable(fields, records) elif option == 'database' or option == 'databases': client = SystemAdministratorClient(self.host, self.port) if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = "******" InstallTools.getMySQLPasswords() result = client.getDatabases(InstallTools.mysqlRootPwd) if not result['OK']: self.__errMsg(result['Message']) return resultSW = client.getAvailableDatabases() if not resultSW['OK']: self.__errMsg(resultSW['Message']) return sw = resultSW['Value'] installed = result['Value'] print for db in sw: if db in installed: print db.rjust(25), ': Installed' else: print db.rjust(25), ': Not installed' if not sw: print "No database found" elif option == 'mysql': client = SystemAdministratorClient(self.host, self.port) result = client.getMySQLStatus() if not result['OK']: self.__errMsg(result['Message']) elif result['Value']: print for par, value in result['Value'].items(): print par.rjust(28), ':', value else: print "No MySQL database found" elif option == "log": self.getLog(argss) elif option == "info": client = SystemAdministratorClient(self.host, self.port) result = client.getInfo() if not result['OK']: self.__errMsg(result['Message']) else: print print "Setup:", result['Value']['Setup'] print "DIRAC version:", result['Value']['DIRAC'] if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): print "%s version" % e, v print elif option == "host": client = SystemAdministratorClient(self.host, self.port) result = client.getHostInfo() if not result['OK']: self.__errMsg(result['Message']) else: print print "Host info:" print fields = ['Parameter', 'Value'] records = [] for key, value in result['Value'].items(): records.append([key, str(value)]) printTable(fields, records) elif option == "errors": self.getErrors(argss) else: print "Unknown option:", option
'Status', 'ProductionID', 'CreationDate', 'LastUpdate', 'AuthorDN', 'AuthorGroup'] records = [] if res['OK']: prodList = res['Value'] if not isinstance(res['Value'], list): prodList = [res['Value']] for prod in prodList: records.append( [ str( prod['ProductionName']), str( prod['Status']), str( prod['ProductionID']), str( prod['CreationDate']), str( prod['LastUpdate']), str( prod['AuthorDN']), str( prod['AuthorGroup'])]) else: DIRAC.gLogger.error(res['Message']) DIRAC.exit(-1) printTable(fields, records) DIRAC.exit(0)
def do_showall(self, args): """ Show status of all the components in all the hosts Usage: showall [-snmth] [-ASE] [-N name] [-H host] - show status of components Options: -d extra debug printout Sorting options: -s system -n component name -m component module -t component type -h component host Selection options: -A select agents -S select services -E select executors -N <component pattern> select component with the name containing the pattern -H <host name> select the given host -T <setup name> select the given setup """ argss = args.split() sortOption = '' componentType = '' componentName = '' hostName = '' setupName = '' debug = False while len(argss) > 0: option = argss[0] del argss[0] sortOption = '' if option == '-s': sortOption = "System" elif option == '-n': sortOption = "Name" elif option == '-m': sortOption = "Module" elif option == '-t': sortOption = "Type" elif option == '-h': sortOption = "Host" elif option == "-A": componentType = 'Agents' elif option == "-S": componentType = 'Services' elif option == "-E": componentType = 'Executors' elif option == "-d": debug = True elif option == "-N": componentName = argss[0] del argss[0] elif option == "-H": hostName = argss[0] del argss[0] elif option == "-T": setupName = argss[0] del argss[0] else: self.__errMsg('Invalid option %s' % option) return client = SystemAdministratorIntegrator() resultAll = client.getOverallStatus() resultInfo = client.getInfo() if not resultAll['OK']: self.__errMsg(resultAll['Message']) else: fields = [ "System", 'Name', 'Module', 'Type', 'Setup', 'Host', 'Runit', 'Uptime' ] records = [] for host in resultAll['Value']: if hostName and not hostName in host: continue result = resultAll['Value'][host] if not result['OK']: if debug: self.__errMsg("Host %s: %s" % (host, result['Message'])) continue rDict = result['Value'] for compType in rDict: if componentType and componentType != compType: continue for system in rDict[compType]: components = rDict[compType][system].keys() components.sort() for component in components: if componentName and not componentName in component: continue record = [] if rDict[compType][system][component]['Installed']: module = str(rDict[compType][system][component] ['Module']) record += [ system, component, module, compType.lower()[:-1] ] if resultInfo['OK'] and host in resultInfo[ 'Value'] and resultInfo['Value'][host][ 'OK']: setup = resultInfo['Value'][host]['Value'][ 'Setup'] else: setup = 'Unknown' if setupName and not setupName in setup: continue record += [setup] record += [host] record += [ str(rDict[compType][system][component] ['RunitStatus']) ] record += [ str(rDict[compType][system][component] ['Timeup']) ] records.append(record) printTable(fields, records, sortOption)
def main(): import os import DIRAC from DIRAC import gConfig from DIRAC.Core.Security.ProxyInfo import getProxyInfo from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getVOForGroup from DIRAC.Core.Utilities.PrettyPrint import printTable def version(arg): Script.disableCS() print(DIRAC.version) DIRAC.exit(0) def platform(arg): Script.disableCS() print(DIRAC.getPlatform()) DIRAC.exit(0) Script.registerSwitch("v", "version", "print version of current DIRAC installation", version) Script.registerSwitch("p", "platform", "print platform of current DIRAC installation", platform) Script.parseCommandLine(ignoreErrors=True) records = [] records.append(("Setup", gConfig.getValue("/DIRAC/Setup", "Unknown"))) records.append(( "AuthorizationServer", gConfig.getValue( "/DIRAC/Security/Authorization/issuer", "/DIRAC/Security/Authorization/issuer option is absent"), )) records.append(("ConfigurationServer", gConfig.getValue("/DIRAC/Configuration/Servers", "None found"))) records.append(("Installation path", DIRAC.rootPath)) if os.path.exists( os.path.join(DIRAC.rootPath, DIRAC.getPlatform(), "bin", "mysql")): records.append(("Installation type", "server")) else: records.append(("Installation type", "client")) records.append(("Platform", DIRAC.getPlatform())) ret = getProxyInfo(disableVOMS=True) if ret["OK"]: if "group" in ret["Value"]: vo = getVOForGroup(ret["Value"]["group"]) else: vo = getVOForGroup("") if not vo: vo = "None" records.append(("VirtualOrganization", vo)) if "identity" in ret["Value"]: records.append(("User DN", ret["Value"]["identity"])) if "secondsLeft" in ret["Value"]: records.append(("Proxy validity, secs", { "Value": str(ret["Value"]["secondsLeft"]), "Just": "L" })) if gConfig.getValue("/DIRAC/Security/UseServerCertificate", True): records.append(("Use Server Certificate", "Yes")) else: records.append(("Use Server Certificate", "No")) if gConfig.getValue("/DIRAC/Security/UseTokens", "false").lower() in ("y", "yes", "true"): records.append(("Use tokens", "Yes")) else: records.append(("Use tokens", "No")) if gConfig.getValue("/DIRAC/Security/SkipCAChecks", False): records.append(("Skip CA Checks", "Yes")) else: records.append(("Skip CA Checks", "No")) records.append(("DIRAC version", DIRAC.version)) fields = ["Option", "Value"] print() printTable(fields, records, numbering=False) print()