From 98396240cd8bb0229294169f4c2f456d38c8d5dc Mon Sep 17 00:00:00 2001 From: Evan Shi <14984764+evanyeyeye@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:26:41 -0500 Subject: [PATCH] linting --- config.template.py | 4 ++++ restful_tango/tangoREST.py | 24 +++++++++--------------- vmms/localDocker.py | 6 ++++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/config.template.py b/config.template.py index 091fb3c8..400e51cd 100644 --- a/config.template.py +++ b/config.template.py @@ -86,6 +86,10 @@ class Config(object): DOCKER_RM_TIMEOUT = 5 DOCKER_HOST_USER = "" + # Docker autograding container resource limits + DOCKER_CORES_LIMIT = None + DOCKER_MEMORY_LIMIT = None # in MB + # Maximum size for input files in bytes MAX_INPUT_FILE_SIZE = 10 * 1024 * 1024 * 1024 # 10GB diff --git a/restful_tango/tangoREST.py b/restful_tango/tangoREST.py index f4d92f4d..c8840c63 100644 --- a/restful_tango/tangoREST.py +++ b/restful_tango/tangoREST.py @@ -111,16 +111,19 @@ def checkFileExists(self, directory, filename, fileMD5): except IOError: continue - def createTangoMachine( - self, image, vmms=Config.VMMS_NAME, vmObj={"cores": 1, "memory": 512} - ): + def createTangoMachine(self, image, vmms=Config.VMMS_NAME, vmObj=None): """createTangoMachine - Creates a tango machine object from image""" + cores = Config.DOCKER_CORES_LIMIT + memory = Config.DOCKER_MEMORY_LIMIT + if vmObj and "cores" in vmObj and "memory" in vmObj: + cores = vmObj["cores"] + memory = vmObj["memory"] return TangoMachine( name=image, vmms=vmms, image="%s" % (image), - cores=vmObj["cores"], - memory=vmObj["memory"], + cores=cores, + memory=memory, disk=None, network=None, ) @@ -153,16 +156,7 @@ def convertJobObj(self, dirName, jobObj): input.append(handinfile) # VM object - if "cores" in jobObj and "memory" in jobObj: - vm = self.createTangoMachine( - jobObj["image"], - vmObj={ - "cores": jobObj["cores"], - "memory": jobObj["memory"], - }, - ) - else: - vm = self.createTangoMachine(jobObj["image"]) + vm = self.createTangoMachine(jobObj["image"]) # for backward compatibility accessKeyId = None diff --git a/vmms/localDocker.py b/vmms/localDocker.py index 51fa5377..6557237b 100644 --- a/vmms/localDocker.py +++ b/vmms/localDocker.py @@ -157,8 +157,10 @@ def runJob(self, vm, runTimeout, maxOutputFileSize): ) args = ["docker", "run", "--name", instanceName, "-v"] args = args + ["%s:%s" % (volumePath, "/home/mount")] - args = args + [f"--cpus={vm.cores}"] - args = args + ["-m", f"{vm.memory}m"] + if vm.cores: + args = args + [f"--cpus={vm.cores}"] + if vm.memory: + args = args + ["-m", f"{vm.memory}m"] args = args + [vm.image] args = args + ["sh", "-c"]