mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Unhardcode the port and protocol on eos EAPI (#23350)
We were hard-coding the protocol, port and validate_certs on eos EAPI via the action plugin. Put defaults on the eos_argument_spec and pull those values from it.
This commit is contained in:
parent
5f4673b5ae
commit
3537b24742
2 changed files with 11 additions and 14 deletions
|
@ -40,8 +40,7 @@ _DEVICE_CONNECTION = None
|
||||||
|
|
||||||
eos_argument_spec = {
|
eos_argument_spec = {
|
||||||
'host': dict(),
|
'host': dict(),
|
||||||
'port': dict(type='int'),
|
'port': dict(type='int', default=443),
|
||||||
|
|
||||||
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
|
'username': dict(fallback=(env_fallback, ['ANSIBLE_NET_USERNAME'])),
|
||||||
'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
|
'password': dict(fallback=(env_fallback, ['ANSIBLE_NET_PASSWORD']), no_log=True),
|
||||||
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
|
'ssh_keyfile': dict(fallback=(env_fallback, ['ANSIBLE_NET_SSH_KEYFILE']), type='path'),
|
||||||
|
@ -50,8 +49,8 @@ eos_argument_spec = {
|
||||||
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
|
'authorize': dict(fallback=(env_fallback, ['ANSIBLE_NET_AUTHORIZE']), type='bool'),
|
||||||
'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
|
'auth_pass': dict(no_log=True, fallback=(env_fallback, ['ANSIBLE_NET_AUTH_PASS'])),
|
||||||
|
|
||||||
'use_ssl': dict(type='bool'),
|
'use_ssl': dict(type='bool', default=True),
|
||||||
'validate_certs': dict(type='bool'),
|
'validate_certs': dict(type='bool', default=True),
|
||||||
'timeout': dict(type='int'),
|
'timeout': dict(type='int'),
|
||||||
|
|
||||||
'provider': dict(type='dict', no_log=True),
|
'provider': dict(type='dict', no_log=True),
|
||||||
|
@ -236,20 +235,18 @@ class Eapi:
|
||||||
self._session_support = None
|
self._session_support = None
|
||||||
self._device_configs = {}
|
self._device_configs = {}
|
||||||
|
|
||||||
host = module.params['host']
|
host = module.params['provider']['host']
|
||||||
port = module.params['port']
|
port = module.params['provider']['port']
|
||||||
|
|
||||||
self._module.params['url_username'] = self._module.params['username']
|
self._module.params['url_username'] = self._module.params['username']
|
||||||
self._module.params['url_password'] = self._module.params['password']
|
self._module.params['url_password'] = self._module.params['password']
|
||||||
|
|
||||||
if module.params['use_ssl']:
|
if module.params['provider']['use_ssl']:
|
||||||
proto = 'https'
|
proto = 'https'
|
||||||
if not port:
|
|
||||||
port = 443
|
|
||||||
else:
|
else:
|
||||||
proto = 'http'
|
proto = 'http'
|
||||||
if not port:
|
|
||||||
port = 80
|
module.params['validate_certs'] = module.params['provider']['validate_certs']
|
||||||
|
|
||||||
self._url = '%s://%s:%s/command-api' % (proto, host, port)
|
self._url = '%s://%s:%s/command-api' % (proto, host, port)
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ class ActionModule(_ActionModule):
|
||||||
provider['host'] = self._play_context.remote_addr
|
provider['host'] = self._play_context.remote_addr
|
||||||
|
|
||||||
if provider.get('port') is None:
|
if provider.get('port') is None:
|
||||||
provider['port'] = 443
|
provider['port'] = eos_argument_spec['port']['default']
|
||||||
|
|
||||||
if provider.get('timeout') is None:
|
if provider.get('timeout') is None:
|
||||||
provider['timeout'] = self._play_context.timeout
|
provider['timeout'] = self._play_context.timeout
|
||||||
|
@ -110,10 +110,10 @@ class ActionModule(_ActionModule):
|
||||||
provider['authorize'] = False
|
provider['authorize'] = False
|
||||||
|
|
||||||
if provider.get('use_ssl') is None:
|
if provider.get('use_ssl') is None:
|
||||||
provider['use_ssl'] = True
|
provider['use_ssl'] = eos_argument_spec['use_ssl']['default']
|
||||||
|
|
||||||
if provider.get('validate_certs') is None:
|
if provider.get('validate_certs') is None:
|
||||||
provider['validate_certs'] = True
|
provider['validate_certs'] = eos_argument_spec['validate_certs']['default']
|
||||||
|
|
||||||
self._task.args['provider'] = provider
|
self._task.args['provider'] = provider
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue