def main():
    Script.registerSwitch(
        "v:",
        "vo=",
        "Location of pilot version in CS /Operations/<vo>/Pilot/Version"
        " (default value specified in CS under /DIRAC/DefaultSetup)",
    )
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument("version: pilot version you want to update to")
    Script.parseCommandLine(ignoreErrors=False)

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    version = Script.getPositionalArgs(group=True)

    vo = None
    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "v" or switch[0] == "vo":
            vo = switch[1]

    from DIRAC import S_OK, S_ERROR
    from DIRAC import gConfig, gLogger
    from DIRAC.ConfigurationSystem.Client.CSAPI import CSAPI

    def updatePilot(version, vo):
        """
        Update in the CS the pilot version used,
        If only one version present in CS it's overwritten.
        If two versions present, the new one is added and the last removed

        :param version: version vArBpC of pilot you want to use
        :param vo: Location of pilot version in CS /Operations/<vo>/Pilot/Version
        """
        setup = vo
        if not vo:
            setup = gConfig.getValue("/DIRAC/DefaultSetup")
        if not setup:
            return S_ERROR("No value set for /DIRAC/DefaultSetup in CS")

        pilotVersion = gConfig.getValue("Operations/%s/Pilot/Version" % setup, [])
        if not pilotVersion:
            return S_ERROR("No pilot version set under Operations/%s/Pilot/Version in CS" % setup)

        pilotVersion.pop()
        pilotVersion.insert(0, version)
        api = CSAPI()
        api.setOption("Operations/%s/Pilot/Version" % setup, ", ".join(pilotVersion))
        result = api.commit()
        if not result["OK"]:
            gLogger.fatal("Could not commit new version of pilot!")
            return result

        newVersion = gConfig.getValue("Operations/%s/Pilot/Version" % setup)
        return S_OK("New version of pilot set to %s" % newVersion)

    result = updatePilot(version, vo)
    if not result["OK"]:
        gLogger.fatal(result["Message"])
        DIRAC.exit(1)
    gLogger.notice(result["Value"])
    DIRAC.exit(0)
