def _create_task(tid, offer, command, ns):
    """
    `tid` (str) task id
    `offer` a mesos Offer instance
    `ns.mesos_task_resources` the stuff a task would consume:
        {
            "cpus": 10,
            "mem": 1,
            "disk": 12,
            "ports": [(20, 34), (35, 35)],
            "disks": ["sda1"]
        }
    `ns.docker_image` (str|None)
        a docker image you wish to execute the command in
    `ns.volumes` a list of volumes that get mounted into the container:
        [
          ("host_path", "container_path", "mode"),
          ("/my/directory", "/path/on/container", "ro")
        ]
    """
    task = dict(
        task_id=mesos_pb2.TaskID(value=tid),
        slave_id=offer.slave_id,
        command=mesos_pb2.CommandInfo(
            value=command,
            uris=[mesos_pb2.CommandInfo.URI(value=uri) for uri in ns.uris],
            environment=mesos_pb2.Environment(variables=[
                mesos_pb2.Environment.Variable(name=k, value=v)
                for k, v in ns.mesos_environment])
        )
    )
    if ns.mesos_framework_name:
        task.update(
            name="relay.mesos task: %s: %s" % (ns.mesos_framework_name, tid))
    else:
        task.update(name="relay.mesos task: %s" % tid)
    # ability to inject os.environ values into the command
    if ns.docker_image:
        volumes = [
            mesos_pb2.Volume(
                host_path=host_path,
                container_path=container_path,
                mode=mesos_pb2.Volume.Mode.Value(mode.upper()))
            for host_path, container_path, mode in ns.volumes]
        task.update(
            container=mesos_pb2.ContainerInfo(
                type=mesos_pb2.ContainerInfo.DOCKER,
                volumes=volumes,
                docker=mesos_pb2.ContainerInfo.DockerInfo(
                    image=ns.docker_image,
                    force_pull_image=ns.force_pull_image,
                    network=mesos_pb2.ContainerInfo.DockerInfo.Network.Value(
                        ns.docker_network),
                    parameters=[
                        mesos_pb2.Parameter(key=k, value=v)
                        for k, v in ns.docker_parameters.items()],
                )
            ))
    task = mesos_pb2.TaskInfo(**task)
    _create_task_add_task_resources(task, ns)
    return task
dataset/ETHPy150Open sailthru/relay.mesos/relay_mesos/scheduler.py/_create_task/original