lxc: more consistence for profiles

Signed-off-by: Mathieu Le Marec - Pasquet <kiorky@cryptelium.net>
This commit is contained in:
Mathieu Le Marec - Pasquet 2015-05-20 21:29:55 +02:00
parent 139372c055
commit 644bd729f7

View file

@ -1659,6 +1659,39 @@ def templates():
return [x[4:] for x in template_scripts if x.startswith('lxc-')]
def _after_ignition_network_profile(cmd,
ret,
name,
network_profile,
nic_opts):
_clear_context()
if ret['retcode'] == 0 and exists(name):
if network_profile:
network_changes = apply_network_profile(name,
network_profile,
nic_opts=nic_opts)
if network_changes:
log.info(
'Network changes from applying network profile \'{0}\' '
'to newly-created container \'{1}\':\n{2}'
.format(network_profile, name, network_changes)
)
c_state = state(name)
return {'result': True,
'state': {'old': None, 'new': c_state}}
else:
if exists(name):
# destroy the container if it was partially created
cmd = 'lxc-destroy'
cmd += ' -n {0}'.format(name)
__salt__['cmd.retcode'](cmd, python_shell=False)
raise CommandExecutionError(
'Container could not be created with cmd \'{0}\': {1}'
.format(cmd, ret['stderr'])
)
def create(name,
config=None,
profile=None,
@ -1856,11 +1889,19 @@ def create(name,
'Container could not be created with cmd \'{0}\': {1}'
.format(cmd, ret['stderr'])
)
ret = __salt__['cmd.run_all'](cmd, python_shell=False)
return _after_ignition_network_profile(cmd,
ret,
name,
network_profile,
nic_opts)
def clone(name,
orig,
profile=None,
network_profile=None,
nic_opts=None,
**kwargs):
'''
Create a new container as a clone of another container
@ -1889,6 +1930,16 @@ def clone(name,
The type of storage to use. Set to ``lvm`` to use an LVM group.
Defaults to filesystem within /var/lib/lxc.
network_profile
Network profile to use for container
.. versionadded:: 2015.5.0
nic_opts
give extra opts overriding network profile values
.. versionadded:: 2015.5.0
CLI Examples:
@ -1955,6 +2006,11 @@ def clone(name,
'Container could not be cloned with cmd \'{0}\': {1}'
.format(cmd, ret['stderr'])
)
return _after_ignition_network_profile(cmd,
ret,
name,
network_profile,
nic_opts)
def ls_(active=None, cache=True):