setup_sandbox_env() | Sandbox Container Utility | Teradata Python Package - 17.00 - setup_sandbox_env() - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

Use the setup_sandbox_env() function to load a sandbox image and start a new container, or start an existing container.

  • Teradata recommends running this function once before running the Script method test_script.
  • Sandbox image loading on user's system is skipped if the image is already loaded.
  • At any given point, only one container can be started from within teradataml.
  • At the end of a session, the image loaded and the container started by this function will be cleaned up.
  • Users also have the option to manually clean up the image and container using cleanup_sandbox_env().
User should be careful when providing sandbox_image_location and sandbox_image_name. If an incorrect sandbox_image_name is provided that does not match the name and tag of the image to be loaded, then:
  • The image will not be loaded. User should re-run the function with correct sandbox_image_name.
  • If the user's system already has an image that the image name and tag are the same as the image specified in sandbox_image_location, then the new image will be loaded and it might replace the old image.
Optional arguments:
  • To load a sandbox image and start a new container:
    • sandbox_image_location specifies the path to the sandbox image, including the image file name, on user's system.
    • sandbox_image_name specifies the name (tag) of the sandbox image

      This name (tag) is used to start a container.

      • sandbox_image_location and sandbox_image_name must be specified together.
      • After loading the image, a container will be created and started.
      • If the value provided to the argument sandbox_image_name does not match the name (tag) of the image to be loaded, the image will not be loaded. User needs to re-run this function with the correct sandbox_image_name value.
  • To start an existing container:

    container_id specifies the id of an existing Docker container.

    This argument is required, if the arguments sandbox_image_location and sandbox_image_name are not specified.
  • timeout specifies timeout value for docker API calls.

    This argument is useful when loading large sandbox images. The default value is 5000. Increase this value if image loading fails because of timeout.

Example 1: Load a sandbox image and start a new container

This example loads an image from the location specified in the sandbox_image_location argument and starts a container. This is useful when the user wants to setup sandbox environment with a new image.

  1. Import required module.
    >>> from teradataml.table_operators.sandbox_container_util import setup_sandbox_env
  2. Load sandbox image and start a container.
>>> setup_sandbox_env(sandbox_image_location='/tmp/stosandbox.tar.gz',
                              sandbox_image_name='stosandbox:1.0')    
	Loading image from /tmp/stosandbox.tar.gz. It may take few minutes.
    Image loaded successfully.
    Starting a container for stosandbox:1.0 image.
    Container c1dd4d4b722cc54b643ab2bdc57540a3a3e6db98c299defc672227de97d2c345 started successfully.

Example 2: Start an existing container

This example starts an existing container specified in the argument container_id. This is useful when the user wants to run user script in an existing container.

  1. Import required module.
    >>> from teradataml.table_operators.sandbox_container_util import setup_sandbox_env
  2. Load sandbox image and start a container.
    >>> setup_sandbox_env(container_id='3fadb1e8bac3')
        Container 3fadb1e8bac3 started successfully.