Exemple #2
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(exitCode=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(exitCode=1)

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

    return switches
Exemple #3
0
def main():
    Script.registerSwitch("", "Full", "   Print full list of requests")
    Script.parseCommandLine()
    from DIRAC.RequestManagementSystem.Client.ReqClient import ReqClient

    fullPrint = False

    for switch in Script.getUnprocessedSwitches():
        if switch[0] == "Full":
            fullPrint = True

    reqClient = ReqClient()

    for server, rpcClient in reqClient.requestProxies().items():
        DIRAC.gLogger.always("Checking request cache at %s" % server)
        reqCache = rpcClient.listCacheDir()
        if not reqCache["OK"]:
            DIRAC.gLogger.error("Cannot list request cache", reqCache)
            continue
        reqCache = reqCache["Value"]

        if not reqCache:
            DIRAC.gLogger.always("No request in cache")
        else:
            if fullPrint:
                DIRAC.gLogger.always("List of requests", reqCache)
            else:
                DIRAC.gLogger.always("Number of requests in the cache",
                                     len(reqCache))

    DIRAC.exit(0)
def main():
    Script.localCfg.addDefaultEntry("LogLevel", "fatal")

    fileName = ""

    def setFilename(args):
        global fileName
        fileName = args
        return DIRAC.S_OK()

    raw = False

    def setRaw(args):
        global raw
        raw = True
        return DIRAC.S_OK()

    Script.registerSwitch("f:", "file=", "Dump Configuration data into <file>",
                          setFilename)
    Script.registerSwitch("r", "raw",
                          "Do not make any modification to the data", setRaw)
    Script.parseCommandLine()

    from DIRAC import gConfig, gLogger

    result = gConfig.dumpCFGAsLocalCache(fileName, raw)
    if not result["OK"]:
        print("Error: %s" % result["Message"])
        sys.exit(1)

    if not fileName:
        print(result["Value"])

    sys.exit(0)
def main():
    Script.registerSwitch("e", "extended", "Show extended info")

    Script.parseCommandLine(ignoreErrors=True)

    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():
    PARAMS = Params()
    PARAMS.registerSwitches()
    Script.parseCommandLine(ignoreErrors=False)

    # Create Data Recovery Agent and run over single transformation.
    from DIRAC.TransformationSystem.Client.TransformationClient import TransformationClient
    from DIRAC.TransformationSystem.Agent.DataRecoveryAgent import DataRecoveryAgent

    DRA = DataRecoveryAgent("Transformation/DataRecoveryAgent",
                            "Transformation/DataRecoveryAgent")
    DRA.jobStatus = ["Done", "Failed"]
    DRA.enabled = PARAMS.enabled
    TRANSFORMATION = TransformationClient().getTransformations(
        condDict={"TransformationID": PARAMS.transID})
    if not TRANSFORMATION["OK"]:
        gLogger.error("Failed to find transformation: %s" %
                      TRANSFORMATION["Message"])
        exit(1)
    if not TRANSFORMATION["Value"]:
        gLogger.error("Did not find any transformations")
        exit(1)
    TRANS_INFO_DICT = TRANSFORMATION["Value"][0]
    TRANS_INFO_DICT.pop("Body", None)
    gLogger.notice("Found transformation: %s" % TRANS_INFO_DICT)
    DRA.treatTransformation(PARAMS.transID, TRANS_INFO_DICT)
    exit(0)
Exemple #7
0
def main():
    """reads command line parameters, makes check and creates replication transformation"""
    from DIRAC import gLogger, exit as dexit
    from DIRAC.TransformationSystem.Utilities.ReplicationCLIParameters import Params

    clip = Params()
    clip.registerSwitches(Script)
    Script.parseCommandLine()

    from DIRAC.TransformationSystem.Utilities.ReplicationTransformation import createDataTransformation

    if not clip.checkSettings(Script)["OK"]:
        gLogger.error("ERROR: Missing settings")
        dexit(1)
    for metaValue in clip.metaValues:
        resCreate = createDataTransformation(
            flavour=clip.flavour,
            targetSE=clip.targetSE,
            sourceSE=clip.sourceSE,
            metaKey=clip.metaKey,
            metaValue=metaValue,
            extraData=clip.extraData,
            extraname=clip.extraname,
            groupSize=clip.groupSize,
            tGroup=clip.groupName,
            plugin=clip.plugin,
            enable=clip.enable,
        )
        if not resCreate["OK"]:
            gLogger.error("Failed to create Transformation",
                          resCreate["Message"])
            dexit(1)

    dexit(0)
Exemple #8
0
def parseSwitchesAndPositionalArguments():
    """
    Parse switches and positional arguments given to the script
    """

    # Parse the command line and initialize DIRAC
    Script.parseCommandLine(ignoreErrors=False)

    # Get arguments
    allArgs = Script.getPositionalArgs()
    gLogger.debug("All arguments: %s" % ", ".join(allArgs))

    # Get unprocessed switches
    switches = dict(Script.getUnprocessedSwitches())

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

    # Get grouped positional arguments
    repType, user, services = Script.getPositionalArgs(group=True)
    gLogger.debug("The positional arguments are:")
    gLogger.debug("Report type:", repType)
    gLogger.debug("Name or DN:", user)
    gLogger.debug("Services:", services)

    return switches, repType, user, services
def main():
    params = Params()

    Script.registerSwitch("f:", "file=", "File to use as proxy", params.setProxyLocation)
    Script.registerSwitch("D", "DN", "Use DN as myproxy username", params.setDNAsUsername)
    Script.registerSwitch("i", "version", "Print version", params.showVersion)

    Script.addDefaultOptionValue("LogLevel", "always")
    Script.parseCommandLine()

    from DIRAC.Core.Security.MyProxy import MyProxy
    from DIRAC.Core.Security import Locations

    if not params.proxyLoc:
        params.proxyLoc = Locations.getProxyLocation()

    if not params.proxyLoc:
        print("Can't find any valid proxy")
        sys.exit(1)
    print("Uploading proxy file %s" % params.proxyLoc)

    mp = MyProxy()
    retVal = mp.uploadProxy(params.proxyLoc, params.dnAsUsername)
    if not retVal["OK"]:
        print("Can't upload proxy:")
        print(" ", retVal["Message"])
        sys.exit(1)
    print("Proxy uploaded")
    sys.exit(0)
Exemple #10
0
def processScriptSwitches():

    global vo, dry, doCEs, hostURL, onecore

    Script.registerSwitch("V:", "vo=", "Virtual Organization")
    Script.registerSwitch("D", "dry", "Dry run")
    Script.registerSwitch("C", "ce", "Process Computing Elements")
    Script.registerSwitch("H:", "host=", "use this url for information querying")
    Script.registerSwitch(
        "", "onecore", "Add Single Core Queues for each MultiCore Queue, set RequiredTag for those Queues"
    )
    Script.parseCommandLine(ignoreErrors=True)

    vo = ""
    dry = False
    doCEs = False
    hostURL = None
    onecore = False

    for sw in Script.getUnprocessedSwitches():
        if sw[0] in ("V", "vo"):
            vo = sw[1]
        if sw[0] in ("D", "dry"):
            dry = True
        if sw[0] in ("C", "ce"):
            doCEs = True
        if sw[0] in ("H", "host"):
            hostURL = sw[1]
        if sw[0] in ("onecore",):
            onecore = True
Exemple #11
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        ("LFN:      LFN",
         "File:     File name containing a list of affected LFNs"))
    Script.registerArgument(" SE:       Name of Storage Element")
    Script.registerArgument(" Status:   New Status for the replica")
    Script.parseCommandLine(ignoreErrors=False)

    import DIRAC
    from DIRAC import gLogger
    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog
    import os

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    inputFileName, storageElement, status = Script.getPositionalArgs(
        group=True)

    if os.path.exists(inputFileName):
        inputFile = open(inputFileName, "r")
        string = inputFile.read()
        inputFile.close()
        lfns = sorted(string.splitlines())
    else:
        lfns = [inputFileName]

    fc = FileCatalog()

    res = fc.getReplicas(lfns, allStatus=True)
    if not res["OK"]:
        gLogger.error("Failed to get catalog replicas.", res["Message"])
        DIRAC.exit(-1)
    lfnDict = {}
    for lfn, error in res["Value"]["Failed"].items():
        gLogger.error("Failed to get replicas for file.",
                      "%s:%s" % (lfn, error))
    for lfn, replicas in res["Value"]["Successful"].items():
        if storageElement not in replicas.keys():
            gLogger.error("LFN not registered at provided storage element.",
                          "%s %s" % (lfn, storageElement))
        else:
            lfnDict[lfn] = {
                "SE": storageElement,
                "PFN": replicas[storageElement],
                "Status": status
            }
    if not lfnDict:
        gLogger.error("No files found at the supplied storage element.")
        DIRAC.exit(2)

    res = fc.setReplicaStatus(lfnDict)
    if not res["OK"]:
        gLogger.error("Failed to set catalog replica status.", res["Message"])
        DIRAC.exit(-1)
    for lfn, error in res["Value"]["Failed"].items():
        gLogger.error("Failed to set replica status for file.",
                      "%s:%s" % (lfn, error))
    gLogger.notice("Successfully updated the status of %d files at %s." %
                   (len(res["Value"]["Successful"].keys()), storageElement))
    DIRAC.exit(0)
    def registerSwitchesAndParseCommandLine(self):
        """Register the default plus additional parameters and parse options.

        :param list options: list of three tuple for options to add to the script
        :param list flags:  list of three tuple for flags to add to the script
        :param str opName
        """
        for short, longOption, doc in self.options:
            Script.registerSwitch(short + ":" if short else "",
                                  longOption + "=", doc)
        for short, longOption, doc in self.flags:
            Script.registerSwitch(short, longOption, doc)
            self.switches[longOption] = False
        Script.parseCommandLine()
        if Script.getPositionalArgs():
            Script.showHelp(exitCode=1)

        for switch in Script.getUnprocessedSwitches():
            for short, longOption, doc in self.options:
                if switch[0] == short or switch[0].lower() == longOption.lower(
                ):
                    sLog.verbose("Found switch %r with value %r" %
                                 (longOption, switch[1]))
                    self.switches[longOption] = switch[1]
                    break
            for short, longOption, doc in self.flags:
                if switch[0] == short or switch[0].lower() == longOption.lower(
                ):
                    self.switches[longOption] = True
                    break

        self.checkSwitches()
        self.switches["DryRun"] = not self.switches.get("Execute", False)
        self.switches["SourceSE"] = self.switches.get("SourceSE",
                                                      "").split(",")
