mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Revert "[PR #7980/74c15c12 backport][stable-7] Updates lxd_container
to support new LXD API (#8045)"
This reverts commit 8b2e658fc0
.
(Considering this again, this looks a lot more like a feature than a bugfix. I shouldn't have backported it.)
This commit is contained in:
parent
5c80ff00ab
commit
36edaaa6ea
2 changed files with 9 additions and 18 deletions
|
@ -1,2 +0,0 @@
|
||||||
minor_changes:
|
|
||||||
- "lxd_container - uses ``/1.0/instances`` API endpoint, if available. Falls back to ``/1.0/containers`` or ``/1.0/virtual-machines``. Fixes issue when using Incus or LXD 5.19 due to migrating to ``/1.0/instances`` endpoint (https://github.com/ansible-collections/community.general/pull/7980)."
|
|
|
@ -436,12 +436,12 @@ ANSIBLE_LXD_DEFAULT_URL = 'unix:/var/lib/lxd/unix.socket'
|
||||||
|
|
||||||
# CONFIG_PARAMS is a list of config attribute names.
|
# CONFIG_PARAMS is a list of config attribute names.
|
||||||
CONFIG_PARAMS = [
|
CONFIG_PARAMS = [
|
||||||
'architecture', 'config', 'devices', 'ephemeral', 'profiles', 'source', 'type'
|
'architecture', 'config', 'devices', 'ephemeral', 'profiles', 'source'
|
||||||
]
|
]
|
||||||
|
|
||||||
# CONFIG_CREATION_PARAMS is a list of attribute names that are only applied
|
# CONFIG_CREATION_PARAMS is a list of attribute names that are only applied
|
||||||
# on instance creation.
|
# on instance creation.
|
||||||
CONFIG_CREATION_PARAMS = ['source', 'type']
|
CONFIG_CREATION_PARAMS = ['source']
|
||||||
|
|
||||||
|
|
||||||
class LXDContainerManagement(object):
|
class LXDContainerManagement(object):
|
||||||
|
@ -467,6 +467,13 @@ class LXDContainerManagement(object):
|
||||||
|
|
||||||
self.type = self.module.params['type']
|
self.type = self.module.params['type']
|
||||||
|
|
||||||
|
# LXD Rest API provides additional endpoints for creating containers and virtual-machines.
|
||||||
|
self.api_endpoint = None
|
||||||
|
if self.type == 'container':
|
||||||
|
self.api_endpoint = '/1.0/containers'
|
||||||
|
elif self.type == 'virtual-machine':
|
||||||
|
self.api_endpoint = '/1.0/virtual-machines'
|
||||||
|
|
||||||
self.key_file = self.module.params.get('client_key')
|
self.key_file = self.module.params.get('client_key')
|
||||||
if self.key_file is None:
|
if self.key_file is None:
|
||||||
self.key_file = '{0}/.config/lxc/client.key'.format(os.environ['HOME'])
|
self.key_file = '{0}/.config/lxc/client.key'.format(os.environ['HOME'])
|
||||||
|
@ -492,18 +499,6 @@ class LXDContainerManagement(object):
|
||||||
)
|
)
|
||||||
except LXDClientException as e:
|
except LXDClientException as e:
|
||||||
self.module.fail_json(msg=e.msg)
|
self.module.fail_json(msg=e.msg)
|
||||||
|
|
||||||
# LXD (3.19) Rest API provides instances endpoint, failback to containers and virtual-machines
|
|
||||||
# https://documentation.ubuntu.com/lxd/en/latest/rest-api/#instances-containers-and-virtual-machines
|
|
||||||
self.api_endpoint = '/1.0/instances'
|
|
||||||
check_api_endpoint = self.client.do('GET', '{0}?project='.format(self.api_endpoint), ok_error_codes=[404])
|
|
||||||
|
|
||||||
if check_api_endpoint['error_code'] == 404:
|
|
||||||
if self.type == 'container':
|
|
||||||
self.api_endpoint = '/1.0/containers'
|
|
||||||
elif self.type == 'virtual-machine':
|
|
||||||
self.api_endpoint = '/1.0/virtual-machines'
|
|
||||||
|
|
||||||
self.trust_password = self.module.params.get('trust_password', None)
|
self.trust_password = self.module.params.get('trust_password', None)
|
||||||
self.actions = []
|
self.actions = []
|
||||||
self.diff = {'before': {}, 'after': {}}
|
self.diff = {'before': {}, 'after': {}}
|
||||||
|
@ -556,8 +551,6 @@ class LXDContainerManagement(object):
|
||||||
url = '{0}?{1}'.format(url, urlencode(url_params))
|
url = '{0}?{1}'.format(url, urlencode(url_params))
|
||||||
config = self.config.copy()
|
config = self.config.copy()
|
||||||
config['name'] = self.name
|
config['name'] = self.name
|
||||||
if self.type not in self.api_endpoint:
|
|
||||||
config['type'] = self.type
|
|
||||||
if not self.module.check_mode:
|
if not self.module.check_mode:
|
||||||
self.client.do('POST', url, config, wait_for_container=self.wait_for_container)
|
self.client.do('POST', url, config, wait_for_container=self.wait_for_container)
|
||||||
self.actions.append('create')
|
self.actions.append('create')
|
||||||
|
|
Loading…
Reference in a new issue