示例#1
0
def weblab_stop(directory):
    parser = OptionParser(usage="%prog stop DIR [options]")

    check_dir_exists(directory, parser)
    if sys.platform.lower().startswith('win'):
        print >> sys.stderr, "Stopping not yet supported. Try killing the process from the Task Manager or simply press enter"
        sys.exit(-1)
    os.kill(int(open(os.path.join(directory, 'weblab.pid')).read()), signal.SIGTERM)
示例#2
0
def weblab_stop(directory):
    parser = OptionParser(usage="%prog stop DIR [options]")

    check_dir_exists(directory, parser)
    if sys.platform.lower().startswith('win'):
        print(
            "Stopping not yet supported. Try killing the process from the Task Manager or simply press enter",
            file=sys.stderr)
        sys.exit(-1)
    os.kill(int(open(os.path.join(directory, 'weblab.pid')).read()),
            signal.SIGTERM)
示例#3
0
def weblab_monitor(directory):
    check_dir_exists(directory)
    new_globals = {}
    new_locals = {}
    execfile(os.path.join(directory, 'debugging.py'), new_globals, new_locals)

    SERVERS = new_locals['SERVERS']

    def list_users(experiment):
        information, ups_orphans, coordinator_orphans = wl.list_users(
            experiment)

        print("%15s\t%25s\t%11s\t%11s" %
              ("LOGIN", "STATUS", "UPS_SESSID", "RESERV_ID"))
        for login, status, ups_session_id, reservation_id in information:
            if isinstance(status,
                          WebLabQueueStatus.WaitingQueueStatus) or isinstance(
                              status,
                              WebLabQueueStatus.WaitingInstancesQueueStatus):
                status_str = "%s: %s" % (status.status, status.position)
            else:
                status_str = status.status

            if options.full_info:
                print("%15s\t%25s\t%8s\t%8s" %
                      (login, status_str, ups_session_id, reservation_id))
            else:
                print("%15s\t%25s\t%8s...\t%8s..." %
                      (login, status_str, ups_session_id[:8], reservation_id))

        if len(ups_orphans) > 0:
            print()
            print("UPS ORPHANS")
            for ups_info in ups_orphans:
                print(ups_info)

        if len(coordinator_orphans) > 0:
            print()
            print("COORDINATOR ORPHANS")
            for coordinator_info in coordinator_orphans:
                print(coordinator_info)

    def show_server(number):
        if number > 0:
            print()
        print("Server %s" % (number + 1))

    option_parser = OptionParser()

    option_parser.add_option("-e",
                             "--list-experiments",
                             action="store_true",
                             dest="list_experiments",
                             help="Lists all the available experiments")

    option_parser.add_option(
        "-u",
        "--list-users",
        dest="list_users",
        nargs=1,
        default=None,
        metavar='EXPERIMENT_ID',
        help=
        "Lists all users using a certain experiment (format: experiment@category)"
    )

    option_parser.add_option("-a",
                             "--list-experiment-users",
                             action="store_true",
                             dest="list_experiment_users",
                             help="Lists all users using any experiment")

    option_parser.add_option("-l",
                             "--list-all-users",
                             action="store_true",
                             dest="list_all_users",
                             help="Lists all connected users")

    option_parser.add_option(
        "-f",
        "--full-info",
        action="store_true",
        dest="full_info",
        help=
        "Shows full information (full session ids instead of only the first characteres)"
    )

    option_parser.add_option(
        "-k",
        "--kick-session",
        dest="kick_session",
        nargs=1,
        default=None,
        metavar='SESSION_ID',
        help=
        "Given the full UPS Session ID, it kicks out a user from the system")

    option_parser.add_option(
        "-b",
        "--kick-user",
        dest="kick_user",
        nargs=1,
        default=None,
        metavar='USER_LOGIN',
        help="Given the user login, it kicks him out from the system")

    options, _ = option_parser.parse_args()

    for num, server in enumerate(SERVERS):
        wl = WebLabMonitor(server)

        if options.list_experiments:
            print(wl.list_experiments(), end='')

        elif options.list_experiment_users:
            show_server(num)
            experiments = wl.list_experiments()
            if experiments != '':
                for experiment in experiments.split('\n')[:-1]:
                    print()
                    print("%s..." % experiment)
                    print()
                    list_users(experiment)

        elif options.list_users != None:
            show_server(num)
            list_users(options.list_users)

        elif options.list_all_users:
            show_server(num)
            all_users = wl.list_all_users()

            print("%15s\t%11s\t%17s\t%24s" %
                  ("LOGIN", "UPS_SESSID", "FULL_NAME", "LATEST TIMESTAMP"))

            for ups_session_id, user_information, latest_timestamp in all_users:
                latest = time.asctime(time.localtime(latest_timestamp))
                if options.full_info:
                    print("%15s\t%11s\t%17s\t%24s" %
                          (user_information.login, ups_session_id.id,
                           user_information.full_name, latest))
                else:
                    if len(user_information.full_name) <= 14:
                        print("%15s\t%8s...\t%s\t%24s" %
                              (user_information.login, ups_session_id.id[:8],
                               user_information.full_name, latest))
                    else:
                        print("%15s\t%8s...\t%14s...\t%24s" %
                              (user_information.login, ups_session_id.id[:8],
                               user_information.full_name[:14], latest))

        elif options.kick_session != None:
            show_server(num)
            wl.kick_session(options.kick_session)

        elif options.kick_user != None:
            show_server(num)
            wl.kick_user(options.kick_user)

        else:
            option_parser.print_help()
            break
示例#4
0
def weblab_monitor(directory):
    check_dir_exists(directory)
    new_globals = {}
    new_locals  = {}
    execfile(os.path.join(directory, 'debugging.py'), new_globals, new_locals)

    SERVERS = new_locals['SERVERS']

    def list_users(experiment):
        information, ups_orphans, coordinator_orphans = wl.list_users(experiment)

        print "%15s\t%25s\t%11s\t%11s" % ("LOGIN","STATUS","UPS_SESSID","RESERV_ID")
        for login, status, ups_session_id, reservation_id in information:
            if isinstance(status, WebLabQueueStatus.WaitingQueueStatus) or isinstance(status, WebLabQueueStatus.WaitingInstancesQueueStatus):
                status_str = "%s: %s" % (status.status, status.position)
            else:
                status_str = status.status

            if options.full_info:
                    print "%15s\t%25s\t%8s\t%8s" % (login, status_str, ups_session_id, reservation_id)
            else:
                    print "%15s\t%25s\t%8s...\t%8s..." % (login, status_str, ups_session_id[:8], reservation_id)

        if len(ups_orphans) > 0:
            print 
            print "UPS ORPHANS"
            for ups_info in ups_orphans:
                print ups_info

        if len(coordinator_orphans) > 0:
            print 
            print "COORDINATOR ORPHANS"
            for coordinator_info in coordinator_orphans:
                print coordinator_info

    def show_server(number):
        if number > 0:
            print 
        print "Server %s" % (number + 1)

    option_parser = OptionParser()

    option_parser.add_option( "-e", "--list-experiments",
                              action="store_true",
                              dest="list_experiments",
                              help="Lists all the available experiments" )
                            
    option_parser.add_option( "-u", "--list-users",
                              dest="list_users",
                              nargs=1,
                              default=None,
                              metavar='EXPERIMENT_ID',
                              help="Lists all users using a certain experiment (format: experiment@category)" )

    option_parser.add_option( "-a", "--list-experiment-users",
                              action="store_true",
                              dest="list_experiment_users",
                              help="Lists all users using any experiment" )

    option_parser.add_option( "-l", "--list-all-users",
                              action="store_true",
                              dest="list_all_users",
                              help="Lists all connected users" )

    option_parser.add_option( "-f", "--full-info",
                      action="store_true",
                              dest="full_info",
                              help="Shows full information (full session ids instead of only the first characteres)" )
                             
    option_parser.add_option( "-k", "--kick-session",
                              dest="kick_session",
                              nargs=1,
                              default=None,
                              metavar='SESSION_ID',
                              help="Given the full UPS Session ID, it kicks out a user from the system" )

    option_parser.add_option( "-b", "--kick-user",
                              dest="kick_user",
                              nargs=1,
                              default=None,
                              metavar='USER_LOGIN',
                              help="Given the user login, it kicks him out from the system" )

    options, _ = option_parser.parse_args()

    for num, server in enumerate(SERVERS):
        wl = WebLabMonitor(server)

        if options.list_experiments:
            print wl.list_experiments(),

        elif options.list_experiment_users:
            show_server(num)
            experiments = wl.list_experiments()
            if experiments != '':
                for experiment in experiments.split('\n')[:-1]:
                    print 
                    print "%s..." % experiment
                    print 
                    list_users(experiment)
            
        elif options.list_users != None:
            show_server(num)
            list_users(options.list_users)
            
        elif options.list_all_users:
            show_server(num)
            all_users = wl.list_all_users()

            print "%15s\t%11s\t%17s\t%24s" % ("LOGIN","UPS_SESSID","FULL_NAME","LATEST TIMESTAMP")

            for ups_session_id, user_information, latest_timestamp in all_users:
                latest = time.asctime(time.localtime(latest_timestamp))
                if options.full_info:
                    print "%15s\t%11s\t%17s\t%24s" % (user_information.login, ups_session_id.id, user_information.full_name, latest)
                else:
                    if len(user_information.full_name) <= 14:
                        print "%15s\t%8s...\t%s\t%24s" % (user_information.login, ups_session_id.id[:8], user_information.full_name, latest)
                    else:
                        print "%15s\t%8s...\t%14s...\t%24s" % (user_information.login, ups_session_id.id[:8], user_information.full_name[:14], latest)
            
        elif options.kick_session != None:
            show_server(num)
            wl.kick_session(options.kick_session)

        elif options.kick_user != None:
            show_server(num)
            wl.kick_user(options.kick_user)
           
        else:
            option_parser.print_help()
            break
