Exemplo n.º 1
0
def main():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = dir_path[:dir_path.index("scripts/labtainer-instructor")]
    path = dir_path + "labs/"
    dirs = os.listdir(path)
    parser = argparse.ArgumentParser(
        description=
        'Start a Labtainers lab.  Provide no arguments see a list of labs.')
    parser.add_argument('labname', help='The lab to run')
    num_args = len(sys.argv)
    if num_args < 2:
        showLabs(dirs, path)
        exit(0)
    args = parser.parse_args()
    labname = args.labname
    if labname not in dirs:
        sys.stderr.write("ERROR: Lab named %s was not found!\n" % labname)
        sys.exit(1)

    docgoals.displayGoalInfo(labname)
    labutils.logger = LabtainerLogging.LabtainerLogging(
        "labtainer.log", labname, "../../config/labtainer.config")
    labutils.logger.INFO("Begin logging start.py for %s lab" % labname)
    lab_path = os.path.join(os.path.abspath('../../labs'), labname)
    labutils.StartLab(lab_path, "instructor")

    return 0
Exemplo n.º 2
0
def main():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = dir_path[:dir_path.index("scripts/labtainer-student")]
    path = dir_path + "labs/"
    dirs = os.listdir(path)
    parser = argparse.ArgumentParser(
        description=
        'Start a Labtainers lab.  Provide no arguments see a list of labs.')
    parser.add_argument('labname', help='The lab to run')
    parser.add_argument(
        '-q',
        '--quiet',
        action='store_true',
        help='Do not prompt for email, use previoulsy supplied email.')
    parser.add_argument(
        '-s',
        '--servers',
        action='store_true',
        help=
        'Intended for distributed Labtainers, start the containers that are not clients.'
    )
    parser.add_argument(
        '-w',
        '--workstation',
        action='store_true',
        help=
        'Intended for distributed Labtainers, start the client workstation.')
    parser.add_argument(
        '-n',
        '--client_count',
        action='store',
        help=
        'Number of clones of client components to create, itended for multi-user labs'
    )
    parser.add_argument('-o',
                        '--only_container',
                        action='store',
                        help='run only the named container')
    num_args = len(sys.argv)
    if num_args < 2:
        showLabs(dirs, path)
        exit(0)
    args = parser.parse_args()
    labname = args.labname
    if labname not in dirs:
        sys.stderr.write("ERROR: Lab named %s was not found!\n" % labname)
        sys.exit(1)

    labutils.logger = LabtainerLogging.LabtainerLogging(
        "labtainer.log", labname, "../../config/labtainer.config")
    labutils.logger.INFO("Begin logging start.py for %s lab" % labname)
    lab_path = os.path.join(os.path.abspath('../../labs'), labname)
    update_flag = '../../../.doupdate'
    if os.path.isfile(update_flag):
        ''' for prepackaged VMs, do not auto update after first lab is run '''
        os.remove(update_flag)
    #print('lab_path is %s' % lab_path)
    distributed = None
    if args.servers and args.workstation:
        print('--server and --workstation are mutually exclusive')
        exit(1)
    elif args.servers:
        distributed = 'server'
    elif args.workstation:
        distributed = 'client'
    if distributed is not None and args.client_count is not None:
        print(
            'Cannot specify --server or --client if a --client_count is provided'
        )
        exit(1)
    labutils.StartLab(lab_path,
                      "student",
                      quiet_start=args.quiet,
                      run_container=args.only_container,
                      servers=distributed,
                      clone_count=args.client_count)
    current_lab = CurrentLab.CurrentLab()
    current_lab.add('lab_name', args.labname)
    current_lab.add('clone_count', args.client_count)
    current_lab.add('servers', distributed)
    current_lab.save()

    return 0
