コード例 #1
0
ファイル: WebApp.py プロジェクト: collinmelton/DDCloudServer
def newWorkflow(user, data, new, delete):
    if delete:
        wfid = getID(request.form["workflowWorkflowsSelect"])
        WorkflowTemplate.delete(SESSION, wfid, user)
        result = {"updates": {}, "message": "deleted workflow"}
    elif new:
        credID = getID(data["workflowCredentialsSelect"])
        if credID == None:
            credentials = None
        else:
            credentials = Credentials.findByID(SESSION, credID, user)
        nwf = WorkflowTemplate(data["newWorkflowName"], user, credentials=credentials)
        SESSION.add(nwf)
        SESSION.commit()
        result = {"updates": {"workflows": {str(nwf.id): nwf.dictForJSON()}}, "message": "added new workflow"}
    else:
        wfid = getID(request.form["workflowVarWorkflowsSelect"])
        wf = WorkflowTemplate.findByID(SESSION, wfid, user)
        if VERBOSE:
            print user.name, user.id
        if wf == None:
            return {"updates": {}, "message": "user permissions error"}
        newvars = parseVariables(request.form)
        wf.updateVarDict(newvars, user)
        result = {"updates": {"workflows": {str(wf.id): wf.dictForJSON()}}, "message": "updated workflow"}
    return result
コード例 #2
0
 def getWorkflowTemplate(self, vardict = {}):
     user = self.getUser()
     cred = self.getCredentials(user)
     wft = WorkflowTemplate.findByName(SESSION, "test_workflow_template", user)
     if wft==None:
         wft = WorkflowTemplate("test_workflow_template", user, workflowVars={"$1":"collin"}, credentials = cred)
     wft.updateVarDict(vardict, user)
     return wft
コード例 #3
0
ファイル: WebApp.py プロジェクト: collinmelton/DDCloudServer
def saveDisk(user, data, variables, delete):
    if delete:
        diskID = getID(data["diskDisksSelect"])
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["diskWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error on workflow"}
        if diskID != None:
            DiskTemplate.delete(SESSION, diskID, user)
    elif variables:
        diskID = getID(data["diskVarDisksSelect"])
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["diskVarWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error on workflow"}
        disk = DiskTemplate.findByID(SESSION, diskID, user)
        if disk == None:
            return {"updates": {}, "message": "user permissions error on disk"}
        disk.updateVarDict(parseVariables(data), user)
    else:
        diskID = getID(data["diskDisksSelect"])
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["diskWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error on workflow"}
        name = data["diskName"]
        if getID(data["diskImagesSelect"]) == "0":
            image = None
        else:
            image = Image.findByID(SESSION, getID(data["diskImagesSelect"]), user)
            if image == None:
                return {"updates": {}, "message": "user permissions error on image"}
        diskSize = data["diskSize"]
        diskType = data["diskTypeSelector"]
        location = data["diskLocationSelector"]
        if VERBOSE:
            print "diskID", diskID
        if diskID == None:
            disk = DiskTemplate(name.lower(), workflow, image, diskSize, diskType, location)
        else:
            disk = DiskTemplate.findByID(SESSION, diskID, user)
            if disk != None:
                disk.updateValues(name.lower(), workflow, image, diskSize, diskType, location, user)
            else:
                return {"updates": {}, "message": "user permissions error on disk"}
    #                 disk = DiskTemplate(name, workflow, image, diskSize, diskType, location)
    SESSION.add(workflow)
    SESSION.commit()
    result = {"updates": {"workflows": {str(workflow.id): workflow.dictForJSON()}}, "message": "updated disk"}
    return result
