mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-04 15:29:10 -07:00
parent
1b8e6bc95b
commit
524d5883b8
19 changed files with 142 additions and 64 deletions
32
plugins/module_utils/datetime.py
Normal file
32
plugins/module_utils/datetime.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2023 Felix Fontein <felix@fontein.de>
|
||||
# Simplified BSD License (see LICENSES/BSD-2-Clause.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
# SPDX-License-Identifier: BSD-2-Clause
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import datetime as _datetime
|
||||
import sys
|
||||
|
||||
|
||||
_USE_TIMEZONE = sys.version_info >= (3, 6)
|
||||
|
||||
|
||||
def ensure_timezone_info(value):
|
||||
if not _USE_TIMEZONE or value.tzinfo is not None:
|
||||
return value
|
||||
return value.astimezone(_datetime.timezone.utc)
|
||||
|
||||
|
||||
def fromtimestamp(value):
|
||||
if _USE_TIMEZONE:
|
||||
return _datetime.fromtimestamp(value, tz=_datetime.timezone.utc)
|
||||
return _datetime.utcfromtimestamp(value)
|
||||
|
||||
|
||||
def now():
|
||||
if _USE_TIMEZONE:
|
||||
return _datetime.datetime.now(tz=_datetime.timezone.utc)
|
||||
return _datetime.datetime.utcnow()
|
|
@ -17,6 +17,10 @@ from ansible.module_utils.basic import env_fallback, missing_required_lib
|
|||
from ansible.module_utils.urls import fetch_url
|
||||
from ansible.module_utils.six.moves.urllib.parse import urlencode
|
||||
|
||||
from ansible_collections.community.general.plugins.module_utils.datetime import (
|
||||
now,
|
||||
)
|
||||
|
||||
SCALEWAY_SECRET_IMP_ERR = None
|
||||
try:
|
||||
from passlib.hash import argon2
|
||||
|
@ -306,10 +310,10 @@ class Scaleway(object):
|
|||
# Prevent requesting the resource status too soon
|
||||
time.sleep(wait_sleep_time)
|
||||
|
||||
start = datetime.datetime.utcnow()
|
||||
start = now()
|
||||
end = start + datetime.timedelta(seconds=wait_timeout)
|
||||
|
||||
while datetime.datetime.utcnow() < end:
|
||||
while now() < end:
|
||||
self.module.debug("We are going to wait for the resource to finish its transition")
|
||||
|
||||
state = self.fetch_state(resource)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue