예제 #1
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Stop a Labtainers lab.  If no arguments are provided, then all labs are stopped.'
    )
    parser.add_argument('lab', nargs='?', default='all')
    args = parser.parse_args()

    labname = args.lab
    lablist = []
    if labname != 'all':
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist.append(labname)
    else:
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist = labutils.GetListRunningLab()

    for labname in lablist:
        labutils.logger.info("Begin logging stop.py for %s lab" % labname)
        # Pass 'False' to ignore_stop_error (i.e., do not ignore error)
        lab_path = os.path.join(os.path.abspath('../../labs'), labname)
        has_running_containers, running_containers_list = labutils.GetRunningContainersList(
        )
        if has_running_containers:
            has_lab_role, labnamelist = labutils.GetRunningLabNames(
                running_containers_list)
            if has_lab_role:
                if labname not in labnamelist:
                    labutils.logger.error(
                        "No lab named %s in currently running labs!" % labname)
                    sys.exit(1)
            else:
                labutils.logger.error("Student is not running any labs")
                sys.exit(1)
        else:
            labutils.logger.error("No running labs at all")
            sys.exit(1)
        current_lab = CurrentLab.CurrentLab()
        clone_count = current_lab.get('clone_count')
        servers = current_lab.get('servers')
        labutils.StopLab(lab_path,
                         False,
                         servers=servers,
                         clone_count=clone_count)
        current_lab.clear()
        current_dir = os.getcwd()
        grade_dir = '../labtainer-instructor'
        os.chdir(grade_dir)
        subprocess.call('gradelab {}'.format(labname), shell=True)
        os.chdir(current_dir)
    subprocess.call(
        'python3 ../labtainer-instructor/assess_bin/json_upload.py',
        shell=True)

    return 0
예제 #2
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Stop a Labtainers lab.  If no arguments are provided, then all labs are stopped.'
    )
    parser.add_argument('lab', nargs='?', default='all')
    args = parser.parse_args()

    labname = args.lab
    lablist = []
    if labname != 'all':
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist.append(labname)
    else:
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist = labutils.GetListRunningLab()

    for labname in lablist:
        labutils.logger.INFO("Begin logging stop.py for %s lab" % labname)
        # Pass 'False' to ignore_stop_error (i.e., do not ignore error)
        lab_path = os.path.join(os.path.abspath('../../labs'), labname)
        has_running_containers, running_containers_list = labutils.GetRunningContainersList(
        )
        if has_running_containers:
            has_lab_role, labnamelist = labutils.GetRunningLabNames(
                running_containers_list, "student")
            if has_lab_role:
                if labname not in labnamelist:
                    labutils.logger.ERROR(
                        "No lab named %s in currently running labs!" % labname)
                    sys.exit(1)
            else:
                labutils.logger.ERROR("No running labs in student's role")
                sys.exit(1)
        else:
            labutils.logger.ERROR("No running labs at all")
            sys.exit(1)
        current_lab = CurrentLab.CurrentLab()
        clone_count = current_lab.get('clone_count')
        servers = current_lab.get('servers')
        labutils.StopLab(lab_path,
                         "student",
                         False,
                         servers=servers,
                         clone_count=clone_count)
        current_lab.clear()

    return 0
예제 #3
0
def main():
    if len(sys.argv) > 2:
        sys.stderr.write("Usage: stop.py [<labname>]\n")
        sys.exit(1)

    lablist = []
    if len(sys.argv) == 2:
        labname = sys.argv[1]
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist.append(labname)
    else:
        labname = "all"
        # labutils.logger need to be set before calling GetListRunningLab()
        labutils.logger = LabtainerLogging.LabtainerLogging(
            "labtainer.log", labname, "../../config/labtainer.config")
        lablist = labutils.GetListRunningLab()

    for labname in lablist:
        labutils.logger.info("Begin logging stop.py for %s lab" % labname)
        labutils.logger.debug("Instructor CWD = (%s), Student CWD = (%s)" %
                              (instructor_cwd, student_cwd))
        # Pass 'False' to ignore_stop_error (i.e., do not ignore error)
        lab_path = os.path.join(os.path.abspath('../../labs'), labname)
        has_running_containers, running_containers_list = labutils.GetRunningContainersList(
        )
        if has_running_containers:
            has_lab_role, labnamelist = labutils.GetRunningLabNames(
                running_containers_list, "instructor")
            if has_lab_role:
                if labname not in labnamelist:
                    labutils.logger.error(
                        "No lab named %s in currently running labs!" % labname)
                    sys.exit(1)
            else:
                labutils.logger.error("No running labs in instructor's role")
                sys.exit(1)
        else:
            labutils.logger.error("No running labs at all")
            sys.exit(1)
        labutils.StopLab(lab_path, "instructor", False)

    return 0