コード例 #4
0
ファイル: WebApp.py プロジェクト: collinmelton/DDCloudServer
def workflowLauncher(user, data, stop):
    if stop:
        wfid = getID(request.form["activeWorkflowSelect"])
    else:
        wfid = getID(request.form["launcherWorkflowSelect"])
        workflowname = request.form["launcherWorkflowRunName"]
        print workflowname
    if VERBOSE:
        print "finding workflow"
    wf = WorkflowTemplate.findByID(SESSION, wfid, user)
    if VERBOSE:
        print "found workflow"
    if wf == None:
        return {"updates": {}, "message": "user permissions error for workflow"}
    if not stop:
        if VERBOSE:
            print os.path.join(app.config["LOGFILEDIRECTORY"], user.name)
        if VERBOSE:
            print getTimeStampedFile(wf.name)
        if VERBOSE:
            print os.path.join(
                ensureDirectoryExists(os.path.join(app.config["LOGFILEDIRECTORY"], user.name)),
                getTimeStampedFile(wf.name),
            )
        logfilename = os.path.join(
            ensureDirectoryExists(os.path.join(app.config["LOGFILEDIRECTORY"], user.name)), getTimeStampedFile(wf.name)
        )
        if VERBOSE:
            print logfilename
        address = request.url_root
        if VERBOSE:
            print address
        #         wf.startWorkflow(SESSION, logfilename, address, workflowname)
        celeryStartWorkflow.delay(wfid, logfilename, address, workflowname)
    else:
        if VERBOSE:
            print "stopping workflow"
        celeryStopWorkflow.delay(wfid)
    #         wf.stopWorkflow(SESSION)
    return {"updates": {"active_workflows": user.getActiveWorkflows()}, "message": "started workflow"}
コード例 #5
0
ファイル: WebApp.py プロジェクト: collinmelton/DDCloudServer
def saveCommand(user, data, delete):
    workflow = WorkflowTemplate.findByID(SESSION, getID(data["workflowInCommandForm"]), user)
    if workflow == None:
        return {"updates": {}, "message": "user permissions error on workflow"}
    if delete:
        cid = getID(data["commandInCommandForm"])
        if cid != None:
            CommandTemplate.delete(SESSION, cid, user)
    else:
        instance = InstanceTemplate.findByID(SESSION, getID(data["instanceInCommandForm"]), user)
        if instance == None:
            return {"updates": {}, "message": "user permissions error on instance"}
        name = data["CommandName"]
        commandText = data["Command"]
        commandID = getID(data["commandInCommandForm"])
        dependencies = [
            CommandTemplate.findByID(SESSION, cid, user)
            for cid in list(set([getID(idname) for idname in data.getlist("commandDependenciesSelect")]))
        ]
        if None in dependencies:
            return {"updates": {}, "message": "user permissions error on command dependencies"}
        ## edit old command or make new command
        if commandID != None:
            command = CommandTemplate.findByID(SESSION, commandID, user)
            if command == None:
                return {"updates": {}, "message": "user permissions error on command"}
            command.updateValues(instance, name.lower(), commandText, dependencies)
        else:
            command = CommandTemplate(instance, name.lower(), commandText, dependencies)
            SESSION.add(command)
            SESSION.commit()

    result = {"updates": {"workflows": {str(workflow.id): workflow.dictForJSON()}}, "message": "updated command"}
    SESSION.add(workflow)
    SESSION.commit()
    return result
