mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
docker_swarm_service: Use inspect_service to get service data (#52534)
* Use inspect_service to get service data * Catch NotFound error * Return None explicitly
This commit is contained in:
parent
f8d1fa80e9
commit
af154e42ec
1 changed files with 9 additions and 15 deletions
|
@ -652,9 +652,13 @@ try:
|
|||
from docker.utils import (
|
||||
parse_repository_tag,
|
||||
parse_env_file,
|
||||
format_environment
|
||||
format_environment,
|
||||
)
|
||||
from docker.errors import (
|
||||
APIError,
|
||||
DockerException,
|
||||
NotFound,
|
||||
)
|
||||
from docker.errors import APIError, DockerException
|
||||
except ImportError:
|
||||
# missing docker-py handled in ansible.module_utils.docker.common
|
||||
pass
|
||||
|
@ -1320,20 +1324,10 @@ class DockerServiceManager(object):
|
|||
return [{'name': n['Name'], 'id': n['Id']} for n in self.client.networks()]
|
||||
|
||||
def get_service(self, name):
|
||||
# The Docker API allows filtering services by name but the filter looks
|
||||
# for a substring match, not an exact match. (Filtering for "foo" would
|
||||
# return information for services "foobar" and "foobuzz" even if the
|
||||
# service "foo" doesn't exist.) Avoid incorrectly determining that a
|
||||
# service is present by filtering the list of services returned from the
|
||||
# Docker API so that the name must be an exact match.
|
||||
raw_data = [
|
||||
service for service in self.client.services(filters={'name': name})
|
||||
if service['Spec']['Name'] == name
|
||||
]
|
||||
if len(raw_data) == 0:
|
||||
try:
|
||||
raw_data = self.client.inspect_service(name)
|
||||
except NotFound:
|
||||
return None
|
||||
|
||||
raw_data = raw_data[0]
|
||||
ds = DockerService()
|
||||
|
||||
task_template_data = raw_data['Spec']['TaskTemplate']
|
||||
|
|
Loading…
Reference in a new issue