mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
pass filters argument to dockerng.ps
This commit is contained in:
parent
9a0171089d
commit
821ed72f37
2 changed files with 22 additions and 2 deletions
|
@ -2296,7 +2296,7 @@ def port(name, private_port=None):
|
|||
return dict((x, mappings[x]) for x in fnmatch.filter(mappings, pattern))
|
||||
|
||||
|
||||
def ps_(**kwargs):
|
||||
def ps_(filters=None, **kwargs):
|
||||
'''
|
||||
Returns information about the Docker containers on the Minion. Equivalent
|
||||
to running the ``docker ps`` Docker CLI command.
|
||||
|
@ -2311,6 +2311,13 @@ def ps_(**kwargs):
|
|||
If ``True``, a ``docker inspect`` will be run on each container
|
||||
returned.
|
||||
|
||||
filters: None
|
||||
A dictionary of filters to be processed on the container list.
|
||||
Available filters:
|
||||
|
||||
- exited (int): Only containers with specified exit code
|
||||
- status (str): One of restarting, running, paused, exited
|
||||
- label (str): format either "key" or "key=value"
|
||||
|
||||
**RETURN DATA**
|
||||
|
||||
|
@ -2324,9 +2331,10 @@ def ps_(**kwargs):
|
|||
|
||||
salt myminion dockerng.ps
|
||||
salt myminion dockerng.ps all=True
|
||||
salt myminion dockerng.ps filters="{'label': 'role=web'}"
|
||||
'''
|
||||
if 'docker.ps' not in __context__:
|
||||
response = _client_wrapper('containers', all=True)
|
||||
response = _client_wrapper('containers', all=True, filters=filters)
|
||||
key_map = {
|
||||
'Created': 'Time_Created_Epoch',
|
||||
}
|
||||
|
|
|
@ -51,6 +51,18 @@ class DockerngTestCase(TestCase):
|
|||
self.assertEqual(ret,
|
||||
{'host': {'interfaces': {'mocked': None}}})
|
||||
|
||||
def test_ps_with_filters(self):
|
||||
'''
|
||||
Check that dockerng.ps accept filters parameter.
|
||||
'''
|
||||
client = MagicMock()
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.ps_(filters={'label': 'KEY'})
|
||||
client.containers.assert_called_once_with(
|
||||
all=True,
|
||||
filters={'label': 'KEY'})
|
||||
|
||||
@patch.object(dockerng_mod, '_get_exec_driver')
|
||||
def test_check_mine_cache_is_refreshed_on_container_change_event(self, _):
|
||||
'''
|
||||
|
|
Loading…
Add table
Reference in a new issue