mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 14:59:09 -07:00
[PR #8222/524d5883 backport][stable-8] Avoid deprecated utcnow() (#8243)
Avoid deprecated utcnow() (#8222)
Avoid deprecated utcnow().
(cherry picked from commit 524d5883b8
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
83738f21a3
commit
4832100d76
19 changed files with 142 additions and 64 deletions
|
@ -268,7 +268,6 @@ output:
|
|||
errorDescr="XML PARSING ERROR: Element 'computeRackUnit', attribute 'admin_Power': The attribute 'admin_Power' is not allowed.\n"/>
|
||||
'''
|
||||
|
||||
import datetime
|
||||
import os
|
||||
import traceback
|
||||
|
||||
|
@ -292,6 +291,10 @@ from ansible.module_utils.basic import AnsibleModule, missing_required_lib
|
|||
from ansible.module_utils.six.moves import zip_longest
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.datetime import (
|
||||
now,
|
||||
)
|
||||
|
||||
|
||||
def imc_response(module, rawoutput, rawinput=''):
|
||||
''' Handle IMC returned data '''
|
||||
|
@ -375,14 +378,14 @@ def main():
|
|||
else:
|
||||
module.fail_json(msg='Cannot find/access path:\n%s' % path)
|
||||
|
||||
start = datetime.datetime.utcnow()
|
||||
start = now()
|
||||
|
||||
# Perform login first
|
||||
url = '%s://%s/nuova' % (protocol, hostname)
|
||||
data = '<aaaLogin inName="%s" inPassword="%s"/>' % (username, password)
|
||||
resp, auth = fetch_url(module, url, data=data, method='POST', timeout=timeout)
|
||||
if resp is None or auth['status'] != 200:
|
||||
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
|
||||
result['elapsed'] = (now() - start).seconds
|
||||
module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % auth, **result)
|
||||
result.update(imc_response(module, resp.read()))
|
||||
|
||||
|
@ -415,7 +418,7 @@ def main():
|
|||
# Perform actual request
|
||||
resp, info = fetch_url(module, url, data=data, method='POST', timeout=timeout)
|
||||
if resp is None or info['status'] != 200:
|
||||
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
|
||||
result['elapsed'] = (now() - start).seconds
|
||||
module.fail_json(msg='Task failed with error %(status)s: %(msg)s' % info, **result)
|
||||
|
||||
# Merge results with previous results
|
||||
|
@ -431,7 +434,7 @@ def main():
|
|||
result['changed'] = ('modified' in results)
|
||||
|
||||
# Report success
|
||||
result['elapsed'] = (datetime.datetime.utcnow() - start).seconds
|
||||
result['elapsed'] = (now() - start).seconds
|
||||
module.exit_json(**result)
|
||||
finally:
|
||||
logout(module, url, cookie, timeout)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue