Beispiel #1
0
def parseSwitches():
    '''
    Parses the arguments passed by the user
  '''

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if args:
        subLogger.error(
            "Found the following positional args '%s', but we only accept switches"
            % args)
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    switches = dict(Script.getUnprocessedSwitches())

    # Default values
    switches.setdefault('element', None)
    switches.setdefault('defaultStatus', 'Banned')
    if not switches['element'] in ('all', 'Site', 'Resource', 'Node', None):
        subLogger.error("Found %s as element switch" % switches['element'])
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    subLogger.debug("The switches used are:")
    map(subLogger.debug, switches.iteritems())

    return switches
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["User:     User name"])
    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    choice = input("Are you sure you want to delete user/s %s? yes/no [no]: " %
                   ", ".join(args))
    choice = choice.lower()
    if choice not in ("yes", "y"):
        print("Delete aborted")
        DIRACExit(0)

    for user in args:
        if not diracAdmin.csDeleteUser(user):
            errorList.append(("delete user", "Cannot delete user %s" % user))
            exitCode = 255

    if not exitCode:
        result = diracAdmin.csCommitChanges()
        if not result["OK"]:
            errorList.append(("commit", result["Message"]))
            exitCode = 255

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Beispiel #3
0
def main():
    Script.setUsageMessage("\n".join([
        "Get VM nodes information",
        "Usage:",
        "%s site ce node [option]... [cfgfile]" % Script.scriptName,
        "Arguments:",
        " cfgfile: DIRAC Cfg with description of the configuration (optional)",
    ]))
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()

    from DIRAC.WorkloadManagementSystem.Client.VMClient import VMClient
    from DIRAC.Core.Security.ProxyInfo import getVOfromProxyGroup

    if len(args) != 3:
        print(Script.showHelp())
        DIRACExit(-1)

    site, ce, node = args

    vmClient = VMClient()
    result = vmClient.stopInstance(site, ce, node)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACExit(-1)

    DIRACExit(0)
Beispiel #4
0
def main():
    Script.setUsageMessage(
        "\n".join(
            [
                "Get VM pilot output",
                "Usage:",
                "%s [option]... [cfgfile]" % Script.scriptName,
                "Arguments:",
                " cfgfile: DIRAC Cfg with description of the configuration (optional)",
            ]
        )
    )
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()

    from DIRAC.WorkloadManagementSystem.Client.VMClient import VMClient

    if len(args) != 1:
        print(Script.showHelp())
        DIRACExit(-1)

    pilotRef = args[0]

    vmClient = VMClient()
    result = vmClient.getPilotOutput(pilotRef)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACExit(-1)

    print(result)

    DIRACExit(0)
Beispiel #5
0
def main():
    """
    Main function of the script. Gets the username from the proxy loaded and sets
    the token taking into account that user and the switchDict parameters.
    """
    global subLogger
    global switchDict

    # Logger initialization
    subLogger = gLogger.getSubLogger(__file__)

    # Script initialization
    registerSwitches()
    registerUsageMessage()
    switchDict = parseSwitches()

    user = proxyUser()
    if not user["OK"]:
        subLogger.error(user["Message"])
        DIRACExit(1)
    user = user["Value"]

    res = setToken(user)
    if not res["OK"]:
        subLogger.error(res["Message"])
        DIRACExit(1)

    DIRACExit(0)
def main():
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()

    if len(args) < 1:
        Script.showHelp()

    from DIRAC import exit as DIRACExit, gLogger

    try:
        jobIDs = [int(arg) for arg in args]
    except BaseException:
        gLogger.fatal('DIRAC Job IDs must be integers')
        DIRACExit(2)

    from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient
    client = StorageManagerClient()

    outStr = "\n"
    for jobID in jobIDs:
        res = client.getTaskSummary(jobID)
        if not res['OK']:
            gLogger.error(res['Message'])
            continue
        if not res['Value']:
            gLogger.notice(
                'No info for job %s, probably gone from the stager...' % jobID)
            continue
        taskInfo = res['Value']['TaskInfo']
        replicaInfo = res['Value']['ReplicaInfo']
        outStr = "%s: %s" % ('JobID'.ljust(20), jobID)
        outStr += "\n%s: %s" % ('Status'.ljust(20),
                                taskInfo[str(jobID)]['Status'])
        outStr += "\n%s: %s" % ('SubmitTime'.ljust(20),
                                taskInfo[str(jobID)]['SubmitTime'])
        outStr += "\n%s: %s" % ('CompleteTime'.ljust(20),
                                taskInfo[str(jobID)]['CompleteTime'])
        outStr += "\nStaging files for this job:"
        if not res['Value']['ReplicaInfo']:
            gLogger.notice('No info on files for the job = %s, that is odd' %
                           jobID)
            continue
        else:
            for lfn, metadata in replicaInfo.items():
                outStr += "\n\t--------------------"
                outStr += "\n\t%s: %s" % ('LFN'.ljust(8), lfn.ljust(100))
                outStr += "\n\t%s: %s" % (
                    'SE'.ljust(8), metadata['StorageElement'].ljust(100))
                outStr += "\n\t%s: %s" % ('PFN'.ljust(8), str(
                    metadata['PFN']).ljust(100))
                outStr += "\n\t%s: %s" % ('Status'.ljust(8),
                                          metadata['Status'].ljust(100))
                outStr += "\n\t%s: %s" % ('Reason'.ljust(8),
                                          str(metadata['Reason']).ljust(100))
                outStr += "\n%s: %s" % ('LastUpdate'.ljust(8),
                                        str(metadata['LastUpdate']).ljust(100))
            outStr += "\n----------------------"
        gLogger.notice(outStr)
    DIRACExit(0)
Beispiel #7
0
def parseSwitches():
  """
  Parses the arguments passed by the user
  """

  Script.parseCommandLine( ignoreErrors = True )
  args = Script.getPositionalArgs()
  if args:
    subLogger.error( "Found the following positional args '%s', but we only accept switches" % args )
    subLogger.error( "Please, check documentation below" )
    Script.showHelp()
    DIRACExit( 1 )

  switches = dict( Script.getUnprocessedSwitches() )
  switches.setdefault( 'statusType'  , None )
  switches.setdefault( 'releaseToken', False )

  for key in ( 'element', 'name', 'reason' ):

    if not key in switches:
      subLogger.error( "%s Switch missing" % key )
      subLogger.error( "Please, check documentation below" )
      Script.showHelp()
      DIRACExit( 1 )

  if not switches[ 'element' ] in ( 'Site', 'Resource', 'Node' ):
    subLogger.error( "Found %s as element switch" % switches[ 'element' ] )
    subLogger.error( "Please, check documentation below" )
    Script.showHelp()
    DIRACExit( 1 )

  subLogger.debug( "The switches used are:" )
  map( subLogger.debug, switches.iteritems() )

  return switches
def parseSwitches():
    '''
    Parses the arguments passed by the user
  '''

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if args:
        subLogger.error(
            "Found the following positional args '%s', but we only accept switches"
            % args)
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    switches = dict(Script.getUnprocessedSwitches())

    for key in ('status', 'se', 'limit'):
        if key not in switches:
            subLogger.warn(
                "You're not using switch --%s, query may take long!" % key)

    if 'status' in switches and switches['status'] not in (
            'New', 'Offline', 'Waiting', 'Failed', 'StageSubmitted', 'Staged'):
        subLogger.error("Found \"%s\" as Status value. Incorrect value used!" %
                        switches['status'])
        subLogger.error("Please, check documentation below")
        Script.showHelp()
        DIRACExit(1)

    subLogger.debug("The switches used are:")
    map(subLogger.debug, switches.iteritems())

    return switches
def main():
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()

    csAPI = CSAPI()

    if len(args) < 3:
        Script.showHelp(exitCode=1)

    shifterRole = args[0]
    userName = args[1]
    diracGroup = args[2]

    res = csAPI.addShifter(
        {shifterRole: {
            'User': userName,
            'Group': diracGroup
        }})
    if not res['OK']:
        gLogger.error("Could not add shifter", ": " + res['Message'])
        DIRACExit(1)
    res = csAPI.commit()
    if not res['OK']:
        gLogger.error("Could not add shifter", ": " + res['Message'])
        DIRACExit(1)
    gLogger.notice("Added shifter %s as user %s with group %s" %
                   (shifterRole, userName, diracGroup))
Beispiel #10
0
def initSites():
    """
    Initializes Sites statuses taking their values from the "SiteMask" table of "JobDB" database.
    """
    from DIRAC.WorkloadManagementSystem.Client.WMSAdministratorClient import WMSAdministratorClient
    from DIRAC.ResourceStatusSystem.Client import ResourceStatusClient

    rssClient = ResourceStatusClient.ResourceStatusClient()

    sites = WMSAdministratorClient().getAllSiteMaskStatus()

    if not sites["OK"]:
        subLogger.error(sites["Message"])
        DIRACExit(1)

    for site, elements in sites["Value"].items():
        result = rssClient.addOrModifyStatusElement(
            "Site",
            "Status",
            name=site,
            statusType="all",
            status=elements[0],
            elementType=site.split(".")[0],
            tokenOwner="rs_svc",
            reason="dirac-rss-sync",
        )
        if not result["OK"]:
            subLogger.error(result["Message"])
            DIRACExit(1)

    return S_OK()
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "ShifterRole:  Name of the shifter role, e.g. DataManager")
    Script.registerArgument(
        "UserName:     A user name, as registered in Registry section")
    Script.registerArgument(
        "DIRACGroup:   DIRAC Group, e.g. diracAdmin (the user has to have this role)"
    )
    Script.parseCommandLine(ignoreErrors=True)

    csAPI = CSAPI()

    shifterRole, userName, diracGroup = Script.getPositionalArgs(group=True)
    res = csAPI.addShifter(
        {shifterRole: {
            "User": userName,
            "Group": diracGroup
        }})
    if not res["OK"]:
        gLogger.error("Could not add shifter", ": " + res["Message"])
        DIRACExit(1)
    res = csAPI.commit()
    if not res["OK"]:
        gLogger.error("Could not add shifter", ": " + res["Message"])
        DIRACExit(1)
    gLogger.notice("Added shifter %s as user %s with group %s" %
                   (shifterRole, userName, diracGroup))
Beispiel #12
0
def initSites():
    '''
    Initializes Sites statuses taking their values from the "SiteMask" table of "JobDB" database.
  '''

    rssClient = ResourceStatusClient.ResourceStatusClient()

    sites = WMSAdministratorClient().getAllSiteMaskStatus()

    if not sites['OK']:
        subLogger.error(sites['Message'])
        DIRACExit(1)

    for site, elements in sites['Value'].iteritems():
        result = rssClient.addOrModifyStatusElement(
            "Site",
            "Status",
            name=site,
            statusType='all',
            status=elements[0],
            elementType=site.split('.')[0],
            tokenOwner='rs_svc',
            reason='dirac-rss-sync')
        if not result['OK']:
            subLogger.error(result['Message'])
            DIRACExit(1)

    return S_OK()
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)
Beispiel #14
0
def main():
    global includeMasterCS
    Script.registerSwitch("n", "noMasterCS", "do not include master CS",
                          setNoMasterCS)
    Script.parseCommandLine()

    from DIRAC import gLogger, exit as DIRACExit
    from DIRAC.WorkloadManagementSystem.Utilities.PilotCStoJSONSynchronizer import PilotCStoJSONSynchronizer

    ps = PilotCStoJSONSynchronizer()

    gLogger.verbose("Parameters for this sync:")
    gLogger.verbose("repo=" + ps.pilotRepo)
    gLogger.verbose("VO repo=" + ps.pilotVORepo)
    gLogger.verbose("projectDir=" + ps.projectDir)
    gLogger.verbose("pilotScriptsPath=" + ps.pilotScriptPath)
    gLogger.verbose("pilotVOScriptsPath=" + ps.pilotVOScriptPath)
    gLogger.verbose("pilotRepoBranch=" + ps.pilotRepoBranch)
    gLogger.verbose("pilotVORepoBranch=" + ps.pilotVORepoBranch)

    # pilot.json
    res = ps.getCSDict(includeMasterCS=includeMasterCS)
    if not res['OK']:
        DIRACExit(1)
    pilotDict = res['Value']
    print(json.dumps(
        pilotDict, indent=4,
        sort_keys=True))  # just print here as formatting is important
    with open('pilot.json', 'w') as jf:
        json.dump(pilotDict, jf)

    # pilot files
    res = ps.syncScripts()
    if not res['OK']:
        DIRACExit(1)
    gLogger.always(res['Value'])
    tarPath, tarFiles = res['Value']

    allFiles = [tarPath] + tarFiles + ['pilot.json']

    # checksums
    checksumDict = {}
    for pFile in allFiles:
        filename = os.path.basename(pFile)
        with open(pFile, 'rb') as fp:
            checksumDict[filename] = hashlib.sha512(fp.read()).hexdigest()
        cksPath = 'checksums.sha512'
    with open(cksPath, 'wt') as chksums:
        for filename, chksum in sorted(checksumDict.items()):
            # same as the output from sha512sum commands
            chksums.write('%s  %s\n' % (chksum, filename))

    allFiles = allFiles + [cksPath]

    print(allFiles)
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "Request:  ID of the Stage request in the StorageManager")
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()

    if not len(args) == 1:
        Script.showHelp()

    from DIRAC import exit as DIRACExit, gLogger

    try:
        taskID = int(args[0])
    except Exception:
        gLogger.fatal("Stage requestID must be an integer")
        DIRACExit(2)

    from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient

    client = StorageManagerClient()

    res = client.getTaskSummary(taskID)
    if not res["OK"]:
        gLogger.error(res["Message"])
        DIRACExit(2)
    taskInfo = res["Value"]["TaskInfo"]
    replicaInfo = res["Value"]["ReplicaInfo"]
    outStr = "%s: %s" % ("TaskID".ljust(20), taskID)
    outStr += "\n%s: %s" % ("Status".ljust(20), taskInfo[taskID]["Status"])
    outStr += "\n%s: %s" % ("Source".ljust(20), taskInfo[taskID]["Source"])
    outStr += "\n%s: %s" % ("SourceTaskID".ljust(20),
                            taskInfo[taskID]["SourceTaskID"])
    outStr += "\n%s: %s" % ("CallBackMethod".ljust(20),
                            taskInfo[taskID]["CallBackMethod"])
    outStr += "\n%s: %s" % ("SubmitTime".ljust(20),
                            taskInfo[taskID]["SubmitTime"])
    outStr += "\n%s: %s" % ("CompleteTime".ljust(20),
                            taskInfo[taskID]["CompleteTime"])
    for lfn, metadata in replicaInfo.items():
        outStr += "\n"
        outStr += "\n\t%s: %s" % ("LFN".ljust(8), lfn.ljust(100))
        outStr += "\n\t%s: %s" % ("SE".ljust(8),
                                  metadata["StorageElement"].ljust(100))
        outStr += "\n\t%s: %s" % ("PFN".ljust(8), str(
            metadata["PFN"]).ljust(100))
        outStr += "\n\t%s: %s" % ("Size".ljust(8), str(
            metadata["FileSize"]).ljust(100))
        outStr += "\n\t%s: %s" % ("Status".ljust(8),
                                  metadata["Status"].ljust(100))
        outStr += "\n\t%s: %s" % ("Reason".ljust(8), str(
            metadata["Reason"]).ljust(100))
    gLogger.notice(outStr)
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()

    if len(args) < 1:
        Script.showHelp()

    from DIRAC import exit as DIRACExit, gLogger

    try:
        jobIDs = [int(arg) for arg in args]
    except Exception:
        gLogger.fatal("DIRAC Job IDs must be integers")
        DIRACExit(2)

    from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient

    client = StorageManagerClient()

    outStr = "\n"
    for jobID in jobIDs:
        res = client.getTaskSummary(jobID)
        if not res["OK"]:
            gLogger.error(res["Message"])
            continue
        if not res["Value"]:
            gLogger.notice("No info for job %s, probably gone from the stager..." % jobID)
            continue
        taskInfo = res["Value"]["TaskInfo"]
        replicaInfo = res["Value"]["ReplicaInfo"]
        outStr = "%s: %s" % ("JobID".ljust(20), jobID)
        outStr += "\n%s: %s" % ("Status".ljust(20), taskInfo[str(jobID)]["Status"])
        outStr += "\n%s: %s" % ("SubmitTime".ljust(20), taskInfo[str(jobID)]["SubmitTime"])
        outStr += "\n%s: %s" % ("CompleteTime".ljust(20), taskInfo[str(jobID)]["CompleteTime"])
        outStr += "\nStaging files for this job:"
        if not res["Value"]["ReplicaInfo"]:
            gLogger.notice("No info on files for the job = %s, that is odd" % jobID)
            continue
        else:
            for lfn, metadata in replicaInfo.items():
                outStr += "\n\t--------------------"
                outStr += "\n\t%s: %s" % ("LFN".ljust(8), lfn.ljust(100))
                outStr += "\n\t%s: %s" % ("SE".ljust(8), metadata["StorageElement"].ljust(100))
                outStr += "\n\t%s: %s" % ("PFN".ljust(8), str(metadata["PFN"]).ljust(100))
                outStr += "\n\t%s: %s" % ("Status".ljust(8), metadata["Status"].ljust(100))
                outStr += "\n\t%s: %s" % ("Reason".ljust(8), str(metadata["Reason"]).ljust(100))
                outStr += "\n%s: %s" % ("LastUpdate".ljust(8), str(metadata["LastUpdate"]).ljust(100))
            outStr += "\n----------------------"
        gLogger.notice(outStr)
    DIRACExit(0)
