ACI: Introduce port parameter (#35168)

* ACI: Introduce port parameter

* Add port parameter to documentation
This commit is contained in:
Dag Wieers 2018-01-22 12:44:02 +01:00 committed by GitHub
parent 46e53f90a7
commit 39aad91c5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View file

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

View file

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