From 60fa6cc156c02794c74eb75d49abf7c3000f4e16 Mon Sep 17 00:00:00 2001 From: Firmlyzhu Date: Wed, 3 Apr 2019 17:18:10 +0800 Subject: [PATCH] add mount to task --- src/master/taskmgr.py | 9 +++++-- src/worker/ossmounter.py | 4 +-- src/worker/taskworker.py | 5 ++-- web/templates/batch/batch_create.html | 39 +++++++++++++++------------ 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/master/taskmgr.py b/src/master/taskmgr.py index 3e7d06d..f56f394 100644 --- a/src/master/taskmgr.py +++ b/src/master/taskmgr.py @@ -692,8 +692,13 @@ class TaskMgr(threading.Thread): disk = int(json_task['diskSetting']), gpu = int(json_task['gpuSetting'])), mount = [Mount( - localPath = json_task['mapping'][mapping_key]['mappingLocalDir'], - remotePath=json_task['mapping'][mapping_key]['mappingRemoteDir']) + provider = json_task['mapping'][mapping_key]['mappingProvider'], + localPath = json_task['mapping'][mapping_key]['mappingMountpath'], + remotePath = json_task['mapping'][mapping_key]['mappingBucketName'], + accessKey = json_task['mapping'][mapping_key]['mappingAccessKey'], + secretKey = json_task['mapping'][mapping_key]['mappingSecretKey'], + other = json_task['mapping'][mapping_key]['mappingEndpoint'] + ) for mapping_key in json_task['mapping']] if 'mapping' in json_task else [] ), ), diff --git a/src/worker/ossmounter.py b/src/worker/ossmounter.py index 607ca45..acd2812 100644 --- a/src/worker/ossmounter.py +++ b/src/worker/ossmounter.py @@ -27,7 +27,7 @@ class OssMounter(object): # umount oss pass -class aliyunOssMounter(OssMounter): +class AliyunOssMounter(OssMounter): @staticmethod def mount_oss(datapath, mount_info): @@ -42,7 +42,7 @@ class aliyunOssMounter(OssMounter): cmd = "chmod 640 /etc/passwd-ossfs" [success1, msg] = OssMounter.execute_cmd(cmd) - mountpath = datapath+"/"+mount_info.remotePath + mountpath = datapath+"/Aliyun/"+mount_info.remotePath logger.info("Mount oss %s %s" % (mount_info.remotePath, mountpath)) if not os.path.isdir(mountpath): os.makedirs(mountpath) diff --git a/src/worker/taskworker.py b/src/worker/taskworker.py index 83304ed..bff7a59 100755 --- a/src/worker/taskworker.py +++ b/src/worker/taskworker.py @@ -202,11 +202,12 @@ class TaskWorker(rpc_pb2_grpc.WorkerServicer): return rpc_pb2.Reply(status=rpc_pb2.Reply.REFUSED, message=msg) #mount oss + rootfs = "/var/lib/lxc/%s/rootfs" % lxcname self.mount_oss("%s/global/users/%s/oss" % (self.fspath,username), mount_list) conffile = open("/var/lib/lxc/%s/config" % lxcname, 'a+') - mount_str = "lxc.mount.entry = %s/global/users/%s/oss/%s %s/root/oss/%s none bind,rw,create=dir 0 0" + mount_str = "lxc.mount.entry = %s/global/users/%s/oss/%s/%s %s/root/oss/%s none bind,rw,create=dir 0 0" for mount in mount_list: - conffile.write("\n"+ mount_str % (self.fspath, username, mount.remotePath, rootfs, mount.remotePath)) + conffile.write("\n"+ mount_str % (self.fspath, username, mount.provider, mount.remotePath, rootfs, mount.remotePath)) conffile.close() logger.info("Start container %s..." % lxcname) diff --git a/web/templates/batch/batch_create.html b/web/templates/batch/batch_create.html index eb7238f..9a873ad 100644 --- a/web/templates/batch/batch_create.html +++ b/web/templates/batch/batch_create.html @@ -121,15 +121,20 @@ $("#collapse" + obj.id).collapse('hide'); } + function chmountPath(obj,task_num,mapping_num) { + cellid = 'mapping_mountpath_' + task_num + '_' + mapping_num; + $('#'+cellid).val("/root/oss/"+obj.value); + } + function removeMapping(obj) { $("#mapping_" + obj.id).remove(); } - function addMapping(obj) { + function addMapping(obj,task_num) { mapping_number += 1; var table = $("#storage_mapping_" + obj.id)[0]; var new_mapping = table.insertRow(); - new_mapping.id = "mapping_" + task_number + "_" + mapping_number; + new_mapping.id = "mapping_" + task_num + "_" + mapping_number; var provider = new_mapping.insertCell(); var bucket_name = new_mapping.insertCell(); var accessKey = new_mapping.insertCell(); @@ -137,20 +142,20 @@ var endpoint = new_mapping.insertCell(); var mountpath = new_mapping.insertCell(); var remove = new_mapping.insertCell(); - bucket_name.innerHTML = ''; - accessKey.innerHTML = ''; - secretKey.innerHTML = ''; - endpoint.innerHTML = 'http://'; - mountpath.innerHTML = ''; - provider.innerHTML = ''; + accessKey.innerHTML = ''; + secretKey.innerHTML = ''; + endpoint.innerHTML = 'http://'; + mountpath.innerHTML = ''; + provider.innerHTML = ''; - remove.innerHTML = '
'; } @@ -217,7 +222,7 @@ function addTask() { task_number += 1; var masterip=$("select#masterselector").children('option:selected').val(); - mapping_number = 0; + //mapping_number = 0; var task_html = ''; task_html += '
' @@ -334,7 +339,7 @@ +'
' +'
' +'' +'
' +''