Fix url handling in lxd_container and lxd_profile module (#66097)

* Fix url handling in lxd_container module

* Fix url handling in lxd_profile module
pull/67442/head
tottoto 4 years ago committed by GitHub
parent eaf879a7a7
commit cc86748109
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- Fixes the url handling in lxd_container module that url cannot be specified in lxd environment created by snap.

@ -0,0 +1,2 @@
bugfixes:
- Fixes the url handling in lxd_profile module that url cannot be specified in lxd environment created by snap.

@ -300,6 +300,9 @@ ANSIBLE_LXD_STATES = {
'Frozen': 'frozen',
}
# ANSIBLE_LXD_DEFAULT_URL is a default value of the lxd endpoint
ANSIBLE_LXD_DEFAULT_URL = 'unix:/var/lib/lxd/unix.socket'
# CONFIG_PARAMS is a list of config attribute names.
CONFIG_PARAMS = [
'architecture', 'config', 'devices', 'ephemeral', 'profiles', 'source'
@ -329,7 +332,9 @@ class LXDContainerManagement(object):
self.debug = self.module._verbosity >= 4
try:
if os.path.exists(self.module.params['snap_url'].replace('unix:', '')):
if self.module.params['url'] != ANSIBLE_LXD_DEFAULT_URL:
self.url = self.module.params['url']
elif os.path.exists(self.module.params['snap_url'].replace('unix:', '')):
self.url = self.module.params['snap_url']
else:
self.url = self.module.params['url']
@ -623,7 +628,7 @@ def main():
),
url=dict(
type='str',
default='unix:/var/lib/lxd/unix.socket'
default=ANSIBLE_LXD_DEFAULT_URL
),
snap_url=dict(
type='str',

@ -182,6 +182,8 @@ import os
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.lxd import LXDClient, LXDClientException
# ANSIBLE_LXD_DEFAULT_URL is a default value of the lxd endpoint
ANSIBLE_LXD_DEFAULT_URL = 'unix:/var/lib/lxd/unix.socket'
# PROFILE_STATES is a list for states supported
PROFILES_STATES = [
@ -212,7 +214,9 @@ class LXDProfileManagement(object):
self.debug = self.module._verbosity >= 4
try:
if os.path.exists(self.module.params['snap_url'].replace('unix:', '')):
if self.module.params['url'] != ANSIBLE_LXD_DEFAULT_URL:
self.url = self.module.params['url']
elif os.path.exists(self.module.params['snap_url'].replace('unix:', '')):
self.url = self.module.params['snap_url']
else:
self.url = self.module.params['url']
@ -366,7 +370,7 @@ def main():
),
url=dict(
type='str',
default='unix:/var/lib/lxd/unix.socket'
default=ANSIBLE_LXD_DEFAULT_URL
),
snap_url=dict(
type='str',

Loading…
Cancel
Save