コード例 #6
0
ファイル: WebApp.py プロジェクト: collinmelton/DDCloudServer
def saveInstance(user, data, variables, delete):
    if delete:
        if VERBOSE:
            print "deleting"
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["instanceWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error on workflow"}
        iid = getID(data["instanceInstancesSelect"])
        if iid != None:
            if VERBOSE:
                print iid
            InstanceTemplate.delete(SESSION, iid, user)
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["instanceWorkflowsSelect"]), user)
    elif variables:
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["instanceVarWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error"}
        if VERBOSE:
            print "got workflow"
        instID = getID(data["instanceVarInstancesSelect"])
        if instID == None:
            return {"updates": {}, "message": "instance id error"}
        instance = InstanceTemplate.findByID(SESSION, instID, user)
        if VERBOSE:
            print "got instance"
        if instance == None:
            return {"updates": {}, "message": "user permissions error"}
        instance.updateVarDict(parseVariables(data), user)
        if VERBOSE:
            print "updated vars"
    else:
        workflow = WorkflowTemplate.findByID(SESSION, getID(data["instanceWorkflowsSelect"]), user)
        if workflow == None:
            return {"updates": {}, "message": "user permissions error on workflow"}
        name = data["instanceName"]
        machineType = data["instanceMachineTypeSelector"]
        location = data["instanceLocationSelector"]
        bootDisk = DiskTemplate.findByID(SESSION, getID(data["instanceBootDiskSelect"]), user)
        if bootDisk == None:
            return {"updates": {}, "message": "user permissions error on boot disk"}
        readDisks = [
            DiskTemplate.findByID(SESSION, did, user)
            for did in list(set([getID(idname) for idname in data.getlist("instanceReadDisksSelect")]))
        ]
        if None in readDisks:
            return {"updates": {}, "message": "user permissions error on read disks"}
        readWriteDisks = [
            DiskTemplate.findByID(SESSION, did, user)
            for did in list(set([getID(idname) for idname in data.getlist("instanceReadWriteDisksSelect")]))
        ]
        if None in readWriteDisks:
            return {"updates": {}, "message": "user permissions error on read/write disks"}
        instID = getID(data["instanceInstancesSelect"])
        dependencies = [
            InstanceTemplate.findByID(SESSION, iid, user)
            for iid in list(set([getID(idname) for idname in data.getlist("instanceDependenciesSelect")]))
        ]
        if None in dependencies:
            return {"updates": {}, "message": "user permissions error on instance dependencies"}
        if VERBOSE:
            print "test"
        ex_tags = data["ex_tags"]
        if VERBOSE:
            print ex_tags
        ex_metadata = data["ex_metadata"]
        if VERBOSE:
            print ex_metadata
        ex_network = data["ex_network"]
        if VERBOSE:
            print ex_network
        numLocalSSD = data["numLocalSSD"]
        if VERBOSE:
            print numLocalSSD
        if "preemptible" not in data:
            preemptible = False
        else:
            preemptible = data["preemptible"] == "T"
        if VERBOSE:
            print preemptible
        ## edit old instance or make new instance
        if instID != None:
            if VERBOSE:
                print "updating instance"
            instance = InstanceTemplate.findByID(SESSION, instID, user)
            if instance == None:
                #                 instance = InstanceTemplate(name, machineType, location, bootDisk, readDisks,
                #                                         readWriteDisks, dependencies, workflow)
                return {"updates": {}, "message": "user permissions error on instance"}
            instance.updateValues(
                name.lower(),
                machineType,
                location,
                bootDisk,
                readDisks,
                readWriteDisks,
                dependencies,
                ex_tags,
                ex_metadata,
                ex_network,
                numLocalSSD,
                preemptible,
            )
        else:
            if VERBOSE:
                print "adding instance"
            instance = InstanceTemplate(
                name.lower(),
                machineType,
                location,
                bootDisk,
                readDisks,
                readWriteDisks,
                dependencies,
                workflow,
                ex_tags,
                ex_metadata,
                ex_network,
                numLocalSSD,
                preemptible,
            )
    SESSION.add(workflow)
    SESSION.commit()
    result = {"updates": {"workflows": {str(workflow.id): workflow.dictForJSON()}}, "message": "updated instance"}
    return result
コード例 #7
0
def stopWorkflow(wfid):
    wft = WorkflowTemplate.findByID(SESSION, wfid)
    return wft.stopWorkflow(SESSION)
コード例 #8
0
def startWorkflow(wfid, logfilename, address, workflowname):
    wft = WorkflowTemplate.findByID(SESSION, wfid)
    return wft.startWorkflow(SESSION, logfilename, address, workflowname)