Exemplo n.º 3
0
def main():
    dir_path = os.path.dirname(os.path.realpath(__file__))
    dir_path = dir_path[:dir_path.index("scripts/labtainer-student")]
    path = dir_path + "labs/"
    dirs = os.listdir(path)
    rev = getRev()
    #revision='%(prog)s %s' % rev
    parser = argparse.ArgumentParser(
        prog='labtainer',
        description=
        'Start a Labtainers lab.  Provide no arguments see a list of labs.')
    parser.add_argument('labname',
                        default='NONE',
                        nargs='?',
                        action='store',
                        help='The lab to run')
    parser.add_argument(
        '-q',
        '--quiet',
        action='store_true',
        help='Do not prompt for email, use previoulsy supplied email.')
    parser.add_argument(
        '-r',
        '--redo',
        action='store_true',
        help='Creates new instance of the lab, previous work will be lost.')
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version='%(prog)s ' + rev)
    parser.add_argument(
        '-d',
        '--diagnose',
        action='store_true',
        help='Run diagnostics on the environment expected by Labtainers')
    parser.add_argument(
        '-s',
        '--servers',
        action='store_true',
        help=
        'Intended for distributed Labtainers, start the containers that are not clients.'
    )
    parser.add_argument(
        '-w',
        '--workstation',
        action='store_true',
        help=
        'Intended for distributed Labtainers, start the client workstation.')
    parser.add_argument(
        '-n',
        '--client_count',
        action='store',
        help=
        'Number of clones of client components to create, itended for multi-user labs'
    )
    parser.add_argument('-o',
                        '--only_container',
                        action='store',
                        help='Run only the named container')
    parser.add_argument('-t',
                        '--test_registry',
                        action='store_true',
                        default=False,
                        help='Run with images from the test registry')
    num_args = len(sys.argv)
    versions = getVerList(dirs, path)
    if num_args < 2:
        skip_labs = os.path.join(dir_path, 'distrib', 'skip-labs')
        skip = []
        if os.path.isfile(skip_labs):
            with open(skip_labs) as fh:
                for line in fh:
                    f = os.path.basename(line).strip()
                    skip.append(f)
        showLabs(dirs, path, versions, skip)
        exit(0)
    args = parser.parse_args()
    labname = args.labname
    if labname == 'NONE' and not args.diagnose:
        sys.stderr.write("Missing lab name\n" % labname)
        parser.usage()
        sys.exit(1)
    if args.diagnose:
        diagnose()
        if labname == 'NONE':
            exit(0)

    if labname not in dirs:
        sys.stderr.write("ERROR: Lab named %s was not found!\n" % labname)
        sys.exit(1)

    labutils.logger = LabtainerLogging.LabtainerLogging(
        "labtainer.log", labname, "../../config/labtainer.config")
    labutils.logger.info("Begin logging start.py for %s lab" % labname)
    lab_path = os.path.join(os.path.abspath('../../labs'), labname)
    update_flag = '../../../.doupdate'
    if os.path.isfile(update_flag):
        ''' for prepackaged VMs, do not auto update after first lab is run '''
        os.remove(update_flag)
    #print('lab_path is %s' % lab_path)
    distributed = None
    if args.servers and args.workstation:
        print('--server and --workstation are mutually exclusive')
        exit(1)
    elif args.servers:
        distributed = 'server'
    elif args.workstation:
        distributed = 'client'
    if distributed is not None and args.client_count is not None:
        print(
            'Cannot specify --server or --client if a --client_count is provided'
        )
        exit(1)
    if args.test_registry:
        if os.getenv('TEST_REGISTRY') is None:
            #print('use putenv to set it')
            os.putenv("TEST_REGISTRY", "TRUE")
            ''' why does putenv not set the value? '''
            os.environ['TEST_REGISTRY'] = 'TRUE'
        else:
            #print('exists, set it true')
            os.environ['TEST_REGISTRY'] = 'TRUE'
        print('set TEST REG to %s' % os.getenv('TEST_REGISTRY'))

    if not args.redo:
        labutils.StartLab(lab_path,
                          quiet_start=args.quiet,
                          run_container=args.only_container,
                          servers=distributed,
                          clone_count=args.client_count)
    else:
        labutils.RedoLab(lab_path,
                         quiet_start=args.quiet,
                         run_container=args.only_container,
                         servers=distributed,
                         clone_count=args.client_count)
    current_lab = CurrentLab.CurrentLab()
    current_lab.add('lab_name', args.labname)
    current_lab.add('clone_count', args.client_count)
    current_lab.add('servers', distributed)
    current_lab.save()

    return 0