diff --git a/bonfire/namespaces.py b/bonfire/namespaces.py index 4c5948a9..99be26c6 100644 --- a/bonfire/namespaces.py +++ b/bonfire/namespaces.py @@ -14,7 +14,7 @@ whoami, ) from bonfire.processor import process_reservation -from bonfire.utils import FatalError +from bonfire.utils import FatalError, hms_to_seconds log = logging.getLogger(__name__) @@ -279,10 +279,14 @@ def extend_namespace(namespace, duration): res["status"]["namespace"], ) return None + + prev_duration = hms_to_seconds(res["spec"]["duration"]) + new_duration = prev_duration + hms_to_seconds(duration) + res_config = process_reservation( res["metadata"]["name"], res["spec"]["requester"], - duration, + _pretty_time_delta(new_duration), ) log.debug("processed reservation:\n%s", res_config) diff --git a/bonfire/utils.py b/bonfire/utils.py index f650e42d..3632b017 100644 --- a/bonfire/utils.py +++ b/bonfire/utils.py @@ -501,3 +501,22 @@ def check_pypi(): log.error("unable to parse version info from pypi") else: _compare_version(pypi_version) + + +def hms_to_seconds(s): + fmt = r"^(\d+h)?(\d+m)?(\d+s)?$" + + l = re.split(fmt, s) + + seconds = 0 + + for group in l: + if group: # to ignore 'None' groups when all units aren't present + if 'h' in group: + seconds += int(group.split('h')[0])*3600 + elif 'm' in group: + seconds += int(group.split('m')[0])*60 + elif 's' in group: + seconds += int(group.split('s')[0]) + + return seconds