Beispiel #1
0
def advance(run_id):

    environment = get_environment()
    session = environment.get_session()

    try:
        run = get_run(run_id, session)
    except NoResultFound:
        logger.error("Unknown run ID: {}".format(run_id))

    #resources should get associated with the given run
    resource_manager = ResourceManager(environment, run)
    resource_manager.initialize_resources_from_run()
    #networks should get associated with the given run
    network_manager = NetworkManager(environment, run)
    network_manager.initialize_from_run()
    #containers should get associated with the given run
    container_manager = ContainerManager(environment,resource_manager,network_manager,run)
    container_manager.initialize_containers_from_run()

    container_manager.run_containers(groups = ['actions'])
Beispiel #2
0
def stop(run_id,timeout,wait):

    environment = get_environment()
    session = environment.get_session()

    try:
        run = get_run(run_id, session)
    except NoResultFound:
        logger.error("Unknown run ID: {}".format(run_id))

    #resources should get associated with the given run
    resource_manager = ResourceManager(environment, run)
    resource_manager.initialize_resources_from_run()
    #networks should get associated with the given run
    network_manager = NetworkManager(environment, run)
    network_manager.initialize_from_run()
    #containers should get associated with the given run
    container_manager = ContainerManager(environment,resource_manager,network_manager,run)
    container_manager.initialize_containers_from_run()

    logger.info("Stopping containers")
    container_manager.stop_containers(wait=wait,timeout = timeout)
Beispiel #3
0
def shell(run_id):

    environment = get_environment()
    session = environment.get_session()
    client = environment.get('client')

    try:
        run = get_run(run_id, session)
    except NoResultFound:
        logger.error("Unknown run ID: {}".format(run_id))

    try:
        network = run.networks[0]
    except IndexError:
        logger.error("No network defined for this run!")

    #resources should get associated with the given run
    resource_manager = ResourceManager(environment, run)
    resource_manager.initialize_resources_from_run()
    #networks should get associated with the given run
    network_manager = NetworkManager(environment, run)
    network_manager.initialize_from_run()
    #containers should get associated with the given run
    container_manager = ContainerManager(environment,resource_manager,network_manager,run)
    container_manager.initialize_containers_from_run()

    shell_container = container_manager.create_shell_container()

    try:
        logger.info("Opening shell and handing over control...")

        obj = subprocess.Popen("docker start -i -a {}".format(shell_container.name),shell=True)

        #we make sure the container is up and running before connecting the network
        time.sleep(1)
        network = network_manager.network
        if network:
            client.connect_container_to_network(shell_container.docker_id,network.data['Id'])

        obj.wait()
    finally:
        logger.info("Destroying container...")
        container_manager.destroy_container(shell_container)