Exemple #13
0
def main():
    Script.parseCommandLine(ignoreErrors=False)

    from DIRAC.TransformationSystem.Client.TransformationCLI import TransformationCLI

    cli = TransformationCLI()
    cli.cmdloop()
Exemple #14
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["LFN:      Logical File Name or file containing LFNs"])
    Script.parseCommandLine(ignoreErrors=True)
    lfns = Script.getPositionalArgs()

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

    from DIRAC.Interfaces.API.Dirac import Dirac

    dirac = Dirac()
    exitCode = 0

    if len(lfns) == 1:
        try:
            with open(lfns[0], "r") as f:
                lfns = f.read().splitlines()
        except Exception:
            pass

    result = dirac.getFile(lfns, printOutput=True)
    if not result["OK"]:
        print("ERROR %s" % (result["Message"]))
        exitCode = 2

    DIRAC.exit(exitCode)
Exemple #15
0
def main():
    Script.parseCommandLine()

    from DIRAC.ProductionSystem.Client.ProductionClient import ProductionClient

    prodClient = ProductionClient()
    res = prodClient.getProductions()

    fields = [
        "ProductionName", "Status", "ProductionID", "CreationDate",
        "LastUpdate", "AuthorDN", "AuthorGroup"
    ]
    records = []

    if res["OK"]:
        prodList = res["Value"]
        if not isinstance(res["Value"], list):
            prodList = [res["Value"]]
        for prod in prodList:
            records.append([
                str(prod["ProductionName"]),
                str(prod["Status"]),
                str(prod["ProductionID"]),
                str(prod["CreationDate"]),
                str(prod["LastUpdate"]),
                str(prod["AuthorDN"]),
                str(prod["AuthorGroup"]),
            ])
    else:
        DIRAC.gLogger.error(res["Message"])
        DIRAC.exit(-1)

    printTable(fields, records)

    DIRAC.exit(0)
