From c7080ee369fe38596a2d32db438ac2740ac9b3e0 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Wed, 8 Aug 2018 21:31:53 -0400 Subject: [PATCH] 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 --- paunch/__init__.py | 21 ++++++++++++++------- paunch/cmd.py | 9 ++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/paunch/__init__.py b/paunch/__init__.py index 936e884..e303a69 100644 --- a/paunch/__init__.py +++ b/paunch/__init__.py @@ -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() diff --git a/paunch/cmd.py b/paunch/cmd.py index d069230..fdca6ba 100644 --- a/paunch/cmd.py +++ b/paunch/cmd.py @@ -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