From c01764fe7c6fd39c907b23455c54fad137695f1a Mon Sep 17 00:00:00 2001 From: pinikomarov Date: Mon, 9 Mar 2020 11:55:18 +0200 Subject: [PATCH] add container_runtime_name str var to containers.py it will contain podman/docker as deployed Change-Id: Iff05741ac89fbf21489d5531bf63db03fadf25b8 --- tobiko/tripleo/containers.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tobiko/tripleo/containers.py b/tobiko/tripleo/containers.py index 3a1701877..3c226314c 100644 --- a/tobiko/tripleo/containers.py +++ b/tobiko/tripleo/containers.py @@ -16,7 +16,7 @@ from tobiko.openstack import neutron LOG = log.getLogger(__name__) -def container_runtime(): +def get_container_runtime_module(): """check what container runtime is running and return a handle to it""" # TODO THIS LOCKS SSH CLIENT TO CONTROLLER @@ -28,28 +28,35 @@ def container_runtime(): return podman -container_runtime_type = container_runtime() +container_runtime_module = get_container_runtime_module() + + +def get_container_runtime_name(): + return container_runtime_module.__name__.rsplit('.', 1)[1] + + +container_runtime_name = get_container_runtime_name() def list_node_containers(client): """returns a list of containers and their run state""" - if container_runtime_type == podman: - return container_runtime_type.list_podman_containers(client=client) + if container_runtime_module == podman: + return container_runtime_module.list_podman_containers(client=client) - elif container_runtime_type == docker: - return container_runtime_type.list_docker_containers(client=client) + elif container_runtime_module == docker: + return container_runtime_module.list_docker_containers(client=client) def get_container_client(ssh_client=None): """returns a list of containers and their run state""" - if container_runtime_type == podman: - return container_runtime_type.get_podman_client( + if container_runtime_module == podman: + return container_runtime_module.get_podman_client( ssh_client=ssh_client).connect() - elif container_runtime_type == docker: - return container_runtime_type.get_docker_client( + elif container_runtime_module == docker: + return container_runtime_module.get_docker_client( ssh_client=ssh_client).connect() @@ -206,11 +213,11 @@ def comparable_container_keys(container): """returns the tuple : 'container_host','container_name', 'container_state' """ - if container_runtime_type == podman: + if container_runtime_module == podman: return (container._client._context.hostname, # pylint: disable=W0212 container.data['names'], container.data['status']) - elif container_runtime_type == docker: + elif container_runtime_module == docker: return (container.attrs['Config']['Hostname'], container.attrs['Name'].strip('/'), container.attrs['State']['Status'])