ACI: Introduce port parameter (#35168)

* ACI: Introduce port parameter

* Add port parameter to documentation
pull/35179/head
Dag Wieers 7 years ago committed by GitHub
parent 46e53f90a7
commit 39aad91c5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -64,6 +64,7 @@ except ImportError:
def aci_argument_spec():
return dict(
hostname=dict(type='str', required=True, aliases=['host']),
port=dict(type='int', required=False),
username=dict(type='str', default='admin', aliases=['user']),
password=dict(type='str', no_log=True),
private_key=dict(type='path', aliases=['cert_key']), # Beware, this is not the same as client_key !
@ -214,7 +215,10 @@ class ACIModule(object):
''' Log in to APIC '''
# Perform login request
url = '%(protocol)s://%(hostname)s/api/aaaLogin.json' % self.params
if 'port' in self.params and self.params['port'] is not None:
url = '%(protocol)s://%(hostname)s:%(port)s/api/aaaLogin.json' % self.params
else:
url = '%(protocol)s://%(hostname)s/api/aaaLogin.json' % self.params
payload = {'aaaUser': {'attributes': {'name': self.params['username'], 'pwd': self.params['password']}}}
resp, auth = fetch_url(self.module, url,
data=json.dumps(payload),
@ -275,7 +279,11 @@ class ACIModule(object):
# Ensure method is set (only do this once)
self.define_method()
self.result['path'] = path
self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/')
if 'port' in self.params and self.params['port'] is not None:
self.result['url'] = '%(protocol)s://%(hostname)s:%(port)s/' % self.params + path.lstrip('/')
else:
self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/')
# Sign and encode request as to APIC's wishes
if self.params['private_key'] is not None:
@ -309,7 +317,11 @@ class ACIModule(object):
# Ensure method is set
self.result['path'] = path
self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/')
if 'port' in self.params and self.params['port'] is not None:
self.result['url'] = '%(protocol)s://%(hostname)s:%(port)s/' % self.params + path.lstrip('/')
else:
self.result['url'] = '%(protocol)s://%(hostname)s/' % self.params + path.lstrip('/')
# Sign and encode request as to APIC's wishes
if self.params['private_key'] is not None:
@ -382,7 +394,10 @@ class ACIModule(object):
path, filter_string = self._construct_url_1(root_class, child_includes)
self.result['path'] = path
self.result['url'] = '{0}://{1}/{2}'.format(self.module.params['protocol'], self.module.params['hostname'], path)
if 'port' in self.params and self.params['port'] is not None:
self.result['url'] = '{0}://{1}:{2}/{3}'.format(self.module.params['protocol'], self.module.params['hostname'], self.module.params['port'], path)
else:
self.result['url'] = '{0}://{1}/{2}'.format(self.module.params['protocol'], self.module.params['hostname'], path)
self.result['filter_string'] = filter_string
def _construct_url_1(self, obj, child_includes):

@ -28,6 +28,11 @@ options:
- IP Address or hostname of APIC resolvable by Ansible control host.
required: yes
aliases: [ host ]
port:
description:
- Port number to be used for REST connection.
default: 443 (for https) and 80 (for http)
type: int
username:
description:
- The username to use for authentication.

Loading…
Cancel
Save