def main():
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()

    if not len(args) == 1:
        Script.showHelp()

    from DIRAC import exit as DIRACExit, gLogger

    try:
        taskID = int(args[0])
    except BaseException:
        gLogger.fatal('Stage requestID must be an integer')
        DIRACExit(2)

    from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient
    client = StorageManagerClient()

    res = client.getTaskSummary(taskID)
    if not res['OK']:
        gLogger.error(res['Message'])
        DIRACExit(2)
    taskInfo = res['Value']['TaskInfo']
    replicaInfo = res['Value']['ReplicaInfo']
    outStr = "%s: %s" % ('TaskID'.ljust(20), taskID)
    outStr += "\n%s: %s" % ('Status'.ljust(20), taskInfo[taskID]['Status'])
    outStr += "\n%s: %s" % ('Source'.ljust(20), taskInfo[taskID]['Source'])
    outStr += "\n%s: %s" % ('SourceTaskID'.ljust(20),
                            taskInfo[taskID]['SourceTaskID'])
    outStr += "\n%s: %s" % ('CallBackMethod'.ljust(20),
                            taskInfo[taskID]['CallBackMethod'])
    outStr += "\n%s: %s" % ('SubmitTime'.ljust(20),
                            taskInfo[taskID]['SubmitTime'])
    outStr += "\n%s: %s" % ('CompleteTime'.ljust(20),
                            taskInfo[taskID]['CompleteTime'])
    for lfn, metadata in replicaInfo.items():
        outStr += "\n"
        outStr += "\n\t%s: %s" % ('LFN'.ljust(8), lfn.ljust(100))
        outStr += "\n\t%s: %s" % ('SE'.ljust(8),
                                  metadata['StorageElement'].ljust(100))
        outStr += "\n\t%s: %s" % ('PFN'.ljust(8), str(
            metadata['PFN']).ljust(100))
        outStr += "\n\t%s: %s" % ('Size'.ljust(8), str(
            metadata['FileSize']).ljust(100))
        outStr += "\n\t%s: %s" % ('Status'.ljust(8),
                                  metadata['Status'].ljust(100))
        outStr += "\n\t%s: %s" % ('Reason'.ljust(8), str(
            metadata['Reason']).ljust(100))
    gLogger.notice(outStr)
Beispiel #18
0
def main():
    Script.registerSwitch("f:", "File=",
                          "Get status for jobs with IDs from the file")
    Script.registerSwitch("g:", "JobGroup=",
                          "Get status for jobs in the given group")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"], mandatory=False)
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Core.Utilities.Time import toString, date, day
    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0

    jobs = []
    for key, value in sws:
        if key.lower() in ("f", "file"):
            if os.path.exists(value):
                jFile = open(value)
                jobs += jFile.read().split()
                jFile.close()
        elif key.lower() in ("g", "jobgroup"):
            jobDate = toString(date() - 30 * day)
            # Choose jobs no more than 30 days old
            result = dirac.selectJobs(jobGroup=value, date=jobDate)
            if not result["OK"]:
                print("Error:", result["Message"])
                DIRACExit(-1)
            jobs += result["Value"]

    if len(args) < 1 and not jobs:
        Script.showHelp(exitCode=1)

    if len(args) > 0:
        jobs += parseArguments(args)

    result = dirac.getJobStatus(jobs)
    if result["OK"]:
        for job in result["Value"]:
            print("JobID=" + str(job), end=" ")
            for status in result["Value"][job].items():
                print("%s=%s;" % status, end=" ")
            print()
    else:
        exitCode = 2
        print("ERROR: %s" % result["Message"])

    DIRACExit(exitCode)
Beispiel #19
0
def main():
    Script.registerSwitch("f:", "File=",
                          "Get status for jobs with IDs from the file")
    Script.registerSwitch("g:", "JobGroup=",
                          "Get status for jobs in the given group")

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()

    from DIRAC import exit as DIRACExit
    from DIRAC.Core.Utilities.Time import toString, date, day
    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0

    jobs = []
    for key, value in Script.getUnprocessedSwitches():
        if key.lower() in ('f', 'file'):
            if os.path.exists(value):
                jFile = open(value)
                jobs += jFile.read().split()
                jFile.close()
        elif key.lower() in ('g', 'jobgroup'):
            jobDate = toString(date() - 30 * day)
            # Choose jobs no more than 30 days old
            result = dirac.selectJobs(jobGroup=value, date=jobDate)
            if not result['OK']:
                print("Error:", result['Message'])
                DIRACExit(-1)
            jobs += result['Value']

    if len(args) < 1 and not jobs:
        Script.showHelp(exitCode=1)

    if len(args) > 0:
        jobs += parseArguments(args)

    result = dirac.getJobStatus(jobs)
    if result['OK']:
        for job in result['Value']:
            print('JobID=' + str(job), end=' ')
            for status in result['Value'][job].items():
                print('%s=%s;' % status, end=' ')
            print()
    else:
        exitCode = 2
        print("ERROR: %s" % result['Message'])

    DIRACExit(exitCode)
Beispiel #20
0
def run():
    '''
    Main function of the script
  '''

    result = synchronize()
    if not result['OK']:
        subLogger.error(result['Message'])
        DIRACExit(1)

    if 'init' in switchDict:
        result = initSEs()
        if not result['OK']:
            subLogger.error(result['Message'])
            DIRACExit(1)
Beispiel #21
0
def main():
    Script.parseCommandLine()

    from DIRAC import gLogger
    from DIRAC.DataManagementSystem.Client.DataManager import DataManager

    args = Script.getPositionalArgs()
    if not len(args) == 2:
        Script.showHelp(exitCode=1)
    else:
        inputFileName = args[0]
        storageElement = args[1]

    if os.path.exists(inputFileName):
        inputFile = open(inputFileName, 'r')
        string = inputFile.read()
        lfns = [lfn.strip() for lfn in string.splitlines()]
        inputFile.close()
    else:
        lfns = [inputFileName]

    res = DataManager().getReplicaMetadata(lfns, storageElement)
    if not res['OK']:
        print('Error:', res['Message'])
        DIRACExit(1)

    print('%s %s %s %s' % ('File'.ljust(100), 'Migrated'.ljust(8),
                           'Cached'.ljust(8), 'Size (bytes)'.ljust(10)))
    for lfn, metadata in res['Value']['Successful'].items():
        print('%s %s %s %s' %
              (lfn.ljust(100), str(metadata['Migrated']).ljust(8),
               str(metadata.get('Cached', metadata['Accessible'])).ljust(8),
               str(metadata['Size']).ljust(10)))
    for lfn, reason in res['Value']['Failed'].items():
        print('%s %s' % (lfn.ljust(100), reason.ljust(8)))
Beispiel #22
0
def main():
  Script.parseCommandLine(ignoreErrors=True)
  args = Script.getPositionalArgs()
  if len(args) < 2:
    Script.showHelp()

  from DIRAC import exit as DIRACExit, gLogger

  lfn = args[0]
  se = args[1]

  from DIRAC.StorageManagementSystem.Client.StorageManagerClient import StorageManagerClient
  client = StorageManagerClient()
  res = client.getCacheReplicas({'LFN': lfn, 'SE': se})
  if not res['OK']:
    gLogger.error(res['Message'])
  cacheReplicaInfo = res['Value']
  if cacheReplicaInfo:
    replicaID = list(cacheReplicaInfo)[0]
    outStr = "\n--------------------"
    outStr += "\n%s: %s" % ('LFN'.ljust(8), cacheReplicaInfo[replicaID]['LFN'].ljust(100))
    outStr += "\n%s: %s" % ('SE'.ljust(8), cacheReplicaInfo[replicaID]['SE'].ljust(100))
    outStr += "\n%s: %s" % ('PFN'.ljust(8), cacheReplicaInfo[replicaID]['PFN'].ljust(100))
    outStr += "\n%s: %s" % ('Status'.ljust(8), cacheReplicaInfo[replicaID]['Status'].ljust(100))
    outStr += "\n%s: %s" % ('LastUpdate'.ljust(8), str(cacheReplicaInfo[replicaID]['LastUpdate']).ljust(100))
    outStr += "\n%s: %s" % ('Reason'.ljust(8), str(cacheReplicaInfo[replicaID]['Reason']).ljust(100))

    resTasks = client.getTasks({'ReplicaID': replicaID})

    if resTasks['OK']:
      # print resTasks['Message']
      outStr += '\nJob IDs requesting this file to be staged:'.ljust(8)
      tasks = resTasks['Value']
      for tid in tasks.keys():
        outStr += ' %s ' % (tasks[tid]['SourceTaskID'])

    resStageRequests = client.getStageRequests({'ReplicaID': replicaID})

    if not resStageRequests['OK']:
      gLogger.error(resStageRequests['Message'])

    if resStageRequests['Records']:
      stageRequests = resStageRequests['Value']
      outStr += "\n------SRM staging request info--------------"
      for info in stageRequests.values():
        outStr += "\n%s: %s" % ('SRM RequestID'.ljust(8), info['RequestID'].ljust(100))
        outStr += "\n%s: %s" % ('SRM StageStatus'.ljust(8), info['StageStatus'].ljust(100))
        outStr += "\n%s: %s" % ('SRM StageRequestSubmitTime'.ljust(8), str(info['StageRequestSubmitTime']).ljust(100))
        outStr += "\n%s: %s" % ('SRM StageRequestCompletedTime'.ljust(8),
                                str(info['StageRequestCompletedTime']).ljust(100))
        outStr += "\n%s: %s" % ('SRM PinExpiryTime'.ljust(8), str(info['PinExpiryTime']).ljust(100))
        outStr += "\n%s: %s sec" % ('SRM PinLength'.ljust(8), str(info['PinLength']).ljust(100))
    else:
      outStr += '\nThere are no staging requests submitted to the site yet.'.ljust(8)
  else:
    outStr = "\nThere is no such file requested for staging. Check for typo's!"
    # Script.showHelp()
  gLogger.notice(outStr)

  DIRACExit(0)
Beispiel #23
0
def main():
  """
  Main function of the script. Gets the username from the proxy loaded and sets
  the token taking into account that user and the switchDict parameters.
  """

  user = proxyUser()
  if not user[ 'OK' ]:
    subLogger.error( user[ 'Message' ] )
    DIRACExit( 1 )
  user = user[ 'Value' ]

  res = setToken( user )
  if not res[ 'OK' ]:
    subLogger.error( res[ 'Message' ] )
    DIRACExit( 1 )
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["PilotID:  Grid ID of the pilot"])
    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    for gridID in args:

        result = diracAdmin.getPilotLoggingInfo(gridID)
        if not result["OK"]:
            errorList.append((gridID, result["Message"]))
            exitCode = 2
        else:
            print("Pilot Reference: %s", gridID)
            print(result["Value"])
            print()

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Beispiel #25
0
def main():
    Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit, gLogger
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()

    gLogger.setLevel("ALWAYS")

    result = diracAdmin.getSiteMask(printOutput=True, status="Active")
    if result["OK"]:
        DIRACExit(0)
    else:
        print(result["Message"])
        DIRACExit(2)
