From 119a79cf0c0cff5e78c6d58faf27679417baf4c2 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Thu, 17 Aug 2017 17:01:47 +0100 Subject: [PATCH] Replace lxc-clone with lxc-copy (#19890) (#20373) The command lxc-clone is deprecated in favor of lxc-copy. This patch changes the lxc module to use the new lxc-copy command by default. If not present, it will fallback to the old lxc-clone command to keep it backward compatible with older versions of lxc. --- .../modules/cloud/lxc/lxc_container.py | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/cloud/lxc/lxc_container.py b/lib/ansible/modules/cloud/lxc/lxc_container.py index aef8365c0ee..ae8b196f8af 100644 --- a/lib/ansible/modules/cloud/lxc/lxc_container.py +++ b/lib/ansible/modules/cloud/lxc/lxc_container.py @@ -477,7 +477,15 @@ LXC_COMMAND_MAP = { } }, 'clone': { - 'variables': { + 'variables-lxc-copy': { + 'backing_store': '--backingstorage', + 'lxc_path': '--lxcpath', + 'fs_size': '--fssize', + 'name': '--name', + 'clone_name': '--newname' + }, + # lxc-clone is deprecated in favor of lxc-copy + 'variables-lxc-clone': { 'backing_store': '--backingstore', 'lxc_path': '--lxcpath', 'fs_size': '--fssize', @@ -788,13 +796,20 @@ class LxcContainerManagement(object): self.state_change = True self.container.stop() + # lxc-clone is deprecated in favor of lxc-copy + clone_vars = 'variables-lxc-copy' + clone_cmd = self.module.get_bin_path('lxc-copy') + if not clone_cmd: + clone_vars = 'variables-lxc-clone' + clone_cmd = self.module.get_bin_path('lxc-clone', True) + build_command = [ - self.module.get_bin_path('lxc-clone', True), + clone_cmd, ] build_command = self._add_variables( variables_dict=self._get_vars( - variables=LXC_COMMAND_MAP['clone']['variables'] + variables=LXC_COMMAND_MAP['clone'][clone_vars] ), build_command=build_command ) @@ -810,7 +825,7 @@ class LxcContainerManagement(object): rc, return_data, err = self._run_command(build_command) if rc != 0: - message = "Failed executing lxc-clone." + message = "Failed executing %s." % os.path.basename(clone_cmd) self.failure( err=err, rc=rc, msg=message, command=' '.join( build_command