Exemple #16
0
def main():
    Script.disableCS()
    Script.parseCommandLine()

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True
    gComponentInstaller.setupPortal()
Exemple #17
0
def main():
    Script.localCfg.addDefaultEntry("LogLevel", "info")
    Script.parseCommandLine()

    from DIRAC.AccountingSystem.Client.AccountingCLI import AccountingCLI

    acli = AccountingCLI()
    acli.start()
    def registerSwitchesAndParseCommandLine(self):
        """Register the default plus additional parameters and parse options.

        :param list options: list of three tuple for options to add to the script
        :param list flags:  list of three tuple for flags to add to the script
        :param str opName
        """
        for short, longOption, doc in self.options:
            Script.registerSwitch(short + ":" if short else "",
                                  longOption + "=", doc)
        for short, longOption, doc in self.flags:
            Script.registerSwitch(short, longOption, doc)
            self.switches[longOption] = False
        Script.parseCommandLine()
        if Script.getPositionalArgs():
            Script.showHelp(exitCode=1)

        ops = Operations()
        if not ops.getValue("DataManagement/ArchiveFiles/Enabled", False):
            sLog.error(
                'The "ArchiveFiles" operation is not enabled, contact your administrator!'
            )
            DIRAC.exit(1)
        for _short, longOption, _doc in self.options:
            defaultValue = ops.getValue(
                "DataManagement/ArchiveFiles/%s" % longOption, None)
            if defaultValue:
                sLog.verbose(
                    "Found default value in the CS for %r with value %r" %
                    (longOption, defaultValue))
                self.switches[longOption] = defaultValue
        for _short, longOption, _doc in self.flags:
            defaultValue = ops.getValue(
                "DataManagement/ArchiveFiles/%s" % longOption, False)
            if defaultValue:
                sLog.verbose(
                    "Found default value in the CS for %r with value %r" %
                    (longOption, defaultValue))
                self.switches[longOption] = defaultValue

        for switch in Script.getUnprocessedSwitches():
            for short, longOption, doc in self.options:
                if switch[0] == short or switch[0].lower() == longOption.lower(
                ):
                    sLog.verbose("Found switch %r with value %r" %
                                 (longOption, switch[1]))
                    self.switches[longOption] = switch[1]
                    break
            for short, longOption, doc in self.flags:
                if switch[0] == short or switch[0].lower() == longOption.lower(
                ):
                    self.switches[longOption] = True
                    break

        self.checkSwitches()
        self.switches["DryRun"] = not self.switches.get("Execute", False)
        self.switches["SourceSE"] = self.switches.get("SourceSE",
                                                      "").split(",")
