예제 #1
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)
예제 #2
0
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)
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)
예제 #4
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
예제 #5
0
def registerSwitches():
    """
    Registers all switches that can be used while calling the script from the
    command line interface.
    """

    switches = (
        ("element=",
         "Element family to be Synchronized ( Site, Resource, Node )"),
        ("tableType=", "A valid table type (Status, Log, History)"),
        ("name=",
         "ElementName (comma separated list allowed); None if default"),
        (
            "statusType=",
            "A valid StatusType argument (it admits a comma-separated list of statusTypes); None if default",
        ),
        ("status=",
         "A valid Status argument ( Active, Probing, Degraded, Banned, Unknown, Error ); None if default"
         ),
        ("elementType=", "ElementType narrows the search; None if default"),
        ("reason=", "Decision that triggered the assigned status"),
        ("lastCheckTime=",
         "Time-stamp setting last time the status & status were checked"),
        ("tokenOwner=",
         "Owner of the token ( to specify only with select/delete queries"),
        ("VO=", "Virtual organisation; None if default"),
    )

    for switch in switches:
        Script.registerSwitch("", switch[0], switch[1])
예제 #6
0
def main():
    original = False
    Script.registerSwitch("O", "Original", "Gets the original JDL")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    for switch in sws:
        if switch[0] == "Original" or switch[0] == "O":
            original = True

    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0
    errorList = []

    for job in parseArguments(args):

        result = dirac.getJobJDL(job, original=original, printOutput=True)
        if not result["OK"]:
            errorList.append((job, result["Message"]))
            exitCode = 2

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

    DIRAC.exit(exitCode)
예제 #7
0
def main():
    Script.registerSwitch("D:", "Dir=", "Store the output in this directory")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JobID:    DIRAC Job ID"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.Dirac import Dirac, parseArguments

    dirac = Dirac()
    exitCode = 0
    errorList = []

    outputDir = ""
    for sw, v in sws:
        if sw in ("D", "Dir"):
            outputDir = v

    for job in parseArguments(args):

        result = dirac.getJobOutputData(job, destinationDir=outputDir)
        if result["OK"]:
            print("Job %s output data retrieved" % (job))
        else:
            errorList.append((job, result["Message"]))
            exitCode = 2

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

    DIRAC.exit(exitCode)
    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(",")
