1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

imc_rest: Increase default timeout, add elapsed time (#26743)

The IMC interface can be quite slow depending on the XML fragments used.
So we increase the default timeout to 60 seconds, and return the elapsed
time so it is easier to determine what timeout value makes sense from
earlier runs.

We also renamed **imc_xml** to **imc_rest**, now that we still can.
This commit is contained in:
Dag Wieers 2017-08-04 08:15:27 +02:00 committed by John R Barker
parent 8e8d4df340
commit d125520071
3 changed files with 65 additions and 19 deletions

2
.github/BOTMETA.yml vendored
View file

@ -562,7 +562,7 @@ files:
$modules/packaging/os/zypper_repository.py: matze robinro $modules/packaging/os/zypper_repository.py: matze robinro
$modules/remote_management/foreman/: ehelms $modules/remote_management/foreman/: ehelms
$modules/remote_management/hpilo/: dagwieers haad $modules/remote_management/hpilo/: dagwieers haad
$modules/remote_management/imc/imc_xml.py: dagwieers $modules/remote_management/imc/: dagwieers
$modules/remote_management/ipmi/: cloudnull $modules/remote_management/ipmi/: cloudnull
$modules/remote_management/stacki/stacki_host.py: bbyhuy bsanders $modules/remote_management/stacki/stacki_host.py: bbyhuy bsanders
$modules/remote_management/wakeonlan.py: dagwieers $modules/remote_management/wakeonlan.py: dagwieers

View file

@ -279,7 +279,7 @@ Ansible Changes By Release
* purefa_pg * purefa_pg
* purefa_volume * purefa_volume
- imc - imc
* imc_xml * imc_rest
- rundeck - rundeck
* rundeck_acl_policy * rundeck_acl_policy
* rundeck_project * rundeck_project

View file

@ -13,12 +13,12 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
DOCUMENTATION = r''' DOCUMENTATION = r'''
--- ---
module: imc_xml module: imc_rest
short_description: Manage Cisco IMC hardware through its XML API short_description: Manage Cisco IMC hardware through its REST API
description: description:
- Provides direct access to the Cisco IMC XML API. - Provides direct access to the Cisco IMC REST API.
- Perform any configuration changes and actions that the Cisco IMC supports. - Perform any configuration changes and actions that the Cisco IMC supports.
- More information about the IMC XML API is available from - More information about the IMC REST API is available from
U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html) U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html)
author: author:
- Dag Wieers (@dagwieers) - Dag Wieers (@dagwieers)
@ -44,16 +44,16 @@ options:
path: path:
description: description:
- Name of the absolute path of the filename that includes the body - Name of the absolute path of the filename that includes the body
of the http request being sent to the Cisco IMC XML API. of the http request being sent to the Cisco IMC REST API.
- Parameter C(path) is mutual exclusive with parameter C(content). - Parameter C(path) is mutual exclusive with parameter C(content).
aliases: [ src ] aliases: [ src ]
content: content:
description: description:
- When used instead of C(path), sets the content of the API requests directly. - When used instead of C(path), sets the content of the API requests directly.
- This may be convenient to template simple requests, for anything complex use the M(template) module. - This may be convenient to template simple requests, for anything complex use the M(template) module.
- You can add multiple IMC XML documents and they will be processed sequentially, - You can collate multiple IMC XML fragments and they will be processed sequentially in a single stream,
the Cisco IMC output is subsequently merged. the Cisco IMC output is subsequently merged.
- Parameter C(path) is mutual exclusive with parameter C(content). - Parameter C(content) is mutual exclusive with parameter C(path).
protocol: protocol:
description: description:
- Connection protocol to use. - Connection protocol to use.
@ -62,7 +62,10 @@ options:
timeout: timeout:
description: description:
- The socket level timeout in seconds. - The socket level timeout in seconds.
default: 30 - This is the time that every single connection (every fragment) can spend.
If this C(timeout) is reached, the module will fail with a
C(Connection failure) indicating that C(The read operation timed out).
default: 60
validate_certs: validate_certs:
description: description:
- If C(no), SSL certificates will not be validated. - If C(no), SSL certificates will not be validated.
@ -70,18 +73,20 @@ options:
type: bool type: bool
default: 'yes' default: 'yes'
notes: notes:
- The XML snippets don't need an authentication cookie, this is injected by the module automatically. - The XML fragments don't need an authentication cookie, this is injected by the module automatically.
- The Cisco IMC XML output is being translated to JSON using the Cobra convention. - The Cisco IMC XML output is being translated to JSON using the Cobra convention.
- Any configConfMo change requested has a return status of 'modified', even if there was no actual change - Any configConfMo change requested has a return status of 'modified', even if there was no actual change
from the previous configuration. As a result, this module will always report a change on subsequent runs. from the previous configuration. As a result, this module will always report a change on subsequent runs.
In case this behaviour is fixed in a future update to Cisco IMC, this module will automatically adapt. In case this behaviour is fixed in a future update to Cisco IMC, this module will automatically adapt.
- More information about the IMC XML API is available from - If you get a C(Connection failure) related to C(The read operation timed out) increase the C(timeout)
parameter. Some XML fragments can take longer than the default timeout.
- More information about the IMC REST API is available from
U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html) U(http://www.cisco.com/c/en/us/td/docs/unified_computing/ucs/c/sw/api/3_0/b_Cisco_IMC_api_301.html)
''' '''
EXAMPLES = r''' EXAMPLES = r'''
- name: Power down server - name: Power down server
imc_xml: imc_rest:
hostname: '{{ imc_hostname }}' hostname: '{{ imc_hostname }}'
username: '{{ imc_username }}' username: '{{ imc_username }}'
password: '{{ imc_password }}' password: '{{ imc_password }}'
@ -92,12 +97,13 @@ EXAMPLES = r'''
</inConfig></configConfMo> </inConfig></configConfMo>
delegate_to: localhost delegate_to: localhost
- name: Configure IMC using multiple XML documents - name: Configure IMC using multiple XML fragments
imc_xml: imc_rest:
hostname: '{{ imc_hostname }}' hostname: '{{ imc_hostname }}'
username: '{{ imc_username }}' username: '{{ imc_username }}'
password: '{{ imc_password }}' password: '{{ imc_password }}'
validate_certs: no validate_certs: no
timeout: 120
content: | content: |
<!-- Configure Serial-on-LAN --> <!-- Configure Serial-on-LAN -->
<configConfMo><inConfig> <configConfMo><inConfig>
@ -117,7 +123,7 @@ EXAMPLES = r'''
delegate_to: localhost delegate_to: localhost
- name: Enable PXE boot and power-cycle server - name: Enable PXE boot and power-cycle server
imc_xml: imc_rest:
hostname: '{{ imc_hostname }}' hostname: '{{ imc_hostname }}'
username: '{{ imc_username }}' username: '{{ imc_username }}'
password: '{{ imc_password }}' password: '{{ imc_password }}'
@ -135,7 +141,7 @@ EXAMPLES = r'''
delegate_to: localhost delegate_to: localhost
- name: Reconfigure IMC to boot from storage - name: Reconfigure IMC to boot from storage
imc_xml: imc_rest:
hostname: '{{ imc_host }}' hostname: '{{ imc_host }}'
username: '{{ imc_username }}' username: '{{ imc_username }}'
password: '{{ imc_password }}' password: '{{ imc_password }}'
@ -145,6 +151,35 @@ EXAMPLES = r'''
<lsbootStorage dn="sys/rack-unit-1/boot-policy/storage-read-write" access="read-write" order="1" type="storage"/> <lsbootStorage dn="sys/rack-unit-1/boot-policy/storage-read-write" access="read-write" order="1" type="storage"/>
</inConfig></configConfMo> </inConfig></configConfMo>
delegate_to: localhost delegate_to: localhost
- name: Add customer description to server
imc_rest:
hostname: '{{ imc_host }}'
username: '{{ imc_username }}'
password: '{{ imc_password }}'
validate_certs: no
content: |
<configConfMo><inConfig>
<computeRackUnit dn="sys/rack-unit-1" usrLbl="Customer Lab - POD{{ pod_id }} - {{ inventory_hostname_short }}"/>
</inConfig></configConfMo>
delegate_to: localhost
- name: Disable HTTP and increase session timeout to max value 10800 secs
imc_rest:
hostname: '{{ imc_host }}'
username: '{{ imc_username }}'
password: '{{ imc_password }}'
validate_certs: no
timeout: 120
content: |
<configConfMo><inConfig>
<commHttp dn="sys/svc-ext/http-svc" adminState="disabled"/>
</inConfig></configConfMo>
<configConfMo><inConfig>
<commHttps dn="sys/svc-ext/https-svc" adminState="enabled" sessionTimeout="10800"/>
</inConfig></configConfMo>
delegate_to: localhost
''' '''
RETURN = r''' RETURN = r'''
@ -163,10 +198,15 @@ aaLogin:
"response": "yes" "response": "yes"
} }
configConfMo: configConfMo:
description: Cisco IMC XML output for any configConfMo XML snipets, translated to JSON using Cobra convention description: Cisco IMC XML output for any configConfMo XML fragments, translated to JSON using Cobra convention
returned: success returned: success
type: dict type: dict
sample: | sample: |
elapsed:
description: Elapsed time in seconds
returned: always
type: int
sample: 31
response: response:
description: HTTP response message, including content length description: HTTP response message, including content length
returned: always returned: always
@ -219,6 +259,7 @@ output:
''' '''
import atexit import atexit
import datetime
import itertools import itertools
import os import os
@ -285,7 +326,7 @@ def main():
content=dict(type='str'), content=dict(type='str'),
path=dict(type='path', aliases=['config_file', 'src']), path=dict(type='path', aliases=['config_file', 'src']),
protocol=dict(type='str', default='https', choices=['http', 'https']), protocol=dict(type='str', default='https', choices=['http', 'https']),
timeout=dict(type='int', default=30), timeout=dict(type='int', default=60),
validate_certs=dict(type='bool', default=True), validate_certs=dict(type='bool', default=True),
), ),
supports_check_mode=True, supports_check_mode=True,
@ -315,11 +356,14 @@ def main():
else: else:
module.fail_json(msg='Cannot find/access path:\n%s' % path) module.fail_json(msg='Cannot find/access path:\n%s' % path)
start = datetime.datetime.utcnow()
# Perform login first # Perform login first
url = '%s://%s/nuova' % (protocol, hostname) url = '%s://%s/nuova' % (protocol, hostname)
data = '<aaaLogin inName="%s" inPassword="%s"/>' % (username, password) data = '<aaaLogin inName="%s" inPassword="%s"/>' % (username, password)
resp, auth = fetch_url(module, url, data=data, method='POST', timeout=timeout) resp, auth = fetch_url(module, url, data=data, method='POST', timeout=timeout)
if resp is None or auth['status'] != 200: if resp is None or auth['status'] != 200:
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % auth, **result) module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % auth, **result)
result.update(imc_response(module, resp.read())) result.update(imc_response(module, resp.read()))
@ -353,6 +397,7 @@ def main():
# Perform actual request # Perform actual request
resp, info = fetch_url(module, url, data=data, method='POST', timeout=timeout) resp, info = fetch_url(module, url, data=data, method='POST', timeout=timeout)
if resp is None or info['status'] != 200: if resp is None or info['status'] != 200:
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % info, **result) module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % info, **result)
# Merge results with previous results # Merge results with previous results
@ -368,6 +413,7 @@ def main():
result['changed'] = ('modified' in results) result['changed'] = ('modified' in results)
# Report success # Report success
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
module.exit_json(**result) module.exit_json(**result)
if __name__ == '__main__': if __name__ == '__main__':