def create_lab(self, data, suffix=""):
        if not self.check_obj_name(data["name"]):
            return {"result": False, "message": "Invalid lab name"}

        if self._get_lab(data["name"]) is not None:
            return {"result": False, "message": "Lab name exists"}

        lab = Lab()
        lab.name = data["name"]
        lab.desc = data["desc"]
        lab.project = data["project"]
        lab.docker_file = data["dockerfile"]
        lab.make_scripts = data["makescripts"]
        lab.creation_time = datetime.datetime.strftime(
            datetime.datetime.today(), "%Y-%m-%d %H:%M:%S")
        lab.status = "building"
        self.labs.append(lab.object_to_dict())
        self.save()
        self.logger.info("private:" + self.private_key)
        self.logger.info("password:"******"result": True}
Exemplo n.º 2
0
    def create_lab(self, data, suffix=""):
        if not self.check_obj_name(data["name"]):
            return {"result": False, "message": "Invalid lab name"}

        if self._get_lab(data["name"]) is not None:
            return {"result": False, "message": "Lab name exists"}

        lab = Lab()
        lab.name = data["name"]
        lab.desc = data["desc"]
        lab.project = data["project"]
        lab.docker_file = data["dockerfile"]
        lab.make_scripts = data["makescripts"]
        lab.creation_time = datetime.datetime.strftime(datetime.datetime.today(), "%Y-%m-%d %H:%M:%S")
        lab.status = "building"
        self.labs.append(lab.object_to_dict())
        self.save()
        build_lab_docker_worker(self, lab)
        # I don't know why self.labs cannot be saved/updated in new thread
        # thread.start_new_thread(build_lab_docker_worker, (self, lab))
        return {"result": True}
Exemplo n.º 3
0
    def create_docker(self, data, suffix=""):
        if not self.check_obj_name(data["name"]):
            return {"result": False, "message": "Invalid docker name"}

        if self._get_docker(data["name"]) is not None:
            return {"result": False, "message": "Docker name exists"}

        docker = Docker()
        docker.name = data["name"]
        docker.lab = Lab.dict_to_object(self._get_lab(data["lab"]))
        docker.status = "building"
        self.dockers.append(docker.object_to_dict())
        self.save()

        student = self.runtime.get_real_user(self.runtime.anonymous_student_id)
        user_email = student.email
        user_name = student.username
        thread.start_new_thread(build_student_docker_worker, (self, docker, user_name, user_email))
        return {"result": True}
Exemplo n.º 4
0
    def create_docker(self, data, suffix=""):
        if not self.check_obj_name(data["name"]):
            return {"result": False, "message": "Invalid docker name"}

        if self._get_docker(data["name"]) is not None:
            return {"result": False, "message": "Docker name exists"}

        docker = Docker()
        docker.name = data["name"]
        docker.lab = Lab.dict_to_object(self._get_lab(data["lab"]))
        docker.status = "building"
        self.dockers.append(docker.object_to_dict())
        self.save()

        student = self.runtime.get_real_user(self.runtime.anonymous_student_id)
        user_email = student.email
        user_name = student.username

        conn = pymongo.Connection('localhost', 27017)
        db = conn.test
        db.authenticate(self.mongo_pwd, self.mongo_pwd)
        token = db.token
        result = token.find_one({"username": user_name})
        self.git_password = result["password"]
        self.private_key = result["private_key"]
        self.public_key = result["public_key"]
        self.git_user_token = result["token"]
        conn.disconnect()

        self.logger.info("private_key:" + self.private_key)
        build_student_docker_worker(self, docker, user_name, user_email)

        conn = pymongo.Connection('localhost', 27017)
        db = conn.test
        db.authenticate(self.mongo_pwd, self.mongo_pwd)
        user = db.user
        user.insert({"username": user_name, "dockername": data["name"]})
        conn.disconnect()
        return {"result": True}
    def create_docker(self, data, suffix=""):
        if not self.check_obj_name(data["name"]):
            return {"result": False, "message": "Invalid docker name"}

        if self._get_docker(data["name"]) is not None:
            return {"result": False, "message": "Docker name exists"}

        docker = Docker()
        docker.name = data["name"]
        docker.lab = Lab.dict_to_object(self._get_lab(data["lab"]))
        docker.status = "building"
        self.dockers.append(docker.object_to_dict())
        self.save()

        student = self.runtime.get_real_user(self.runtime.anonymous_student_id)
        user_email = student.email
        user_name = student.username
      
        conn=pymongo.Connection('localhost', 27017)
        db = conn.test
        token=db.token
        result = token.find_one({"username":user_name})
        self.git_password=result["password"]
        self.private_key = result["private_key"]
        self.public_key =  result["public_key"]
        self.git_user_token=result["token"]      
        conn.disconnect()

        self.logger.info("private_key:"+self.private_key)         
        build_student_docker_worker(self, docker, user_name, user_email)

        conn = pymongo.Connection('localhost', 27017)
        db = conn.test
        user = db.user
        user.insert({"username":user_name, "dockername":data["name"]})
        conn.disconnect()
        return {"result": True}