Exemple #19
0
def main():
    global overwrite
    Script.registerSwitch("f", "force", "Force overwrite of existing file",
                          setOverwrite)
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if len(args) < 1 or len(args) > 4:
        Script.showHelp(exitCode=1)

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

    exitCode = 0

    lfns = []
    if len(args) == 1:
        inputFileName = args[0]
        if os.path.exists(inputFileName):
            inputFile = open(inputFileName, "r")
            for line in inputFile:
                line = line.rstrip()
                items = line.split()
                items[0] = items[0].replace("LFN:", "").replace("lfn:", "")
                lfns.append(getDict(items))
            inputFile.close()
        else:
            gLogger.error("Error: LFN list '%s' missing." % inputFileName)
            exitCode = 4
    else:
        lfns.append(getDict(args))

    dm = DataManager()
    for lfn in lfns:
        if not os.path.exists(lfn["localfile"]):
            gLogger.error("File %s must exist locally" % lfn["localfile"])
            exitCode = 1
            continue
        if not os.path.isfile(lfn["localfile"]):
            gLogger.error("%s is not a file" % lfn["localfile"])
            exitCode = 2
            continue

        gLogger.notice("\nUploading %s" % lfn["lfn"])
        res = dm.putAndRegister(lfn["lfn"],
                                lfn["localfile"],
                                lfn["SE"],
                                lfn["guid"],
                                overwrite=overwrite)
        if not res["OK"]:
            exitCode = 3
            gLogger.error("Error: failed to upload %s to %s: %s" %
                          (lfn["lfn"], lfn["SE"], res))
            continue
        else:
            gLogger.notice("Successfully uploaded file to %s" % lfn["SE"])

    DIRAC.exit(exitCode)
def main():
    Script.disableCS()

    Script.registerSwitch("t:", "type=",
                          "Installation type. 'server' by default.",
                          setInstallType)
    Script.parseCommandLine(ignoreErrors=True)

    # Collect all the requested python modules to install
    reqDict = {}
    for entry in os.listdir(rootPath):
        if len(entry) < 5 or entry.find("DIRAC") != len(entry) - 5:
            continue
        reqFile = os.path.join(rootPath, entry, "releases.cfg")
        try:
            with open(reqFile, "r") as extfd:
                reqCFG = CFG().loadFromBuffer(extfd.read())
        except Exception:
            gLogger.verbose("%s not found" % reqFile)
            continue
        reqList = reqCFG.getOption(
            "/RequiredExternals/%s" % instType.capitalize(), [])
        if not reqList:
            gLogger.verbose(
                "%s does not have requirements for %s installation" %
                (entry, instType))
            continue
        for req in reqList:
            reqName = False
            reqCond = ""
            for cond in ("==", ">="):
                iP = cond.find(req)
                if iP > 0:
                    reqName = req[:iP]
                    reqCond = req[iP:]
                    break
            if not reqName:
                reqName = req
            if reqName not in reqDict:
                reqDict[reqName] = (reqCond, entry)
            else:
                gLogger.notice("Skipping %s, it's already requested by %s" %
                               (reqName, reqDict[reqName][1]))

    if not reqDict:
        gLogger.notice("No extra python module requested to be installed")
        sys.exit(0)

    for reqName in reqDict:
        package = "%s%s" % (reqName, reqDict[reqName][0])
        gLogger.notice("Requesting installation of %s" % package)
        status, output = pipInstall(package)
        if status != 0:
            gLogger.error(output)
        else:
            gLogger.notice("Successfully installed %s" % package)
