Exemplo n.º 1
0
def main(args):
    "Starting point of the code"
    job_name = ''
    vm = None
    container = None
    if args.job:
        job_name = args.job
    else:
        sys.exit(-2)

    # First let us read the vm configuration.
    config = read_job_configuration(job_name, args.config_dir)
    if not config: # Bad config name
        sys.exit(-1)

    if config['type'] == 'vm':
        vm = build_and_run(config['image'], config['ram'], graphics=True, vnc=False, atomic=False)
        job_pid = vm.pid # The pid to kill at the end
        # We should wait for a minute here
        time.sleep(60)
    if config['type'] == 'docker':
        container = Docker(config['image'], int(config.get('wait', 600)))
    jobpath = os.path.join(args.config_dir, job_name + '.txt')

    try:
        run_job(args, jobpath, job_name, config, container)
    finally:
        # Now let us kill the kvm process
        if vm:
            os.kill(job_pid, signal.SIGKILL)
        if container:
            container.rm()
Exemplo n.º 2
0
def main(args):
    "Starting point of the code"
    job_name = ''
    vm = None
    port = None
    temp_d = None
    container = None
    atomic = False
    if args.atomic:
        atomic = True
    if args.job:
        job_name = args.job
    else:
        sys.exit(-2)

    # First let us read the vm configuration.
    config = read_job_configuration(job_name, args.config_dir)
    if not config:  # Bad config name
        sys.exit(-1)

    if config['type'] == 'vm':
        # First get us the free port number from redis queue.
        port = get_port()
        if not port:
            print "No port found in the redis queue."
            return
        # Now we need a temporary directory
        temp_d = tempfile.mkdtemp()
        os.system('chmod 0777 %s' % temp_d)
        os.mkdir(os.path.join(temp_d, 'meta'))
        vm = build_and_run(config['image'],
                           config['ram'],
                           graphics=True,
                           vnc=False,
                           atomic=atomic,
                           port=port,
                           temppath=temp_d)
        job_pid = vm.pid  # The pid to kill at the end
        # We should wait for a minute here
        time.sleep(60)
    if config['type'] == 'docker':
        container = Docker(config['image'])
    jobpath = os.path.join(args.config_dir, job_name + '.txt')

    try:
        run_job(args, jobpath, job_name, config, container, port)
    finally:
        # Now let us kill the kvm process
        if vm:
            os.kill(job_pid, signal.SIGKILL)
            if temp_d:
                shutil.rmtree(temp_d)
            return_port(port)
        if container:
            container.rm()
        else:
            # FIXME!!!
            # Somehow the terminal is not echoing unless we do the line below.
            os.system('stty sane')
Exemplo n.º 3
0
def main(args):
    "Starting point of the code"
    job_name = ''
    vm = None
    port = None
    temp_d = None
    container = None
    atomic = False
    image_dir = ''
    vagrant = None
    return_code = -100
    run_job_flag = True
    if args.atomic:
        atomic = True
    if args.job:
        job_name = args.job
    else:
        sys.exit(-2)

    # First let us read the vm configuration.
    config = read_job_configuration(job_name, args.config_dir)
    if not config: # Bad config name
        sys.exit(-1)

    os.system('mkdir -p /var/run/tunir')
    if config['type'] in ['vm',]:
        # If there is an image_dir then use that, else we need to
        # create a temp directory to store the image in
        if args.image_dir:
            image_dir = args.image_dir
        else:
            temp_d = tempfile.mkdtemp()
            image_dir = temp_d
        # If the image_dir is not yet created lets create it
        if not os.path.exists(image_dir):
            os.mkdir(image_dir)
        # Create the supporting meta directory if it doesn't exist
        if not os.path.exists(os.path.join(image_dir, 'meta')):
            os.mkdir(os.path.join(image_dir, 'meta'))
        # Update perms on directory
        os.system('chmod 0777 %s' % image_dir)


    if config['type'] == 'vm':
        # First get us the free port number from redis queue.
        port = get_port()
        if not port:
            print "No port found in the redis queue."
            return
        vm = build_and_run(config['image'], config['ram'],
                           graphics=True, vnc=False, atomic=atomic,
                           port=port, image_dir=image_dir)
        job_pid = vm.pid # The pid to kill at the end
        # We should wait for a minute here
        time.sleep(60)
    if config['type'] == 'docker':
        container = Docker(config['image'])
    jobpath = os.path.join(args.config_dir, job_name + '.txt')

    if config['type'] == 'vagrant':
        vagrant, config = vagrant_and_run(config)
        if vagrant.failed:
            run_job_flag = False

    try:
        if run_job_flag:
            status = run_job(args, jobpath, job_name, config, container, port)
            if status:
                return_code = 0
    finally:
        # Now let us kill the kvm process
        if vm:
            os.kill(job_pid, signal.SIGKILL)
            if temp_d:
                shutil.rmtree(temp_d)
            return_port(port)
        if container:
            container.rm()
        if vagrant:
            print "Removing the box."
            vagrant.destroy()
        else:
            # FIXME!!!
            # Somehow the terminal is not echoing unless we do the line below.
            os.system('stty sane')
        sys.exit(return_code)