def stop(): """Method to stop all containers Returns: None """ if ask_question( "Stop all Gigantum managed containers? MAKE SURE YOU HAVE SAVED YOUR WORK FIRST!" ): # remove any lingering gigantum managed containers _cleanup_containers() else: raise ExitCLI("Stop command cancelled")
def stop(): """Method to stop all containers Returns: None """ if ask_question( "Stop all containers? MAKE SURE YOU HAVE SAVED YOUR WORK FIRST!"): docker = DockerInterface() for container in docker.client.containers.list(): print('- stopping {}'.format(container.short_id)) container.stop() docker.client.containers.prune() else: raise ExitCLI("Stop command cancelled")
def stop(): """Method to stop all containers Returns: None """ if ask_question( "Stop all Gigantum managed containers? MAKE SURE YOU HAVE SAVED YOUR WORK FIRST!" ): docker = DockerInterface() # Stop any labbook containers for container in docker.client.containers.list(): if "gmlb-" in container.name: _, user, owner, labbook_name = container.name.split('-', 3) print('- Stopping container for LabBook: {}'.format( labbook_name)) container.stop() container.remove() # Stop app container try: app_container = docker.client.containers.get( "gigantum.labmanager-edge") print('- Stopping Gigantum app container') app_container.stop() app_container.remove() except NotFound: pass try: app_container = docker.client.containers.get("gigantum.labmanager") print('- Stopping Gigantum app container') app_container.stop() app_container.remove() except NotFound: pass # Do a container prune to make sure things are cleaned up docker.client.containers.prune() else: raise ExitCLI("Stop command cancelled")
def _print_installing_help(): """Print help for installing docker, taking OS into account Returns: str """ queried_system = platform.system() if queried_system == 'Linux': if ask_question( "Docker isn't installed. Would you like to try to install it now?" ): installer_path = os.path.expanduser('~/get-docker.sh') resp = requests.get('https://get.docker.com/') with open(installer_path, 'wb') as file_handle: file_handle.write(resp.content) print_cmd = "An installer script has been downloaded to {}:\n".format( installer_path) print_cmd = "{}- Run `sudo sh ~/get-docker.sh`\n".format( print_cmd) print_cmd = "{}- Wait for installer to complete\n".format( print_cmd) print_cmd = "{}- Run `sudo usermod -aG docker <your-user-name>`\n".format( print_cmd) print_cmd = "{} - This lets you run Docker commands not as root\n".format( print_cmd) print_cmd = "{}- Log out and then log back in\n".format( print_cmd) else: raise ExitCLI( "You must install Docker to use the Gigantum application") elif queried_system == 'Darwin': print_cmd = "Docker isn't installed. Get the Docker for Mac app here: " print_cmd = "{}\n\n https://docs.docker.com/docker-for-mac/install/ \n\n".format( print_cmd) print_cmd = "{}- Install the `Stable Channel` version.\n".format( print_cmd) print_cmd = "{}- You can change the amount of RAM and CPU allocated to Docker from".format( print_cmd) print_cmd = "{} the preferences menu that is available when clicking on the Docker logo".format( print_cmd) print_cmd = "{} in the OSX taskbar.\n".format(print_cmd) print_cmd = "{}- Be sure to sign-in to DockerHub by clicking on Sign-In\n".format( print_cmd) print_cmd = "{}- You don't need to leave Docker running all the time, but it must be".format( print_cmd) print_cmd = "{} running before you start the Gigantum application\n".format( print_cmd) elif queried_system == 'Windows': print_cmd = "Docker isn't installed!\n" print_cmd = "{}If you have 64bit Windows 10 Pro, install Docker for Windows app here:".format( print_cmd) print_cmd = "{}\n\n https://docs.docker.com/docker-for-windows/install/ \n\n".format( print_cmd) print_cmd = "{}- Install the `Stable Channel` version.\n".format( print_cmd) print_cmd = "{}- You can change the amount of RAM and CPU allocated to Docker from".format( print_cmd) print_cmd = "{} the preferences menu that is available when clicking on the Docker logo".format( print_cmd) print_cmd = "{} in the notification area.\n".format(print_cmd) print_cmd = "{}- Be sure to sign-in to DockerHub by clicking on Sign-In\n".format( print_cmd) print_cmd = "{}- You don't need to leave Docker running all the time, but it must be".format( print_cmd) print_cmd = "{} running before you start the Gigantum application\n".format( print_cmd) print_cmd = "{}\nIf you have an old version of Windows, you can still use Docker Toolbox:".format( print_cmd) print_cmd = "{}\n\n https://docs.docker.com/toolbox/overview/ \n\n".format( print_cmd) else: raise ValueError("Unsupported OS: {}".format(queried_system)) print(print_cmd)
def update(tag=None): """Method to update the existing image, warning about changes before accepting Args: tag(str): Tag to pull if you wish to override `latest` Returns: None """ docker = DockerInterface() try: cl = ChangeLog() if not tag: # Trying to update to the latest version tag = 'latest' # Get id of current labmanager install try: current_image = docker.client.images.get( "gigantum/labmanager:latest") except ImageNotFound: raise ExitCLI( "Gigantum Image not yet installed. Run 'gigantum install' first." ) short_id = current_image.short_id.split(':')[1] # Check if there is an update available if not cl.is_update_available(short_id): print("Latest version already installed.") sys.exit(0) # Get Changelog info for the latest or specified version try: print(cl.get_changelog(tag)) except ValueError as err: raise ExitCLI(err) # Make sure user wants to pull if ask_question("Are you sure you want to update?"): # Pull print( "\nDownloading and installing the Gigantum Docker Image. Please wait...\n" ) image = docker.client.images.pull('gigantum/labmanager', tag) # If pulling not truly latest, force to latest if tag != 'latest': print("Tagging explicit version {} with latest".format(tag)) docker.client.api.tag('gigantum/labmanager:{}'.format(tag), 'gigantum/labmanager', 'latest') else: raise ExitCLI("Update cancelled") except APIError: msg = "ERROR: failed to pull image!" msg += "\n- Are you signed into DockerHub?" msg += "\n- Do you have access to gigantum/labmanager? If not, contact Gigantum." msg += "\n - Can test by going here: https://hub.docker.com/r/gigantum/labmanager/" msg += "\n - If you see `404 Not Found`, request access\n" raise ExitCLI(msg) short_id = image.short_id.split(':')[1] print("\nSuccessfully pulled gigantum/labmanager:{}\n".format(short_id))
def update(image_name, tag=None): """Method to update the existing image, warning about changes before accepting Args: image_name(str): Image name, including repository and namespace (e.g. gigantum/labmanager) tag(str): Tag to pull if you wish to override `latest` Returns: None """ # Make sure user is not root if is_running_as_admin(): raise ExitCLI("Do not run `gigantum update` as root.") docker = DockerInterface() try: cl = ChangeLog() if "edge" not in image_name: # Normal install, so do checks if not tag: # Trying to update to the latest version tag = 'latest' # Get id of current labmanager install try: current_image = docker.client.images.get( "{}:latest".format(image_name)) except ImageNotFound: raise ExitCLI( "Gigantum Client image not yet installed. Run 'gigantum install' first." ) short_id = current_image.short_id.split(':')[1] # Check if there is an update available if not cl.is_update_available(short_id): print("Latest version already installed.") sys.exit(0) # Get Changelog info for the latest or specified version try: print(cl.get_changelog(tag)) except ValueError as err: raise ExitCLI(err) else: # Edge build, set tag if needed if not tag: # Trying to update to the latest version tag = 'latest' # Make sure user wants to pull if ask_question("Are you sure you want to update?"): # Pull print( "\nDownloading and installing the Gigantum Client Docker Image. Please wait...\n" ) image = docker.client.images.pull(image_name, tag) # If pulling not truly latest, force to latest if tag != 'latest': print("Tagging explicit version {} with latest".format(tag)) docker.client.api.tag('{}:{}'.format(tag, image_name), image_name, 'latest') else: raise ExitCLI("Update cancelled") except APIError: msg = "ERROR: failed to pull image!" msg += "\n- Are you signed into DockerHub?" msg += "\n- Do you have access to {}? If not, contact Gigantum.".format( image_name) msg += "\n - Can test by going here: https://hub.docker.com/r/gigantum/labmanager/" msg += "\n - If you see `404 Not Found`, request access\n" raise ExitCLI(msg) short_id = image.short_id.split(':')[1] print("\nSuccessfully pulled {}:{}\n".format(image_name, short_id))