def main():
    Script.registerSwitch(
        "", "Site=", "Site for which protocols are to be set (mandatory)")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["Protocol: SE access protocol"], mandatory=False)
    switches, args = Script.parseCommandLine(ignoreErrors=True)

    site = None
    for switch in switches:
        if switch[0].lower() == "site":
            site = switch[1]

    if not site or not args:
        Script.showHelp(exitCode=1)

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

    diracAdmin = DiracAdmin()
    exitCode = 0
    result = diracAdmin.setSiteProtocols(site, args, printOutput=True)
    if not result["OK"]:
        print("ERROR: %s" % result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
예제 #10
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)
예제 #11
0
def main():
    Script.registerSwitch("a", "All", "  Also show inactive replicas")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        ["LFN:      Logical File Name or file containing LFNs"])
    switches, lfns = Script.parseCommandLine(ignoreErrors=True)

    active = True
    for switch in switches:
        opt = switch[0].lower()
        if opt in ("a", "all"):
            active = False

    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.getReplicas(lfns, active=active, printOutput=True)
    if not result["OK"]:
        print("ERROR: ", result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
예제 #12
0
 def registerCLISwitches(self):
     """
     add options to dirac option parser
     """
     Script.registerSwitch(
         "a", "all", "Delete the local and all uploaded proxies (the nuclear option)", self.setDeleteAll
     )
     Script.registerSwitch("v:", "vo=", "Delete uploaded proxy for vo name given", self.addVO)
예제 #13
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 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(",")
예제 #15
0
def main():
    unit = "GB"
    Script.registerSwitch("u:", "Unit=",
                          "   Unit to use [default %s] (MB,GB,TB,PB)" % unit)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(("LocalFile: Path to local file containing LFNs",
                             "LFN:       Logical File Name"))
    Script.registerArgument(["LFN:       Logical File Name"], mandatory=False)
    unprSwitches, args = Script.parseCommandLine(ignoreErrors=False)

    for switch in unprSwitches:
        if switch[0].lower() == "u" or switch[0].lower() == "unit":
            unit = switch[1]
    scaleDict = {
        "MB": 1000 * 1000.0,
        "GB": 1000 * 1000 * 1000.0,
        "TB": 1000 * 1000 * 1000 * 1000.0,
        "PB": 1000 * 1000 * 1000 * 1000 * 1000.0,
    }
    if unit not in scaleDict.keys():
        gLogger.error("Unit must be one of MB,GB,TB,PB")
        DIRAC.exit(2)
    scaleFactor = scaleDict[unit]

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

    from DIRAC.Resources.Catalog.FileCatalog import FileCatalog

    res = FileCatalog().getFileSize(lfns)
    if not res["OK"]:
        gLogger.error("Failed to get size of data", res["Message"])
        DIRAC.exit(-2)
    for lfn, reason in res["Value"]["Failed"].items():
        gLogger.error("Failed to get size for %s" % lfn, reason)
    totalSize = 0
    totalFiles = 0
    for lfn, size in res["Value"]["Successful"].items():
        totalFiles += 1
        totalSize += size
    gLogger.notice("-" * 30)
    gLogger.notice("%s|%s" % ("Files".ljust(15),
                              ("Size (%s)" % unit).rjust(15)))
    gLogger.notice("-" * 30)
    gLogger.notice(
        "%s|%s" %
        (str(totalFiles).ljust(15), str("%.1f" %
                                        (totalSize / scaleFactor)).rjust(15)))
    gLogger.notice("-" * 30)
    DIRAC.exit(0)
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)
예제 #17
0
def main():
    Script.registerSwitch("f:", "File=", "Writes job ids to file <value>")
    Script.registerSwitch("r:", "UseJobRepo=", "Use the job repository")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["JDL:    Path to JDL file"])
    sws, args = Script.parseCommandLine(ignoreErrors=True)

    from DIRAC.Interfaces.API.Dirac import Dirac

    unprocessed_switches = sws
    use_repo = False
    repo_name = ""
    for sw, value in unprocessed_switches:
        if sw.lower() in ["r", "usejobrepo"]:
            use_repo = True
            repo_name = value
            repo_name = repo_name.replace(".cfg", ".repo")
    dirac = Dirac(use_repo, repo_name)
    exitCode = 0
    errorList = []

    jFile = None
    for sw, value in unprocessed_switches:
        if sw.lower() in ("f", "file"):
            if os.path.isfile(value):
                print("Appending job ids to existing logfile: %s" % value)
                if not os.access(value, os.W_OK):
                    print("Existing logfile %s must be writable by user." %
                          value)
            jFile = open(value, "a")

    for jdl in args:

        result = dirac.submitJob(jdl)
        if result["OK"]:
            print("JobID = %s" % (result["Value"]))
            if jFile is not None:
                # parametric jobs
                if isinstance(result["Value"], list):
                    jFile.write("\n".join(str(p) for p in result["Value"]))
                    jFile.write("\n")
                else:
                    jFile.write(str(result["Value"]) + "\n")
        else:
            errorList.append((jdl, result["Message"]))
            exitCode = 2

    if jFile is not None:
        jFile.close()

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

    DIRAC.exit(exitCode)
