Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update lxc_container to support py3 #5304

Merged
merged 5 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelogs/fragments/5280-lxc_container-py3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bugfixes:
- lxc_container - the module has been updated to support Python 3 (https://github.com/ansible-collections/community.general/pull/5304).

deprecated_features:
- lxc_container - the module will no longer make any effort to support Python 2 (https://github.com/ansible-collections/community.general/pull/5304).
19 changes: 9 additions & 10 deletions plugins/modules/cloud/lxc/lxc_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@
type: list
elements: str
requirements:
- 'lxc >= 1.0 # OS package'
- 'python >= 2.6 # OS Package'
- 'lxc-python2 >= 0.1 # PIP Package from https://github.com/lxc/python2-lxc'
- 'lxc >= 2.0 # OS package'
- 'python3 >= 3.5 # OS Package'
- 'python3-lxc # OS Package'
notes:
- Containers must have a unique name. If you attempt to create a container
with a name that already exists in the users namespace the module will
Expand All @@ -184,10 +184,10 @@
tarball of the running container. The "archive" option supports LVM backed
containers and will create a snapshot of the running container when
creating the archive.
- If your distro does not have a package for "python2-lxc", which is a
- If your distro does not have a package for C(python3-lxc), which is a
requirement for this module, it can be installed from source at
"https://github.com/lxc/python2-lxc" or installed via pip using the package
name lxc-python2.
U(https://github.com/lxc/python3-lxc) or installed via pip using the
package name C(lxc).
'''

EXAMPLES = r"""
Expand Down Expand Up @@ -434,7 +434,6 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE, BOOLEANS_TRUE
from ansible.module_utils.six.moves import xrange
from ansible.module_utils.common.text.converters import to_text, to_bytes


Expand Down Expand Up @@ -559,7 +558,7 @@
def create_script(command):
"""Write out a script onto a target.

This method should be backward compatible with Python 2.4+ when executing
This method should be backward compatible with Python when executing
from within the container.

:param command: command to run, this can be a script and can use spacing
Expand Down Expand Up @@ -939,7 +938,7 @@ def _container_startup(self, timeout=60):
"""

self.container = self.get_container_bind()
for dummy in xrange(timeout):
for dummy in range(timeout):
if self._get_state() != 'running':
self.container.start()
self.state_change = True
Expand Down Expand Up @@ -992,7 +991,7 @@ def _destroyed(self, timeout=60):
:type timeout: ``int``
"""

for dummy in xrange(timeout):
for dummy in range(timeout):
if not self._container_exists(container_name=self.container_name, lxc_path=self.lxc_path):
break

Expand Down