Skip to content

Commit

Permalink
on extend - increasse duration instead of overwriting (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason-RH authored Dec 21, 2021
1 parent 5e5ccd9 commit 2be3891
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bonfire/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions bonfire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2be3891

Please sign in to comment.