Beispiel #26
0
def main():
    Script.registerSwitch("e", "extended", "Show extended info")

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []
    extendedInfo = False

    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ('e', 'extended'):
            extendedInfo = True

    if not extendedInfo:
        result = diracAdmin.csListHosts()
        for host in result['Value']:
            print(" %s" % host)
    else:
        result = diracAdmin.csDescribeHosts()
        print(diracAdmin.pPrint.pformat(result['Value']))

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
def main():
    signal.signal(signal.SIGTERM, handler)
    signal.signal(signal.SIGINT, handler)

    global vo, dry, doCEs, ceBdiiDict

    processScriptSwitches()

    if not vo:
        gLogger.error('No VO specified')
        DIRACExit(-1)

    vo = getVOOption(vo, 'VOMSName', vo)

    if doCEs:
        yn = six.moves.input(
            'Do you want to check/add new sites to CS ? [default yes] [yes|no]: '
        )
        yn = yn.strip()
        if yn == '' or yn.lower().startswith('y'):
            checkUnusedCEs()

        yn = six.moves.input(
            'Do you want to update CE details in the CS ? [default yes] [yes|no]: '
        )
        yn = yn.strip()
        if yn == '' or yn.lower().startswith('y'):
            updateSites()
def updateCS(changeSet):

    global vo, dry, ceBdiiDict

    changeList = sorted(changeSet)
    if dry:
        gLogger.notice('The following needed changes are detected:\n')
    else:
        gLogger.notice('We are about to make the following changes to CS:\n')
    for entry in changeList:
        gLogger.notice("%s/%s %s -> %s" % entry)

    if not dry:
        csAPI = CSAPI()
        csAPI.initialize()
        result = csAPI.downloadCSData()
        if not result['OK']:
            gLogger.error('Failed to initialize CSAPI object',
                          result['Message'])
            DIRACExit(-1)
        for section, option, value, new_value in changeSet:
            if value == 'Unknown' or not value:
                csAPI.setOption(cfgPath(section, option), new_value)
            else:
                csAPI.modifyValue(cfgPath(section, option), new_value)

        yn = six.moves.input(
            'Do you want to commit changes to CS ? [default yes] [yes|no]: ')
        if yn == '' or yn.lower().startswith('y'):
            result = csAPI.commit()
            if not result['OK']:
                gLogger.error("Error while commit to CS", result['Message'])
            else:
                gLogger.notice("Successfully committed %d changes to CS" %
                               len(changeSet))
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC ID of the Job"])
    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    _, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC import exit as DIRACExit
    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    errorList = []

    for job in args:

        try:
            job = int(job)
        except Exception:
            errorList.append(("Expected integer for JobID", job))
            exitCode = 2
            continue

        result = diracAdmin.getJobPilotOutput(job)
        if not result["OK"]:
            errorList.append((job, result["Message"]))
            exitCode = 2

    for error in errorList:
        print("ERROR %s: %s" % error)

    DIRACExit(exitCode)
Beispiel #30
0
def main():
  Script.parseCommandLine(ignoreErrors=True)
  args = Script.getPositionalArgs()

  if len(args) < 1:
    Script.showHelp()

  from DIRAC import exit as DIRACExit
  from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin
  diracAdmin = DiracAdmin()
  exitCode = 0
  errorList = []

  for gridID in args:

    result = diracAdmin.getPilotLoggingInfo(gridID)
    if not result['OK']:
      errorList.append((gridID, result['Message']))
      exitCode = 2
    else:
      print('Pilot Reference: %s', gridID)
      print(result['Value'])
      print()

  for error in errorList:
    print("ERROR %s: %s" % error)

  DIRACExit(exitCode)