def main(): # Registering arguments will automatically add their description to the help menu Script.registerArgument( "DIRACSiteName: Name of the site for DIRAC in the form GRID.LOCATION.COUNTRY " "(ie: LCG.CERN.ch)") Script.registerArgument( "GridSiteName: Name of the site in the Grid (ie: CERN-PROD)") Script.registerArgument([ "CE: Name of the CE to be included in the site (ie: ce111.cern.ch)" ]) Script.parseCommandLine(ignoreErrors=True) diracSiteName, gridSiteName, ces = Script.getPositionalArgs(group=True) try: diracGridType, place, country = diracSiteName.split(".") except ValueError: gLogger.error( "The DIRACSiteName should be of the form GRID.LOCATION.COUNTRY for example LCG.CERN.ch" ) DIRACExit(-1) result = getDIRACSiteName(gridSiteName) newSite = True if result["OK"] and result["Value"]: if len(result["Value"]) > 1: gLogger.notice( "%s GOC site name is associated with several DIRAC sites:" % gridSiteName) for i, dSite in enumerate(result["Value"]): gLogger.notice("%d: %s" % (i, dSite)) inp = six.moves.input("Enter your choice number: ") try: inp = int(inp) except ValueError: gLogger.error("You should enter an integer number") DIRACExit(-1) if 0 <= inp < len(result["Value"]): diracCSSite = result["Value"][inp] else: gLogger.error("Number out of range: %d" % inp) DIRACExit(-1) else: diracCSSite = result["Value"][0] if diracCSSite == diracSiteName: gLogger.notice("Site with GOC name %s is already defined as %s" % (gridSiteName, diracSiteName)) newSite = False else: gLogger.error( "ERROR: Site with GOC name %s is already defined as %s" % (gridSiteName, diracCSSite)) DIRACExit(-1) else: gLogger.error("ERROR getting DIRAC site name of %s" % gridSiteName, result.get("Message")) csAPI = CSAPI() if newSite: gLogger.notice("Site to CS: %s" % diracSiteName) res = csAPI.addSite(diracSiteName, {"Name": gridSiteName}) if not res["OK"]: gLogger.error("Failed adding site to CS", res["Message"]) DIRACExit(1) res = csAPI.commit() if not res["OK"]: gLogger.error("Failure committing to CS", res["Message"]) DIRACExit(3) for ce in ces: gLogger.notice("Adding CE %s" % ce) res = csAPI.addCEtoSite(diracSiteName, ce) if not res["OK"]: gLogger.error("Failed adding CE %s to CS" % ce, res["Message"]) DIRACExit(2) res = csAPI.commit() if not res["OK"]: gLogger.error("Failure committing to CS", res["Message"]) DIRACExit(3)
def main(): Script.parseCommandLine(ignoreErrors=True) args = Script.getPositionalArgs() if len(args) < 3: Script.showHelp(exitCode=1) diracSiteName = args[0] gridSiteName = args[1] ces = args[2:] try: diracGridType, place, country = diracSiteName.split('.') except ValueError: gLogger.error( "The DIRACSiteName should be of the form GRID.LOCATION.COUNTRY for example LCG.CERN.ch" ) DIRACExit(-1) result = getDIRACSiteName(gridSiteName) newSite = True if result['OK'] and result['Value']: if len(result['Value']) > 1: gLogger.notice( '%s GOC site name is associated with several DIRAC sites:' % gridSiteName) for i, dSite in enumerate(result['Value']): gLogger.notice('%d: %s' % (i, dSite)) inp = six.moves.input('Enter your choice number: ') try: inp = int(inp) except ValueError: gLogger.error('You should enter an integer number') DIRACExit(-1) if 0 <= inp < len(result['Value']): diracCSSite = result['Value'][inp] else: gLogger.error('Number out of range: %d' % inp) DIRACExit(-1) else: diracCSSite = result['Value'][0] if diracCSSite == diracSiteName: gLogger.notice('Site with GOC name %s is already defined as %s' % (gridSiteName, diracSiteName)) newSite = False else: gLogger.error( 'ERROR: Site with GOC name %s is already defined as %s' % (gridSiteName, diracCSSite)) DIRACExit(-1) else: gLogger.error("ERROR getting DIRAC site name of %s" % gridSiteName, result.get('Message')) csAPI = CSAPI() if newSite: gLogger.notice("Site to CS: %s" % diracSiteName) res = csAPI.addSite(diracSiteName, {"Name": gridSiteName}) if not res['OK']: gLogger.error("Failed adding site to CS", res['Message']) DIRACExit(1) res = csAPI.commit() if not res['OK']: gLogger.error("Failure committing to CS", res['Message']) DIRACExit(3) for ce in ces: gLogger.notice("Adding CE %s" % ce) res = csAPI.addCEtoSite(diracSiteName, ce) if not res['OK']: gLogger.error("Failed adding CE %s to CS" % ce, res['Message']) DIRACExit(2) res = csAPI.commit() if not res['OK']: gLogger.error("Failure committing to CS", res['Message']) DIRACExit(3)
if not res['OK']: gLogger.error( "Failed to get proxy information", res['Message'] ) DIRACExit( 2 ) userName = res['Value']['username'] group = res['Value']['group'] if not 'CSAdministrator' in getPropertiesForGroup( group ): gLogger.error( "You must be CSAdministrator user to execute this script" ) gLogger.notice( "Please issue 'dirac-proxy-init -g [group with CSAdministrator Property]'" ) DIRACExit( 2 ) siteDict = {} siteDict['Name'] = gridSiteName siteDict['Domains'] = diracGridType siteName = '.'.join( [place, country] ) result = csAPI.addSite( siteName, siteDict ) if not result['OK']: gLogger.error( "Error: %s" % result['Message'] ) DIRACExit( -1 ) for ce in ces: result = csAPI.addResource( siteName, 'Computing', ce, { 'CEType': "LCG" } ) if not result['OK']: gLogger.error( "Error: %s" % result['Message'] ) DIRACExit( -1 ) res = csAPI.commitChanges() if not res['OK']: gLogger.error( "Failed to commit changes to CS", res['Message'] ) DIRACExit( -1 ) else:
else: diracCSSite = result['Value'][0] if diracCSSite == diracSiteName: gLogger.notice('Site with GOC name %s is already defined as %s' % (gridSiteName, diracSiteName)) newSite = False else: gLogger.error('ERROR: Site with GOC name %s is already defined as %s' % (gridSiteName, diracCSSite)) DIRACExit(-1) else: gLogger.error("ERROR getting DIRAC site name of %s" % gridSiteName, result.get('Message')) csAPI = CSAPI() if newSite: gLogger.notice("Site to CS: %s" % diracSiteName) res = csAPI.addSite(diracSiteName, {"Name": gridSiteName}) if not res['OK']: gLogger.error("Failed adding site to CS", res['Message']) DIRACExit(1) res = csAPI.commit() if not res['OK']: gLogger.error("Failure committing to CS", res['Message']) DIRACExit(3) for ce in ces: gLogger.notice("Adding CE %s" % ce) res = csAPI.addCEtoSite(diracSiteName, ce) if not res['OK']: gLogger.error("Failed adding CE %s to CS" % ce, res['Message']) DIRACExit(2) res = csAPI.commit()
DIRAC.exit(2) userName = res['Value']['username'] group = res['Value']['group'] if not 'CSAdministrator' in getPropertiesForGroup(group): gLogger.error("You must be CSAdministrator user to execute this script") gLogger.notice( "Please issue 'dirac-proxy-init -g [group with CSAdministrator Property]'" ) DIRAC.exit(2) siteDict = {} siteDict['Name'] = gridSiteName siteDict['Domains'] = diracGridType siteName = '.'.join([place, country]) result = csAPI.addSite(siteName, siteDict) if not result['OK']: gLogger.error("Error: %s" % result['Message']) DIRAC.exit(-1) for ce in ces: result = csAPI.addResource(siteName, 'Computing', ce, {'CEType': "LCG"}) if not result['OK']: gLogger.error("Error: %s" % result['Message']) DIRAC.exit(-1) res = csAPI.commitChanges() if not res['OK']: gLogger.error("Failed to commit changes to CS", res['Message']) DIRAC.exit(-1) else: