From c391f6cfb5e6ca441188ba0a6da702158ca6f37a Mon Sep 17 00:00:00 2001 From: Craig Willis Date: Mon, 30 Nov 2020 18:21:09 +0000 Subject: [PATCH 1/3] Unmount licenses --- gwvolman/tasks.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gwvolman/tasks.py b/gwvolman/tasks.py index 39dec607..71eb2392 100644 --- a/gwvolman/tasks.py +++ b/gwvolman/tasks.py @@ -338,6 +338,9 @@ def remove_volume(self, instanceId): logging.info("Unmounting %s", dest) subprocess.call("umount %s" % dest, shell=True) + logging.info("Unmounting licenses") + subprocess.call("umount /licenses", shell=True) + try: self.girder_client.delete('/dm/session/{sessionId}'.format(**instance)) except Exception as e: From 6e71fa779b55f746f508c104aadcbbf0bdc12419 Mon Sep 17 00:00:00 2001 From: Craig Willis Date: Mon, 2 Nov 2020 18:48:39 +0000 Subject: [PATCH 2/3] Added license handling for STATA --- gwvolman/utils.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/gwvolman/utils.py b/gwvolman/utils.py index 786c91d2..79fa0a46 100644 --- a/gwvolman/utils.py +++ b/gwvolman/utils.py @@ -12,6 +12,7 @@ import uuid import logging import docker +from datetime import datetime from .constants import LICENSE_PATH, MOUNTPOINTS, REPO2DOCKER_VERSION @@ -234,10 +235,20 @@ def _launch_container(volumeName, nodeId, container_config, tale_id='', instance ) host = 'tmp-{}'.format(new_user(12).lower()) - # Add licences mount for STATA and Matlab support - mounts.append( - docker.types.Mount(type="bind", source=LICENSE_PATH, target="/licenses") - ) + if container_config.buildpack: + # Mount the MATLAB and Stata runtime licenses + if container_config.buildpack == "MatlabBuildPack": + mounts.append( + docker.types.Mount(type='bind', + source=MATLAB_LICENSE_PATH, + target=MATLAB_LICENSE_PATH) + ) + elif container_config.buildpack == "StataBuildPack": + mounts.append( + docker.types.Mount(type='bind', + source="/licenses/stata/stata{}.lic".format(datetime.now().month), + target="/usr/local/stata/stata.lic") + ) # https://github.com/containous/traefik/issues/2582#issuecomment-354107053 endpoint_spec = docker.types.EndpointSpec(mode="vip") From e3dc3d3d953a4c8e328ffd0ece1563b61039d33c Mon Sep 17 00:00:00 2001 From: Craig Willis Date: Wed, 9 Dec 2020 18:48:30 +0000 Subject: [PATCH 3/3] Changed to actual weekly license format --- gwvolman/utils.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/gwvolman/utils.py b/gwvolman/utils.py index 79fa0a46..46195f2a 100644 --- a/gwvolman/utils.py +++ b/gwvolman/utils.py @@ -12,7 +12,8 @@ import uuid import logging import docker -from datetime import datetime +import datetime +import dateutil.relativedelta as rel from .constants import LICENSE_PATH, MOUNTPOINTS, REPO2DOCKER_VERSION @@ -240,14 +241,21 @@ def _launch_container(volumeName, nodeId, container_config, tale_id='', instance if container_config.buildpack == "MatlabBuildPack": mounts.append( docker.types.Mount(type='bind', - source=MATLAB_LICENSE_PATH, - target=MATLAB_LICENSE_PATH) + source=LICENSE_PATH, + target="/licenses") ) elif container_config.buildpack == "StataBuildPack": + # Weekly license expires each Sunday and is provided + # in the format stata.YYYYMMDD.lic where YYYYMMDD is the + # license expiration date. + license_date = datetime.date.today() + rel.relativedelta(days=1, weekday=rel.SU) + source_path = os.path.join( + LICENSE_PATH, "stata", f"stata.{license_date.strftime('%Y%m%d')}.lic" + ) mounts.append( - docker.types.Mount(type='bind', - source="/licenses/stata/stata{}.lic".format(datetime.now().month), - target="/usr/local/stata/stata.lic") + docker.types.Mount( + type='bind', source=source_path, target="/usr/local/stata/stata.lic" + ) ) # https://github.com/containous/traefik/issues/2582#issuecomment-354107053