示例#5
0
def weblab_start(directory):
    parser = OptionParser(usage="%prog create DIR [options]")

    parser.add_option("-m", "--machine",           dest="machine", default=None, metavar="MACHINE",
                                                   help = "If there is more than one machine in the configuration, which one should be started.")
    parser.add_option("-l", "--list-machines",     dest="list_machines", action='store_true', default=False, 
                                                   help = "List machines.")

    parser.add_option("-s", "--script",            dest="script", default=None, metavar="SCRIPT",
                                                   help = "If the runner option is not available, which script should be used.")

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    def on_dir(directory, configuration_files):
        db_conf = DbConfiguration(configuration_files)
        regular_url = db_conf.build_url()
        coord_url   = db_conf.build_coord_url()
        upgrader = DbUpgrader(regular_url, coord_url)
        return upgrader.check_updated()

    if not run_with_config(directory, on_dir):
        print >> sys.stderr, "Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s" % directory
        sys.exit(-1)


    old_cwd = os.getcwd()
    os.chdir(directory)
    try:
        if options.script: # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print >> sys.stderr, "Provided script %s does not exist" % options.script
                sys.exit(-1)
        else:
            parser = GlobalParser()
            global_configuration = parser.parse('.')
            if options.list_machines:
                for machine in global_configuration.machines:
                    print ' - %s' % machine
                sys.exit(0)

            machine_name = options.machine
            if machine_name is None: 
                if len(global_configuration.machines) == 1:
                    machine_name = global_configuration.machines.keys()[0]
                else:
                    print >> sys.stderr, "System has more than one machine (see -l). Please detail which machine you want to start with the -m option."
                    sys.exit(-1)

            if not machine_name in global_configuration.machines:
                print >> sys.stderr, "Error: %s machine does not exist. Use -l to see the list of existing machines." % machine_name
                sys.exit(-1)

            machine_config = global_configuration.machines[machine_name]
            if machine_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print >> sys.stderr, "No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s." % machine_name
                    sys.exit(-1)
            else:
                if os.path.exists(machine_config.runner):
                    execfile(machine_config.runner)
                else:
                    print >> sys.stderr, "Misconfigured system. Machine %s points to %s which does not exist." % (machine_name, os.path.abspath(machine_config.runner))
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)
示例#6
0
def weblab_start(directory):
    parser = OptionParser(usage="%prog start DIR [options]")

    parser.add_option(
        '-m',
        '--host',
        '--machine',
        dest='host',
        default=None,
        metavar='HOST',
        help=
        'If there is more than one host in the configuration, which one should be started.'
    )

    parser.add_option('-l',
                      '--list-hosts',
                      '--list-machines',
                      dest='list_hosts',
                      action='store_true',
                      default=False,
                      help='List hosts.')

    parser.add_option(
        '-s',
        '--script',
        dest='script',
        default=None,
        metavar='SCRIPT',
        help=
        'If the runner option is not available, which script should be used.')

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    if not run_with_config(directory, check_updated):
        print(
            "Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s"
            % directory,
            file=sys.stderr)
        sys.exit(-1)

    old_cwd = os.getcwd()
    os.chdir(directory)

    # Ensure we aren't already running. The check is not currently supported on Windows.
    if sys.platform.lower().startswith('win'):
        if os.path.exists("weblab.pid"):
            pid = int(open("weblab.pid").read())
            running = check_pid(pid)
            if not running:
                os.remove("weblab.pid")
            else:
                print(
                    "Error: WebLab-Deusto instance seems to be running already!",
                    file=sys.stderr)
                sys.exit(-1)

    try:
        if options.script:  # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print("Provided script %s does not exist" % options.script,
                      file=sys.stderr)
                sys.exit(-1)
        else:
            global_configuration = load_dir('.')
            if options.list_hosts:
                for host in global_configuration:
                    print(' - %s' % host)
                sys.exit(0)

            host_name = options.host
            if host_name is None:
                if len(global_configuration) == 1:
                    host_name = global_configuration.keys()[0]
                else:
                    print(
                        "System has more than one host (see -l). Please detail which host you want to start with the --host option.",
                        file=sys.stderr)
                    sys.exit(-1)

            if not host_name in global_configuration:
                print(
                    "Error: %s host does not exist. Use -l to see the list of existing hosts."
                    % host_name,
                    file=sys.stderr)
                sys.exit(-1)

            host_config = global_configuration[host_name]
            if host_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print(
                        "No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s."
                        % host_name,
                        file=sys.stderr)
                    sys.exit(-1)
            else:
                if os.path.exists(host_config.runner):
                    execfile(host_config.runner)
                else:
                    print(
                        "Misconfigured system. Machine %s points to %s which does not exist."
                        % (host_name, os.path.abspath(host_config.runner)),
                        file=sys.stderr)
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)
示例#7
0
def weblab_start(directory):
    parser = OptionParser(usage="%prog start DIR [options]")

    parser.add_option('-m', '--host', '--machine',
                                                   dest='host', default=None, metavar='HOST',
                                                   help = 'If there is more than one host in the configuration, which one should be started.')

    parser.add_option('-l', '--list-hosts', '--list-machines',     
                                                   dest='list_hosts', action='store_true', default=False, 
                                                   help = 'List hosts.')

    parser.add_option('-s', '--script',            dest='script', default=None, metavar='SCRIPT',
                                                   help = 'If the runner option is not available, which script should be used.')

    options, args = parser.parse_args()

    check_dir_exists(directory, parser)

    if not run_with_config(directory, check_updated):
        print("Error: WebLab-Deusto instance outdated! You may have updated WebLab-Deusto recently. Run: weblab-admin.py upgrade %s" % directory, file=sys.stderr)
        sys.exit(-1)


    old_cwd = os.getcwd()
    os.chdir(directory)

    # Ensure we aren't already running. The check is not currently supported on Windows.
    if sys.platform.lower().startswith('win'):
        if os.path.exists("weblab.pid"):
            pid = int(open("weblab.pid").read())
            running = check_pid(pid)
            if not running:
                os.remove("weblab.pid")
            else:
                print("Error: WebLab-Deusto instance seems to be running already!", file=sys.stderr)
                sys.exit(-1)

    try:
        if options.script: # If a script is provided, ignore the rest
            if os.path.exists(options.script):
                execfile(options.script)
            elif os.path.exists(os.path.join(old_cwd, options.script)):
                execfile(os.path.join(old_cwd, options.script))
            else:
                print("Provided script %s does not exist" % options.script, file=sys.stderr)
                sys.exit(-1)
        else:
            global_configuration = load_dir('.')
            if options.list_hosts:
                for host in global_configuration:
                    print(' - %s' % host)
                sys.exit(0)

            host_name = options.host
            if host_name is None: 
                if len(global_configuration) == 1:
                    host_name = global_configuration.keys()[0]
                else:
                    print("System has more than one host (see -l). Please detail which host you want to start with the --host option.", file=sys.stderr)
                    sys.exit(-1)

            if not host_name in global_configuration:
                print("Error: %s host does not exist. Use -l to see the list of existing hosts." % host_name, file=sys.stderr)
                sys.exit(-1)

            host_config = global_configuration[host_name]
            if host_config.runner is None:
                if os.path.exists('run.py'):
                    execfile('run.py')
                else:
                    print("No runner was specified, and run.py was not available. Please the -s argument to specify the script or add the <runner file='run.py'/> option in %s." % host_name, file=sys.stderr)
                    sys.exit(-1)
            else:
                if os.path.exists(host_config.runner):
                    execfile(host_config.runner)
                else:
                    print("Misconfigured system. Machine %s points to %s which does not exist." % (host_name, os.path.abspath(host_config.runner)), file=sys.stderr)
                    sys.exit(-1)
    finally:
        os.chdir(old_cwd)