Introduce --default-runtime parameter

Default to 'docker', --default-runtime will allow us to change the
runtime (docker, podman, etc) in the future.
In future patches, we'll add support for LibPod and this patch will
allow to start running "paunch apply" for a specific runtime backend.

Change-Id: I4660f37a3fc231830f4f3a875f63473d68ca7cfc
This commit is contained in:
Emilien Macchi 2018-08-08 21:31:53 -04:00
parent c19a46bb57
commit c7080ee369
2 changed files with 22 additions and 8 deletions

View File

@ -25,7 +25,8 @@ __version__ = pbr.version.VersionInfo('paunch').version_string()
LOG = logging.getLogger(__name__)
def apply(config_id, config, managed_by, labels=None, docker_cmd=None):
def apply(config_id, config, managed_by, labels=None, docker_cmd=None,
default_runtime='docker'):
"""Execute supplied container configuration.
:param str config_id: Unique config ID, should not be re-used until any
@ -38,19 +39,25 @@ def apply(config_id, config, managed_by, labels=None, docker_cmd=None):
:param dict labels: Optional keys/values of labels to apply to containers
created with this invocation.
:param str docker_cmd: Optional override to the docker command to run.
:param str default_runtime: Optional override to the default runtime used
for containers.
:returns (list, list, int) lists of stdout and stderr for each execution,
and a single return code representing the
overall success of the apply.
:rtype: tuple
"""
# TODO(emilien) Call the right runner based on default_runtime
r = runner.DockerRunner(managed_by, docker_cmd=docker_cmd)
builder = compose1.ComposeV1Builder(
config_id=config_id,
config=config,
runner=r,
labels=labels
)
if default_runtime == 'docker':
builder = compose1.ComposeV1Builder(
config_id=config_id,
config=config,
runner=r,
labels=labels
)
else:
LOG.error("container runtime not supported: %s" % default_runtime)
return builder.apply()

View File

@ -56,6 +56,12 @@ class Apply(command.Command):
required=True,
help=('ID to assign to containers'),
)
parser.add_argument(
'--default-runtime',
dest='default_runtime',
default='docker',
help=('Default runtime for containers. Can be docker or podman.'),
)
return parser
def take_action(self, parsed_args):
@ -72,7 +78,8 @@ class Apply(command.Command):
parsed_args.config_id,
config,
managed_by='paunch',
labels=labels
labels=labels,
default_runtime=parsed_args.default_runtime
)
return rc