def main():
    Script.registerSwitch("N:", "NumberOfProcessors=", "Run n parallel copies of the benchmark")
    Script.registerSwitch("U", "Update", "Update dirac.cfg with the resulting value")
    Script.registerSwitch("R:", "Reconfig=", "Update given configuration file with the resulting value")
    Script.parseCommandLine(ignoreErrors=True)

    update = False
    configFile = None
    numberOfProcessors = 0

    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("U", "Update"):
            update = True
        elif unprocSw[0] in ("R", "Reconfig"):
            configFile = unprocSw[1]
        elif unprocSw[0] in ("N", "NumberOfProcessors"):
            try:
                numberOfProcessors = int(unprocSw[1])
            except ValueError:
                gLogger.warn("Cannot make benchmark measurements: NumberOfProcessors is not a number")

    # if numberOfProcessors has not been provided, try to get it from the configuration
    if not numberOfProcessors:
        numberOfProcessors = gConfig.getValue("/Resources/Computing/CEDefaults/NumberOfProcessors", 1)

    gLogger.info("Computing benchmark measurements on", "%d processor(s)..." % numberOfProcessors)

    # we want to get the logs coming from db12
    gLogger.enableLogsFromExternalLibs()
    # multiprocessor allocations generally have a CPU Power lower than single core one.
    # in order to avoid having wrong estimations, we run multiple copies of the benchmark simultaneously
    result = multipleDiracBenchmark(numberOfProcessors)

    if result is None:
        gLogger.error("Cannot make benchmark measurements")
        DIRAC.exit(1)

    # we take a conservative approach and use the minimum value returned as the CPU Power
    db12Result = min(result["raw"])
    # because hardware is continuously evolving, original benchmark scores might need a correction
    corr = Operations().getValue("JobScheduling/CPUNormalizationCorrection", 1.0)

    gLogger.info("Applying a correction on the CPU power:", corr)
    cpuPower = round(db12Result / corr, 1)

    gLogger.notice("Estimated CPU power is %.1f HS06" % cpuPower)

    if update:
        gConfig.setOptionValue("/LocalSite/CPUNormalizationFactor", cpuPower)

        if configFile:
            gConfig.dumpLocalCFGToFile(configFile)
        else:
            gConfig.dumpLocalCFGToFile(gConfig.diracConfigFilePath)

    DIRAC.exit()
Exemple #22
0
def main():
    cliParams = CLIParams()
    cliParams.registerCLISwitches()

    Script.parseCommandLine()

    retVal = uploadProxy(cliParams)
    if not retVal["OK"]:
        print(retVal["Message"])
        sys.exit(1)
    sys.exit(0)
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)
Exemple #24
0
def main():
    host = None
    Script.registerSwitch("H:", "host=", "   Target host")
    Script.parseCommandLine(ignoreErrors=False)
    for switch in Script.getUnprocessedSwitches():
        if switch[0].lower() == "h" or switch[0].lower() == "host":
            host = switch[1]

    from DIRAC.FrameworkSystem.Client.SystemAdministratorClientCLI import SystemAdministratorClientCLI

    cli = SystemAdministratorClientCLI(host)
    cli.cmdloop()
Exemple #25
0
def main():
    Script.registerSwitch("p:", "property=",
                          "Add property to the user <name>=<value>")
    Script.registerSwitch("f", "force", "create the user if it doesn't exist")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(" user:     User name")
    Script.registerArgument(" DN:       DN of the User")
    Script.registerArgument(["group:    Add the user to the group"])
    Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

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

    userProps = {}
    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("f", "force"):
            forceCreation = True
        elif unprocSw[0] in ("p", "property"):
            prop = unprocSw[1]
            pl = prop.split("=")
            if len(pl) < 2:
                errorList.append((
                    "in arguments",
                    "Property %s has to include a '=' to separate name from value"
                    % prop))
                exitCode = 255
            else:
                pName = pl[0]
                pValue = "=".join(pl[1:])
                print("Setting property %s to %s" % (pName, pValue))
                userProps[pName] = pValue

    userName, userProps["DN"], userProps["Groups"] = Script.getPositionalArgs(
        group=True)

    if not diracAdmin.csModifyUser(
            userName, userProps, createIfNonExistant=forceCreation):
        errorList.append(("modify user", "Cannot modify user %s" % userName))
        exitCode = 255
    else:
        result = diracAdmin.csCommitChanges()
        if not result["OK"]:
            errorList.append(("commit", result["Message"]))
            exitCode = 255

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

    DIRAC.exit(exitCode)
Exemple #26
0
def main():
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs",
                             "LFN:       Logical File Names"))
    Script.parseCommandLine()

    from DIRAC.ConfigurationSystem.Client.Helpers.Operations import Operations

    allowUsers = Operations().getValue(
        "DataManagement/AllowUserReplicaManagement", False)

    from DIRAC.Core.Security.ProxyInfo import getProxyInfo

    res = getProxyInfo()
    if not res["OK"]:
        gLogger.fatal("Can't get proxy info", res["Message"])
        dexit(1)
    properties = res["Value"].get("groupProperties", [])

    if not allowUsers:
        if "FileCatalogManagement" not in properties:
            gLogger.error(
                "You need to use a proxy from a group with FileCatalogManagement"
            )
            dexit(5)

    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    fc = FileCatalog()
    import os

    # parseCommandLine show help when mandatory arguments are not specified or incorrect argument
    args = Script.getPositionalArgs()

    inputFileName = args[0]

    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 = fc.removeFile(lfns)
    if not res["OK"]:
        print("Error:", res["Message"])
        dexit(1)
    for lfn in sorted(res["Value"]["Failed"].keys()):
        message = res["Value"]["Failed"][lfn]
        print("Error: failed to remove %s: %s" % (lfn, message))
    print("Successfully removed %d catalog files." %
          (len(res["Value"]["Successful"])))
def run():
    """
    main program entry point
    """
    options = Params()
    options.registerCLISwitches()

    Script.parseCommandLine(ignoreErrors=True)

    if options.delete_all and options.vos:
        gLogger.error("-a and -v options are mutually exclusive. Please pick one or the other.")
        return 1

    proxyLoc = Locations.getDefaultProxyLocation()

    if not os.path.exists(proxyLoc):
        gLogger.error("No local proxy found in %s, exiting." % proxyLoc)
        return 1

    result = ProxyInfo.getProxyInfo(proxyLoc, True)
    if not result["OK"]:
        raise RuntimeError("Failed to get local proxy info.")

    if result["Value"]["secondsLeft"] < 60 and options.needsValidProxy():
        raise RuntimeError("Lifetime of local proxy too short, please renew proxy.")

    userDN = result["Value"]["identity"]

    if options.delete_all:
        # delete remote proxies
        remote_groups = getProxyGroups()
        if not remote_groups:
            gLogger.notice("No remote proxies found.")
        for vo_group in remote_groups:
            deleteRemoteProxy(userDN, vo_group)
        # delete local proxy
        deleteLocalProxy(proxyLoc)
    elif options.vos:
        vo_groups = set()
        for voname in options.vos:
            vo_groups.update(mapVoToGroups(voname))
        # filter set of all groups to only contain groups for which there is a user proxy
        user_groups = getProxyGroups()
        vo_groups.intersection_update(user_groups)
        if not vo_groups:
            gLogger.notice("You have no proxies registered for any of the specified VOs.")
        for group in vo_groups:
            deleteRemoteProxy(userDN, group)
    else:
        deleteLocalProxy(proxyLoc)

    return 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)
Exemple #29
0
def parseSwitches():
    """
    Parses the arguments passed by the user
    """

    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs()
    if len(args) < 3:
        error(
            "Missing all mandatory 'query', 'element', 'tableType' arguments")
    elif args[0].lower() not in ("select", "add", "modify", "delete"):
        error("Incorrect 'query' argument")
    elif args[1].lower() not in ("site", "resource", "component", "node"):
        error("Incorrect 'element' argument")
    elif args[2].lower() not in ("status", "log", "history"):
        error("Incorrect 'tableType' argument")
    else:
        query = args[0].lower()

    switches = dict(Script.getUnprocessedSwitches())

    # Default values
    switches.setdefault("name", None)
    switches.setdefault("statusType", None)
    switches.setdefault("status", None)
    switches.setdefault("elementType", None)
    switches.setdefault("reason", None)
    switches.setdefault("lastCheckTime", None)
    switches.setdefault("tokenOwner", None)
    switches.setdefault("VO", None)

    if "status" in switches and switches["status"] is not None:
        switches["status"] = switches["status"].title()
        if switches["status"] not in ("Active", "Probing", "Degraded",
                                      "Banned", "Unknown", "Error"):
            error("'%s' is an invalid argument for switch 'status'" %
                  switches["status"])

    # when it's a add/modify query and status/reason/statusType are not specified
    # then some specific defaults are set up
    if query == "add" or query == "modify":
        if "status" not in switches or switches["status"] is None:
            switches["status"] = "Unknown"
        if "reason" not in switches or switches["reason"] is None:
            switches["reason"] = "Unknown reason"
        if "statusType" not in switches or switches["statusType"] is None:
            switches["statusType"] = "all"

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

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

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()

    result = diracAdmin.getPilotSummary()
    if result["OK"]:
        DIRAC.exit(0)
    else:
        print(result["Message"])
        DIRAC.exit(2)