mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add execution module to manage docker volumes
This commit is contained in:
parent
8d32d8d43d
commit
dff6fa1fb2
2 changed files with 190 additions and 0 deletions
|
@ -4304,6 +4304,7 @@ def networks(names=None, ids=None):
|
|||
|
||||
|
||||
@_api_version(1.21)
|
||||
@_client_version('1.5.0')
|
||||
def create_network(name, driver=None):
|
||||
'''
|
||||
Create a new network
|
||||
|
@ -4419,6 +4420,107 @@ def disconnect_container_from_network(container, network_id):
|
|||
# Only non-error return case is a True return, so just return the response
|
||||
return response
|
||||
|
||||
# Volume Management
|
||||
|
||||
|
||||
@_api_version(1.21)
|
||||
@_client_version('1.5.0')
|
||||
def volumes(filters=None):
|
||||
'''
|
||||
List existing volumes
|
||||
|
||||
.. versionadded:: 2015.8.4
|
||||
|
||||
filters
|
||||
There is one available filter: dangling=true
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion dockerng.volumes filters="{'dangling': True}"
|
||||
'''
|
||||
response = _client_wrapper('volumes', filters=filters)
|
||||
_clear_context()
|
||||
# Only non-error return case is a True return, so just return the response
|
||||
return response
|
||||
|
||||
|
||||
@_api_version(1.21)
|
||||
@_client_version('1.5.0')
|
||||
def create_volume(name, driver=None, driver_opts=None):
|
||||
'''
|
||||
Create a new volume
|
||||
|
||||
.. versionadded:: 2015.8.4
|
||||
|
||||
name
|
||||
name of volume
|
||||
|
||||
driver
|
||||
Driver of the volume
|
||||
|
||||
driver_opts
|
||||
Options for the driver volume
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion dockerng.create_volume my_volume driver=local
|
||||
'''
|
||||
response = _client_wrapper('create_volume', name, driver=driver,
|
||||
driver_opts=driver_opts)
|
||||
_clear_context()
|
||||
# Only non-error return case is a True return, so just return the response
|
||||
return response
|
||||
|
||||
|
||||
@_api_version(1.21)
|
||||
@_client_version('1.5.0')
|
||||
def remove_volume(name):
|
||||
'''
|
||||
Remove a volume
|
||||
|
||||
.. versionadded:: 2015.8.4
|
||||
|
||||
name
|
||||
Name of volume
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion dockerng.remove_volume my_volume
|
||||
'''
|
||||
response = _client_wrapper('remove_volume', name)
|
||||
_clear_context()
|
||||
# Only non-error return case is a True return, so just return the response
|
||||
return response
|
||||
|
||||
|
||||
@_api_version(1.21)
|
||||
@_client_version('1.5.0')
|
||||
def inspect_volume(name):
|
||||
'''
|
||||
Inspect Volume
|
||||
|
||||
.. versionadded:: 2015.8.4
|
||||
|
||||
name
|
||||
Name of volume
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion dockerng.inspect_volume my_volume
|
||||
'''
|
||||
response = _client_wrapper('inspect_volume', name)
|
||||
_clear_context()
|
||||
# Only non-error return case is a True return, so just return the response
|
||||
return response
|
||||
|
||||
|
||||
# Functions to manage container state
|
||||
@_refresh_mine_cache
|
||||
|
|
|
@ -421,6 +421,94 @@ class DockerngTestCase(TestCase):
|
|||
client.disconnect_container_from_network.assert_called_once_with(
|
||||
'container', 'foo')
|
||||
|
||||
@skipIf(_docker_py_version() < (1, 5, 0),
|
||||
'docker module must be installed to run this test or is too old. >=1.5.0')
|
||||
def test_list_volumes(self, *args):
|
||||
'''
|
||||
test list volumes.
|
||||
'''
|
||||
__salt__ = {
|
||||
'config.get': Mock(),
|
||||
'mine.send': Mock(),
|
||||
}
|
||||
client = Mock()
|
||||
client.api_version = '1.21'
|
||||
with patch.dict(dockerng_mod.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.volumes(
|
||||
filters={'dangling': [True]},
|
||||
)
|
||||
client.volumes.assert_called_once_with(
|
||||
filters={'dangling': [True]},
|
||||
)
|
||||
|
||||
@skipIf(_docker_py_version() < (1, 5, 0),
|
||||
'docker module must be installed to run this test or is too old. >=1.5.0')
|
||||
def test_create_volume(self, *args):
|
||||
'''
|
||||
test create volume.
|
||||
'''
|
||||
__salt__ = {
|
||||
'config.get': Mock(),
|
||||
'mine.send': Mock(),
|
||||
}
|
||||
client = Mock()
|
||||
client.api_version = '1.21'
|
||||
with patch.dict(dockerng_mod.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.create_volume(
|
||||
'foo',
|
||||
driver='bridge',
|
||||
driver_opts={},
|
||||
)
|
||||
client.create_volume.assert_called_once_with(
|
||||
'foo',
|
||||
driver='bridge',
|
||||
driver_opts={},
|
||||
)
|
||||
|
||||
@skipIf(_docker_py_version() < (1, 5, 0),
|
||||
'docker module must be installed to run this test or is too old. >=1.5.0')
|
||||
def test_remove_volume(self, *args):
|
||||
'''
|
||||
test remove volume.
|
||||
'''
|
||||
__salt__ = {
|
||||
'config.get': Mock(),
|
||||
'mine.send': Mock(),
|
||||
}
|
||||
client = Mock()
|
||||
client.api_version = '1.21'
|
||||
with patch.dict(dockerng_mod.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.remove_volume('foo')
|
||||
client.remove_volume.assert_called_once_with('foo')
|
||||
|
||||
@skipIf(_docker_py_version() < (1, 5, 0),
|
||||
'docker module must be installed to run this test or is too old. >=1.5.0')
|
||||
def test_inspect_volume(self, *args):
|
||||
'''
|
||||
test inspect volume.
|
||||
'''
|
||||
__salt__ = {
|
||||
'config.get': Mock(),
|
||||
'mine.send': Mock(),
|
||||
}
|
||||
client = Mock()
|
||||
client.api_version = '1.21'
|
||||
with patch.dict(dockerng_mod.__dict__,
|
||||
{'__salt__': __salt__}):
|
||||
with patch.dict(dockerng_mod.__context__,
|
||||
{'docker.client': client}):
|
||||
dockerng_mod.inspect_volume('foo')
|
||||
client.inspect_volume.assert_called_once_with('foo')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
|
|
Loading…
Add table
Reference in a new issue