예제 #18
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()
예제 #19
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)
예제 #20
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)
예제 #21
0
def main():
    Script.registerSwitch("e", "extended", "Show extended info")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(["Group:    Only users from this group (default: all)"], default=["all"], mandatory=False)
    Script.parseCommandLine(ignoreErrors=True)
    args = Script.getPositionalArgs(group=True)

    import DIRAC
    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

    def printUsersInGroup(group=False):
        result = diracAdmin.csListUsers(group)
        if result["OK"]:
            if group:
                print("Users in group %s:" % group)
            else:
                print("All users registered:")
            for username in result["Value"]:
                print(" %s" % username)

    def describeUsersInGroup(group=False):
        result = diracAdmin.csListUsers(group)
        if result["OK"]:
            if group:
                print("Users in group %s:" % group)
            else:
                print("All users registered:")
            result = diracAdmin.csDescribeUsers(result["Value"])
            print(diracAdmin.pPrint.pformat(result["Value"]))

    for group in args:
        if "all" in args:
            group = False
        if not extendedInfo:
            printUsersInGroup(group)
        else:
            describeUsersInGroup(group)

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

    DIRAC.exit(exitCode)
예제 #22
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)
예제 #23
0
def main():
    Script.registerSwitch("f:", "File=",
                          "Get output for jobs with IDs from the file")
    Script.registerSwitch("g:", "JobGroup=",
                          "Get output 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)

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

    dirac = Dirac()

    jobs = []
    for sw, value in sws:
        if sw.lower() in ("f", "file"):
            if os.path.exists(value):
                jFile = open(value)
                jobs += jFile.read().split()
                jFile.close()
        elif sw.lower() in ("g", "jobgroup"):
            group = value
            jobDate = toString(date() - 30 * day)
            result = dirac.selectJobs(jobGroup=value, date=jobDate)
            if not result["OK"]:
                if "No jobs selected" not in result["Message"]:
                    print("Error:", result["Message"])
                    DIRAC.exit(-1)
            else:
                jobs += result["Value"]

    for arg in parseArguments(args):
        jobs.append(arg)

    if not jobs:
        print("Warning: no jobs selected")
        Script.showHelp()
        DIRAC.exit(0)

    result = dirac.deleteJob(jobs)
    if result["OK"]:
        print("Deleted jobs %s" % ",".join([str(j) for j in result["Value"]]))
        exitCode = 0
    else:
        print(result["Message"])
        exitCode = 2

    DIRAC.exit(exitCode)
예제 #24
0
def main():
    Script.registerSwitch("C:", "CPUNormalizationFactor=",
                          "CPUNormalizationFactor, in case it is known")
    Script.parseCommandLine(ignoreErrors=True)

    CPUNormalizationFactor = 0.0
    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("C", "CPUNormalizationFactor"):
            CPUNormalizationFactor = float(unprocSw[1])

    from DIRAC.WorkloadManagementSystem.Client.CPUNormalization import getCPUTime

    cpuTime = getCPUTime(CPUNormalizationFactor)
    # I hate this kind of output... PhC
    print("CPU time left determined as", cpuTime)
    DIRAC.exit(0)
예제 #25
0
 def registerCLISwitches(self):
     """Register CLI switches"""
     Script.registerSwitch(
         "v:", "valid=",
         "Valid HH:MM for the proxy. By default is 24 hours",
         self.setProxyLifeTime)
     Script.registerSwitch("l", "limited", "Get a limited proxy",
                           self.setLimited)
     Script.registerSwitch("u:", "out=", "File to write as proxy",
                           self.setProxyLocation)
     Script.registerSwitch(
         "a", "voms",
         "Get proxy with VOMS extension mapped to the DIRAC group",
         self.automaticVOMS)
     Script.registerSwitch("m:", "vomsAttr=", "VOMS attribute to require",
                           self.setVOMSAttr)
예제 #26
0
def main():
    global listOfFailedFiles

    Script.registerSwitch("D", "sync", "Make target directory identical to source")
    Script.registerSwitch("j:", "parallel=", "Multithreaded download and upload")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        (
            "LFN:           Logical File Name (Path to directory)",
            "Path:          Local path to the file (Path to directory)",
        )
    )
    Script.registerArgument(
        (
            "Path:          Local path to the file (Path to directory)",
            "LFN:           Logical File Name (Path to directory)",
        )
    )
    Script.registerArgument(" SE:            DIRAC Storage Element", mandatory=False)
    Script.parseCommandLine(ignoreErrors=False)

    args = Script.getPositionalArgs()
    if len(args) > 3:
        Script.showHelp()

    sync = False
    parallel = 1
    for switch in Script.getUnprocessedSwitches():
        if switch[0].lower() == "s" or switch[0].lower() == "sync":
            sync = True
        if switch[0].lower() == "j" or switch[0].lower() == "parallel":
            parallel = int(switch[1])

    listOfFailedFiles = Manager().list()

    # This is the execution
    returnValue = run(args, sync, parallel)
    if listOfFailedFiles:
        gLogger.error("Some file operations failed:\n\t", "\n\t".join(listOfFailedFiles))
        DIRAC.exit(1)
    if not returnValue["OK"]:
        gLogger.fatal(returnValue["Message"])
        DIRAC.exit(1)
    else:
        gLogger.notice(returnValue["Value"])
        DIRAC.exit(0)
