예제 #1
0
 def getReadWriteDiskTemplates(self, workflow=None, vardict = {}):
     if workflow==None: workflow = self.getWorkflowTemplate()
     image = self.getImage()
     user = self.getUser()
     disk = DiskTemplate.findByName(SESSION, "test_read_write_disk_template", user)
     if disk == None:
         disk = DiskTemplate("test_read_write_disk_template", workflow, image, 100, "pd-standard", "us-central1-a")
     disk.updateVarDict(vardict, disk.workflow.user)
     return [disk]
예제 #2
0
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
예제 #3
0
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