Unify unix_socket_path and url to the url parameter

This commit is contained in:
Hiroaki Nakamura 2016-06-30 22:36:58 +09:00
parent cc8b54d3cc
commit 8ba41ee6a2

View file

@ -123,17 +123,11 @@ options:
when it stops or restarts the container. when it stops or restarts the container.
required: false required: false
default: false default: false
unix_socket_path:
description:
- The unix domain socket path for the LXD server.
required: false
default: /var/lib/lxd/unix.socket
url: url:
description: description:
- The https URL for the LXD server. - The unix domain socket path or the https URL for the LXD server.
- If url is set, this module connects to the LXD server via https. required: false
If url it not set, this module connects to the LXD server via default: unix:/var/lib/lxd/unix.socket
unix domain socket specified with unix_socket_path.
key_file: key_file:
description: description:
- The client certificate key file path. - The client certificate key file path.
@ -383,19 +377,21 @@ class LxdContainerManagement(object):
self.wait_for_ipv4_addresses = self.module.params['wait_for_ipv4_addresses'] self.wait_for_ipv4_addresses = self.module.params['wait_for_ipv4_addresses']
self.force_stop = self.module.params['force_stop'] self.force_stop = self.module.params['force_stop']
self.addresses = None self.addresses = None
self.unix_socket_path = self.module.params['unix_socket_path'] self.url = self.module.params['url']
self.url = self.module.params.get('url', None)
self.key_file = self.module.params.get('key_file', None) self.key_file = self.module.params.get('key_file', None)
self.cert_file = self.module.params.get('cert_file', None) self.cert_file = self.module.params.get('cert_file', None)
self.trust_password = self.module.params.get('trust_password', None) self.trust_password = self.module.params.get('trust_password', None)
self.debug = self.module.params['debug'] self.debug = self.module.params['debug']
if self.url is None: if self.url.startswith('https:'):
self.connection = UnixHTTPConnection(self.unix_socket_path)
else:
parts = generic_urlparse(urlparse(self.url)) parts = generic_urlparse(urlparse(self.url))
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
ctx.load_cert_chain(self.cert_file, keyfile=self.key_file) ctx.load_cert_chain(self.cert_file, keyfile=self.key_file)
self.connection = HTTPSConnection(parts.get('netloc'), context=ctx) self.connection = HTTPSConnection(parts.get('netloc'), context=ctx)
elif self.url.startswith('unix:'):
unix_socket_path = self.url[len('unix:'):]
self.connection = UnixHTTPConnection(unix_socket_path)
else:
self.module.fail_json(msg='URL scheme must be unix: or https:')
self.logs = [] self.logs = []
self.actions = [] self.actions = []
@ -814,12 +810,9 @@ def main():
type='bool', type='bool',
default=False default=False
), ),
unix_socket_path=dict(
type='str',
default='/var/lib/lxd/unix.socket'
),
url=dict( url=dict(
type='str', type='str',
default='unix:/var/lib/lxd/unix.socket'
), ),
key_file=dict( key_file=dict(
type='str', type='str',