예제 #27
0
def registerSwitches():
    """
    Registers all switches that can be used while calling the script from the
    command line interface.
    """

    switches = (
        ("element=",
         "Element family to be Synchronized ( Site, Resource or Node )"),
        ("elementType=", "ElementType narrows the search; None if default"),
        ("name=", "ElementName; None if default"),
        ("tokenOwner=", "Owner of the token; None if default"),
        ("statusType=", "StatusType; None if default"),
        ("status=", "Status; None if default"),
        ("VO=", "Virtual organisation; None if default"),
    )

    for switch in switches:
        Script.registerSwitch("", switch[0], switch[1])
예제 #28
0
def main():
    Script.registerSwitch("t", "test", "Only test. Don't commit changes")
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument(
        "UserCfg:  Cfg FileName with Users as sections containing"
        "DN, Groups, and other properties as options")
    Script.parseCommandLine(ignoreErrors=True)

    args = Script.getExtraCLICFGFiles()

    from DIRAC.Interfaces.API.DiracAdmin import DiracAdmin

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

    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("t", "test"):
            testOnly = True

    try:
        usersCFG = CFG().loadFromFile(args[0])
    except Exception as e:
        errorList.append("file open",
                         "Can't parse file %s: %s" % (args[0], str(e)))
        errorCode = 1
    else:
        if not diracAdmin.csSyncUsersWithCFG(usersCFG):
            errorList.append(("modify users", "Cannot sync with %s" % args[0]))
            exitCode = 255

    if not exitCode and not testOnly:
        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)
예제 #29
0
def registerSwitches():
    """
    Registers all switches that can be used while calling the script from the
    command line interface.
    """

    switches = (
        ("downtimeID=", "ID of the downtime"),
        ("element=", "Element (Site, Service) affected by the downtime"),
        ("name=", "Name of the element"),
        ("startDate=", "Starting date of the downtime"),
        ("endDate=", "Ending date of the downtime"),
        ("severity=", "Severity of the downtime (Warning, Outage)"),
        ("description=", "Description of the downtime"),
        ("link=", "URL of the downtime announcement"),
        ("ongoing", 'To force "select" to return the ongoing downtimes'),
    )

    for switch in switches:
        Script.registerSwitch("", switch[0], switch[1])
예제 #30
0
def main():
    # Instantiate the params class
    cliParams = Params()

    # Register accepted switches and their callbacks
    Script.registerSwitch("r", "showRaw", "show raw result from the query",
                          cliParams.setRawResult)
    Script.registerSwitch("p:", "numPings=",
                          "Number of pings to do (by default 1)",
                          cliParams.setNumOfPingsToDo)
    Script.registerArgument(["System: system names"])

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

    # Get the list of services
    servicesList = Script.getPositionalArgs()

    # Do something!
    gLogger.notice("Ping %s!" % ", ".join(servicesList))