def do_add( self, args ): """ Add new entity to the Configuration Service usage: add system <system> <instance> """ argss = args.split() option = argss[0] del argss[0] if option == "instance" or option == "system": system = argss[0] instance = argss[1] client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] instanceName = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( hostSetup, system ), '' ) if instanceName: if instanceName == instance: print "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) else: self.__errMsg( "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) ) return result = InstallTools.addSystemInstance( system, instance, hostSetup ) if not result['OK']: self.__errMsg( result['Message'] ) else: print "%s system instance %s added successfully" % ( system, instance ) else: print "Unknown option:", option
def do_add( self, args ): """ Add new entity to the Configuration Service usage: add system <system> <instance> """ argss = args.split() option = argss[0] del argss[0] if option == "instance" or option == "system": system = argss[0] instance = argss[1] client = SystemAdministratorClient( self.host, self.port ) result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] instanceName = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( hostSetup, system ), '' ) if instanceName: if instanceName == instance: print "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) else: self.__errMsg( "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) ) return result = InstallTools.addSystemInstance( system, instance, hostSetup ) if not result['OK']: self.__errMsg( result['Message'] ) else: print "%s system instance %s added successfully" % ( system, instance ) else: print "Unknown option:", option
def do_install(self, args): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... """ argss = args.split() if not argss: print self.do_install.__doc__ return option = argss[0] del argss[0] if option == "mysql": print "Installing MySQL database, this can take a while ..." client = SystemAdministratorClient(self.host, self.port) if InstallTools.mysqlPassword == 'LocalConfig': InstallTools.mysqlPassword = '' InstallTools.getMySQLPasswords() result = client.installMySQL(InstallTools.mysqlRootPwd, InstallTools.mysqlPassword) if not result['OK']: self.__errMsg(result['Message']) else: print "MySQL:", result['Value'] print "You might need to restart SystemAdministrator service to take new settings into account" elif option == "db": if not argss: print self.do_install.__doc__ return database = argss[0] client = SystemAdministratorClient(self.host, self.port) result = client.getAvailableDatabases() if not result['OK']: self.__errMsg("Can not get database list: %s" % result['Message']) return if not result['Value'].has_key(database): self.__errMsg("Unknown database %s: " % database) return system = result['Value'][database]['System'] setup = gConfig.getValue('/DIRAC/Setup', '') if not setup: self.__errMsg("Unknown current setup") return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % (setup, system), '') if not instance: self.__errMsg("No instance defined for system %s" % system) self.__errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system) return if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = '******' InstallTools.getMySQLPasswords() result = client.installDatabase(database, InstallTools.mysqlRootPwd) if not result['OK']: self.__errMsg(result['Message']) return extension, system = result['Value'] # result = client.addDatabaseOptionsToCS( system, database ) InstallTools.mysqlHost = self.host result = client.getInfo() if not result['OK']: self.__errMsg(result['Message']) hostSetup = result['Value']['Setup'] result = InstallTools.addDatabaseOptionsToCS( gConfig, system, database, hostSetup) if not result['OK']: self.__errMsg(result['Message']) return print "Database %s from %s/%s installed successfully" % ( database, extension, system) elif option in ["service", "agent", "executor"]: if len(argss) < 2: print self.do_install.__doc__ return system = argss[0] del argss[0] component = argss[0] del argss[0] specialOptions = {} module = '' for i in range(len(argss)): if argss[i] == "-m": specialOptions['Module'] = argss[i + 1] module = argss[i + 1] if argss[i] == "-p": opt, value = argss[i + 1].split('=') specialOptions[opt] = value if module == component: module = '' client = SystemAdministratorClient(self.host, self.port) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) InstallTools.host = self.host result = client.getInfo() if not result['OK']: self.__errMsg(result['Message']) return hostSetup = result['Value']['Setup'] # Install Module section if not yet there if module: result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, module, getCSExtensions(), hostSetup) # Add component section with specific parameters only result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions, addDefaultOptions=False) else: # Install component section result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions) if not result['OK']: self.__errMsg(result['Message']) return # Then we can install and start the component result = client.setupComponent(option, system, component, module) if not result['OK']: self.__errMsg(result['Message']) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] print "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit) else: print "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
def do_install( self, args ): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... """ argss = args.split() if not argss: print self.do_install.__doc__ return option = argss[0] del argss[0] if option == "mysql": print "Installing MySQL database, this can take a while ..." client = SystemAdministratorClient( self.host, self.port ) if InstallTools.mysqlPassword == 'LocalConfig': InstallTools.mysqlPassword = '' InstallTools.getMySQLPasswords() result = client.installMySQL( InstallTools.mysqlRootPwd, InstallTools.mysqlPassword ) if not result['OK']: self.__errMsg( result['Message'] ) else: print "MySQL:", result['Value'] print "You might need to restart SystemAdministrator service to take new settings into account" elif option == "db": if not argss: print self.do_install.__doc__ return database = argss[0] client = SystemAdministratorClient( self.host, self.port ) result = client.getAvailableDatabases() if not result['OK']: self.__errMsg( "Can not get database list: %s" % result['Message'] ) return if not result['Value'].has_key( database ): self.__errMsg( "Unknown database %s: " % database ) return system = result['Value'][database]['System'] setup = gConfig.getValue( '/DIRAC/Setup', '' ) if not setup: self.__errMsg( "Unknown current setup" ) return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' ) if not instance: self.__errMsg( "No instance defined for system %s" % system ) self.__errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system ) return if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = '******' InstallTools.getMySQLPasswords() result = client.installDatabase( database, InstallTools.mysqlRootPwd ) if not result['OK']: self.__errMsg( result['Message'] ) return extension, system = result['Value'] # result = client.addDatabaseOptionsToCS( system, database ) InstallTools.mysqlHost = self.host result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] result = InstallTools.addDatabaseOptionsToCS( gConfig, system, database, hostSetup ) if not result['OK']: self.__errMsg( result['Message'] ) return print "Database %s from %s/%s installed successfully" % ( database, extension, system ) elif option in ["service","agent","executor"] : if len( argss ) < 2: print self.do_install.__doc__ return system = argss[0] del argss[0] component = argss[0] del argss[0] specialOptions = {} module = '' for i in range(len(argss)): if argss[i] == "-m": specialOptions['Module'] = argss[i+1] module = argss[i+1] if argss[i] == "-p": opt,value = argss[i+1].split('=') specialOptions[opt] = value if module == component: module = '' client = SystemAdministratorClient( self.host, self.port ) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) InstallTools.host = self.host result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) return hostSetup = result['Value']['Setup'] # Install Module section if not yet there if module: result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, module, getCSExtensions(), hostSetup ) # Add component section with specific parameters only result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions, addDefaultOptions = False ) else: # Install component section result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions ) if not result['OK']: self.__errMsg( result['Message'] ) return # Then we can install and start the component result = client.setupComponent( option, system, component, module ) if not result['OK']: self.__errMsg( result['Message'] ) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] print "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) else: print "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
def do_install(self, args): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> install agent <system> <agent> """ argss = args.split() if not argss: print self.do_install.__doc__ return option = argss[0] del argss[0] if option == "mysql": print "Installing MySQL database, this can take a while ..." client = SystemAdministratorClient(self.host, self.port) if InstallTools.mysqlPassword == 'LocalConfig': InstallTools.mysqlPassword = '' InstallTools.getMySQLPasswords() result = client.installMySQL(InstallTools.mysqlRootPwd, InstallTools.mysqlPassword) if not result['OK']: self.__errMsg(result['Message']) else: print "MySQL:", result['Value'] print "You might need to restart SystemAdministrator service to take new settings into account" elif option == "db": if not argss: print self.do_install.__doc__ return database = argss[0] client = SystemAdministratorClient(self.host, self.port) result = client.getAvailableDatabases() if not result['OK']: self.__errMsg("Can not get database list: %s" % result['Message']) return if not result['Value'].has_key(database): self.__errMsg("Unknown database %s: " % database) return system = result['Value'][database]['System'] setup = gConfig.getValue('/DIRAC/Setup', '') if not setup: self.__errMsg("Unknown current setup") return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % (setup, system), '') if not instance: self.__errMsg("No instance defined for system %s" % system) self.__errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system) return if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = '******' InstallTools.getMySQLPasswords() result = client.installDatabase(database, InstallTools.mysqlRootPwd) if not result['OK']: self.__errMsg(result['Message']) return extension, system = result['Value'] # result = client.addDatabaseOptionsToCS( system, database ) InstallTools.mysqlHost = self.host result = client.getInfo() if not result['OK']: self.__errMsg(result['Message']) hostSetup = result['Value']['Setup'] result = InstallTools.addDatabaseOptionsToCS( gConfig, system, database, hostSetup) if not result['OK']: self.__errMsg(result['Message']) return print "Database %s from %s/%s installed successfully" % ( database, extension, system) elif option == "service" or option == "agent": if len(argss) < 2: print self.do_install.__doc__ return system = argss[0] component = argss[1] client = SystemAdministratorClient(self.host, self.port) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) InstallTools.host = self.host result = client.getInfo() if not result['OK']: self.__errMsg(result['Message']) return hostSetup = result['Value']['Setup'] result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup) if not result['OK']: self.__errMsg(result['Message']) return # Then we can install and start the component result = client.setupComponent(option, system, component) if not result['OK']: self.__errMsg(result['Message']) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] print "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit) else: print "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 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 do_install( self, args ): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> install agent <system> <agent> """ argss = args.split() if not argss: print self.do_install.__doc__ return option = argss[0] del argss[0] if option == "mysql": print "Installing MySQL database, this can take a while ..." client = SystemAdministratorClient( self.host, self.port ) if InstallTools.mysqlPassword == 'LocalConfig': InstallTools.mysqlPassword = '' InstallTools.getMySQLPasswords() result = client.installMySQL( InstallTools.mysqlRootPwd, InstallTools.mysqlPassword ) if not result['OK']: self.__errMsg( result['Message'] ) else: print "MySQL:", result['Value'] print "You might need to restart SystemAdministrator service to take new settings into account" elif option == "db": if not argss: print self.do_install.__doc__ return database = argss[0] client = SystemAdministratorClient( self.host, self.port ) result = client.getAvailableDatabases() if not result['OK']: self.__errMsg( "Can not get database list: %s" % result['Message'] ) return if not result['Value'].has_key( database ): self.__errMsg( "Unknown database %s: " % database ) return system = result['Value'][database]['System'] setup = gConfig.getValue( '/DIRAC/Setup', '' ) if not setup: self.__errMsg( "Unknown current setup" ) return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' ) if not instance: self.__errMsg( "No instance defined for system %s" % system ) self.__errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system ) return if not InstallTools.mysqlPassword: InstallTools.mysqlPassword = '******' InstallTools.getMySQLPasswords() result = client.installDatabase( database, InstallTools.mysqlRootPwd ) if not result['OK']: self.__errMsg( result['Message'] ) return extension, system = result['Value'] # result = client.addDatabaseOptionsToCS( system, database ) InstallTools.mysqlHost = self.host result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] result = InstallTools.addDatabaseOptionsToCS( gConfig, system, database, hostSetup ) if not result['OK']: self.__errMsg( result['Message'] ) return print "Database %s from %s/%s installed successfully" % ( database, extension, system ) elif option == "service" or option == "agent": if len( argss ) < 2: print self.do_install.__doc__ return system = argss[0] component = argss[1] client = SystemAdministratorClient( self.host, self.port ) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) InstallTools.host = self.host result = client.getInfo() if not result['OK']: self.__errMsg( result['Message'] ) return hostSetup = result['Value']['Setup'] result = InstallTools.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup ) if not result['OK']: self.__errMsg( result['Message'] ) return # Then we can install and start the component result = client.setupComponent( option, system, component ) if not result['OK']: self.__errMsg( result['Message'] ) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] print "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) else: print "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 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 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']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: print "ERROR:", result['Message'] else: rDict = result['Value'] print print " System", ' '*20, 'Name', ' '*15, 'Type', ' '*13, 'Setup Installed Runit Uptime PID' print '-' * 116 for compType in rDict: for system in rDict[compType]: for component in rDict[compType][system]: if rDict[compType][system][component]['Installed']: print system.ljust( 28 ), component.ljust( 28 ), compType.lower()[:-1].ljust( 7 ), if rDict[compType][system][component]['Setup']: print 'SetUp'.rjust( 12 ), else: print 'NotSetup'.rjust( 12 ), if rDict[compType][system][component]['Installed']: print 'Installed'.rjust( 12 ), else: print 'NotInstalled'.rjust( 12 ), print str( rDict[compType][system][component]['RunitStatus'] ).ljust( 7 ), print str( rDict[compType][system][component]['Timeup'] ).rjust( 7 ), print str( rDict[compType][system][component]['PID'] ).rjust( 8 ), print 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']: print "ERROR:", result['Message'] return resultSW = client.getAvailableDatabases() if not resultSW['OK']: print "ERROR:", 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']: print "ERROR:", 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']: print "ERROR:", 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 == "errors": self.getErrors( argss ) else: print "Unknown option:", option
def do_install( self, args ): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... """ argss = args.split() if not argss: gLogger.notice( self.do_install.__doc__ ) return option = argss[0] del argss[0] if option == "mysql": gLogger.notice( "Installing MySQL database, this can take a while ..." ) client = SystemAdministratorClient( self.host, self.port ) if gComponentInstaller.mysqlPassword == 'LocalConfig': gComponentInstaller.mysqlPassword = '' gComponentInstaller.getMySQLPasswords() result = client.installMySQL( gComponentInstaller.mysqlRootPwd, gComponentInstaller.mysqlPassword ) if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( "MySQL:", result['Value'] ) gLogger.notice( "You might need to restart SystemAdministrator service to take new settings into account" ) elif option == "db": if not argss: gLogger.notice( self.do_install.__doc__ ) return database = argss[0] client = SystemAdministratorClient( self.host, self.port ) result = client.getAvailableDatabases() if not result['OK']: self._errMsg( "Can not get database list: %s" % result['Message'] ) return if not result['Value'].has_key( database ): self._errMsg( "Unknown database %s: " % database ) return system = result['Value'][database]['System'] setup = gConfig.getValue( '/DIRAC/Setup', '' ) if not setup: self._errMsg( "Unknown current setup" ) return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' ) if not instance: self._errMsg( "No instance defined for system %s" % system ) self._errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system ) return if not gComponentInstaller.mysqlPassword: gComponentInstaller.mysqlPassword = '******' gComponentInstaller.getMySQLPasswords() result = client.installDatabase( database, gComponentInstaller.mysqlRootPwd ) if not result['OK']: self._errMsg( result['Message'] ) return extension, system = result['Value'] result = client.getHostInfo() if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return else: cpu = result[ 'Value' ][ 'CPUModel' ] hostname = self.host if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return if database != 'InstalledComponentsDB': result = MonitoringUtilities.monitorInstallation( 'DB', system.replace( 'System', '' ), database, cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( result['Message'] ) return # result = client.addDatabaseOptionsToCS( system, database ) gComponentInstaller.mysqlHost = self.host result = client.getInfo() if not result['OK']: self._errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] result = gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, database, hostSetup, overwrite = True ) if not result['OK']: self._errMsg( result['Message'] ) return gLogger.notice( "Database %s from %s/%s installed successfully" % ( database, extension, system ) ) elif option in self.runitComponents: if len( argss ) < 2: gLogger.notice( self.do_install.__doc__ ) return system = argss[0] del argss[0] component = argss[0] del argss[0] specialOptions = {} module = '' for i in range(len(argss)): if argss[i] == "-m": specialOptions['Module'] = argss[i+1] module = argss[i+1] if argss[i] == "-p": opt,value = argss[i+1].split('=') specialOptions[opt] = value if module == component: module = '' client = SystemAdministratorClient( self.host, self.port ) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) gComponentInstaller.host = self.host result = client.getInfo() if not result['OK']: self._errMsg( result['Message'] ) return hostSetup = result['Value']['Setup'] # Install Module section if not yet there if module: result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, module, getCSExtensions(), hostSetup ) # in case of Error we must stop, this can happen when the module name is wrong... if not result['OK']: self._errMsg( result['Message'] ) return # Add component section with specific parameters only result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions, addDefaultOptions = True ) else: # Install component section result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions ) if not result['OK']: self._errMsg( result['Message'] ) return # Then we can install and start the component result = client.setupComponent( option, system, component, module ) if not result['OK']: self._errMsg( result['Message'] ) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] gLogger.notice( "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) ) # And register it in the database result = client.getHostInfo() if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return else: cpu = result[ 'Value' ][ 'CPUModel' ] hostname = self.host if component == 'ComponentMonitoring': # Make sure that the service is running before trying to use it nTries = 0 maxTries = 5 mClient = ComponentMonitoringClient() result = mClient.ping() while not result[ 'OK' ] and nTries < maxTries: time.sleep( 3 ) result = mClient.ping() nTries = nTries + 1 if not result[ 'OK' ]: self._errMsg( 'ComponentMonitoring service taking too long to start. Installation will not be logged into the database' ) return result = MonitoringUtilities.monitorInstallation( 'DB', system, 'InstalledComponentsDB', cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] ) return result = MonitoringUtilities.monitorInstallation( option, system, component, module, cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] ) return 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 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_install( self, args ): """ Install various DIRAC components usage: install mysql install db <database> install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ... """ argss = args.split() if not argss: gLogger.notice( self.do_install.__doc__ ) return option = argss[0] del argss[0] if option == "mysql": gLogger.notice( "Installing MySQL database, this can take a while ..." ) client = SystemAdministratorClient( self.host, self.port ) if gComponentInstaller.mysqlPassword == 'LocalConfig': gComponentInstaller.mysqlPassword = '' gComponentInstaller.getMySQLPasswords() result = client.installMySQL( gComponentInstaller.mysqlRootPwd, gComponentInstaller.mysqlPassword ) if not result['OK']: self._errMsg( result['Message'] ) else: gLogger.notice( "MySQL:", result['Value'] ) gLogger.notice( "You might need to restart SystemAdministrator service to take new settings into account" ) elif option == "db": if not argss: gLogger.notice( self.do_install.__doc__ ) return database = argss[0] client = SystemAdministratorClient( self.host, self.port ) result = client.getAvailableDatabases() if not result['OK']: self._errMsg( "Can not get database list: %s" % result['Message'] ) return if not result['Value'].has_key( database ): self._errMsg( "Unknown database %s: " % database ) return system = result['Value'][database]['System'] setup = gConfig.getValue( '/DIRAC/Setup', '' ) if not setup: self._errMsg( "Unknown current setup" ) return instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' ) if not instance: self._errMsg( "No instance defined for system %s" % system ) self._errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system ) return if not gComponentInstaller.mysqlPassword: gComponentInstaller.mysqlPassword = '******' gComponentInstaller.getMySQLPasswords() result = client.installDatabase( database, gComponentInstaller.mysqlRootPwd ) if not result['OK']: self._errMsg( result['Message'] ) return extension, system = result['Value'] result = client.getHostInfo() if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return else: cpu = result[ 'Value' ][ 'CPUModel' ] hostname = self.host if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return if database != 'InstalledComponentsDB': result = MonitoringUtilities.monitorInstallation( 'DB', system.replace( 'System', '' ), database, cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( result['Message'] ) return # result = client.addDatabaseOptionsToCS( system, database ) gComponentInstaller.mysqlHost = self.host result = client.getInfo() if not result['OK']: self._errMsg( result['Message'] ) hostSetup = result['Value']['Setup'] result = gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, database, hostSetup, overwrite = True ) if not result['OK']: self._errMsg( result['Message'] ) return gLogger.notice( "Database %s from %s/%s installed successfully" % ( database, extension, system ) ) elif option in self.runitComponents: if len( argss ) < 2: gLogger.notice( self.do_install.__doc__ ) return system = argss[0] del argss[0] component = argss[0] del argss[0] specialOptions = {} module = '' for i in range(len(argss)): if argss[i] == "-m": specialOptions['Module'] = argss[i+1] module = argss[i+1] if argss[i] == "-p": opt,value = argss[i+1].split('=') specialOptions[opt] = value if module == component: module = '' client = SystemAdministratorClient( self.host, self.port ) # First need to update the CS # result = client.addDefaultOptionsToCS( option, system, component ) gComponentInstaller.host = self.host result = client.getInfo() if not result['OK']: self._errMsg( result['Message'] ) return hostSetup = result['Value']['Setup'] # Install Module section if not yet there if module: result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, module, getCSExtensions(), hostSetup ) # in case of Error we must stop, this can happen when the module name is wrong... if not result['OK']: self._errMsg( result['Message'] ) return # Add component section with specific parameters only result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions, addDefaultOptions = True ) else: # Install component section result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component, getCSExtensions(), hostSetup, specialOptions ) if not result['OK']: self._errMsg( result['Message'] ) return # Then we can install and start the component result = client.setupComponent( option, system, component, module ) if not result['OK']: self._errMsg( result['Message'] ) return compType = result['Value']['ComponentType'] runit = result['Value']['RunitStatus'] gLogger.notice( "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) ) # And register it in the database result = client.getHostInfo() if not result[ 'OK' ]: self._errMsg( result[ 'Message' ] ) return else: cpu = result[ 'Value' ][ 'CPUModel' ] hostname = self.host if component == 'ComponentMonitoring': # Make sure that the service is running before trying to use it nTries = 0 maxTries = 5 mClient = ComponentMonitoringClient() result = mClient.ping() while not result[ 'OK' ] and nTries < maxTries: time.sleep( 3 ) result = mClient.ping() nTries = nTries + 1 if not result[ 'OK' ]: self._errMsg( 'ComponentMonitoring service taking too long to start. Installation will not be logged into the database' ) return result = MonitoringUtilities.monitorInstallation( 'DB', system, 'InstalledComponentsDB', cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] ) return result = MonitoringUtilities.monitorInstallation( option, system, component, module, cpu = cpu, hostname = hostname ) if not result['OK']: self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] ) return 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 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_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 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 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']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'installed': client = SystemAdministratorClient(self.host, self.port) result = client.getInstalledComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'setup': client = SystemAdministratorClient(self.host, self.port) result = client.getSetupComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'status': client = SystemAdministratorClient(self.host, self.port) result = client.getOverallStatus() if not result['OK']: print "ERROR:", result['Message'] else: rDict = result['Value'] print print " System", ' ' * 20, 'Name', ' ' * 15, 'Type', ' ' * 13, 'Setup Installed Runit Uptime PID' print '-' * 116 for compType in rDict: for system in rDict[compType]: for component in rDict[compType][system]: if rDict[compType][system][component]['Installed']: print system.ljust(28), component.ljust( 28), compType.lower()[:-1].ljust(7), if rDict[compType][system][component]['Setup']: print 'SetUp'.rjust(12), else: print 'NotSetup'.rjust(12), if rDict[compType][system][component][ 'Installed']: print 'Installed'.rjust(12), else: print 'NotInstalled'.rjust(12), print str(rDict[compType][system][component] ['RunitStatus']).ljust(7), print str(rDict[compType][system][component] ['Timeup']).rjust(7), print str(rDict[compType][system][component] ['PID']).rjust(8), print 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']: print "ERROR:", result['Message'] return resultSW = client.getAvailableDatabases() if not resultSW['OK']: print "ERROR:", 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']: print "ERROR:", 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']: print "ERROR:", 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 == "errors": self.getErrors(argss) else: print "Unknown option:", option