Exemple #1
0
def checkContainers():
    ''' return true of labs are running '''
    lablist = labutils.GetListRunningLab()
    if len(lablist) == 0:
        return False
    else:
        return True
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
Exemple #3
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
Exemple #4
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
Exemple #5
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()
    labutils.logger = LabtainerLogging.LabtainerLogging("labtainer.log", 'stop.py', "../../config/labtainer.config")
    labutils.logger.debug('stop.py %s' % args.lab)
    lablist = labutils.GetListRunningLab()
    current_lab = CurrentLab.CurrentLab()
    clone_count = current_lab.get('clone_count')        
    servers = current_lab.get('servers')        
    current_lab_name = current_lab.get('lab_name')        
    if len(lablist) == 0:
        print('No labs are running.')
        labutils.logger.debug('No labs are running.')
    else:
        if args.lab == 'all':
            for lab in lablist:
                lab_path = os.path.join(os.path.abspath('../../labs'), lab)
                if current_lab_name is not None and lab != current_lab_name:
                    labutils.StopLab(lab_path, False)
                    print('Stopped lab %s, but was not current lab %s.  Servers and clones may not have stopped' % (lab, current_lab_name))
                    labutils.logger.debug('Stopped lab %s, but was not current lab.  Servers and clones may not have stopped')
                else:
                    labutils.StopLab(lab_path, False, servers=servers, clone_count=clone_count)
                    current_lab.clear()
        else:
            if args.lab in lablist: 
                lab_path = os.path.join(os.path.abspath('../../labs'), args.lab)
                if args.lab == current_lab_name:
                    labutils.StopLab(lab_path, False, servers=servers, clone_count=clone_count)
                    current_lab.clear()
                else:
                    labutils.StopLab(lab_path, False)
                    print('Stopped lab %s, but was not current lab.  Servers and clones may not have stopped' % args.lab)
                    labutils.logger.debug('Stopped lab %s, but was not current lab.  Servers and clones may not have stopped' % args.lab)
            else:
                print('Lab %s is not runnning, however %s is running.' % (args.lab, lablist[0]))
                labutils.logger.debug('Lab %s is not runnning, however %s is running.' % (args.lab, lablist[0]))

    return 0