Docker Commands
While GRID Enterprise’s CLI seamlessly handles Docker authentication and basic orchestration, advanced users may seek greater control and customization by interacting directly with Docker. The following Docker commands provide a deeper level of control over containers and their configurations.1. Monitor Container Logs
Monitoring container logs is crucial for debugging and ensuring that your applications are running smoothly. Command:-f: Follows the log output in real-time, allowing you to monitor logs as they are generated.
2. Access Container Shell
Accessing the container’s shell allows for in-depth troubleshooting and direct interaction with the container’s environment. Command:-i: Interactive mode.-t: Allocates a pseudo-TTY./bin/bash: Specifies the shell to use inside the container.
3. Inspect Container Details
Inspecting a container provides detailed information about its configuration, state, and resource usage, aiding in troubleshooting and optimization. Command:- Retrieves comprehensive details about the specified container in JSON format.
4. Monitor Container Resource Usage
Keeping track of a container’s resource consumption ensures that it operates efficiently without overusing system resources. Command:- Provides real-time statistics on CPU, memory, network, and disk usage for the specified container.
5. Update Docker Containers
Updating containers ensures that you have the latest features, security patches, and performance improvements. This process involves pulling the latest image, stopping and removing the existing container, and deploying a new one with the updated image. Steps to Update a Container:- Pull the Latest Image:
- Stop the Running Container:
- Remove the Existing Container:
- Run the Updated Container:
Data Storage
Images generated during sessions are saved inside the Docker container in the/app/images directory. To save an image using Python, use the following code snippet:
docker cp command as shown below:
grid_core and you want to copy images to /home/user/images, run:
/app/images directory to your specified host directory, allowing you to access and manage them outside the Docker environment.
API Reference
Apart from the CLI, which is meant to be an easy-to-use orchestration module for GRID sessions, the Enterprise also allows you to interact directly with GRID APIs to start/stop sessions. This section provides a detailed reference for the GRID Enterprise’sGRIDSessionManager class, which manages user sessions, including session creation, management, and termination. Below is a description of the class methods and their usage.
GRIDSessionManager Class
The GRIDSessionManager class handles session management for users, including generating JWT tokens, starting and stopping sessions, listing active sessions, and managing resource configurations.
Initialization:
Initializes a GRIDSessionManager instance by loading the resource configuration from ~/.grid/resource_config.json. If the configuration file does not exist, it prompts the user to input the necessary tokens and creates the configuration file.
Raises:
ValueError: If the configuration file does not contain'tokens'.
Method: load_resource_config
Loads the resource configuration from the default path ~/.grid/resource_config.json. If the file does not exist, it creates the directory and prompts the user to input the required tokens and resource details.
Returns:
Dict: The loaded resource configuration dictionary.
Method: generate_jwt_token
Generates a JWT token using the user ID and a predefined secret key.
Returns:
str: The generated JWT token.
Method: create_config
Creates a session configuration dictionary based on the provided session configuration file.
Parameters:
session_config_file_path(str): Path to the session configuration file containing AirGen and GRID settings.session_id(str): The unique identifier for the session.
Dict: A dictionary containing the combined session configuration.
ValueError: If the session configuration file does not contain'airgen'or'grid'settings.
Method: get_ip_for_resource
Retrieves the IP address for the specified resource name.
Parameters:
resource_name(str): The name of the resource.
Optional[str]: The IP address of the resource if found, otherwiseNone.
Method: start_session
Starts a new session by sending a request to the specified node IP.
Parameters:
session_id(str): The unique identifier for the session.session_config_file_path(str): Path to the session configuration file.node_ip(str): The IP address of the node where the session will be started.
Optional[bool]:Trueif the session was started successfully,Falseif it failed, orNoneif a request error occurs.
Method: stop_session
Stops an active session by sending a termination request to the associated node.
Parameters:
session_id(str): The unique identifier for the session to be stopped.
bool:Trueif the session was stopped successfully,Falseotherwise.
Method: list_sessions
Lists all active sessions, providing details such as session ID, node IP, and last active time.
Returns:
List[Dict]: A list of dictionaries containing session details, or an empty list if no active sessions are found.
Method: list_nodes
Lists all configured nodes with their corresponding IP addresses.
Returns:
None: Prints the list of nodes in a tabulated format. If no nodes are found, it notifies the user.
Usage Examples
Below are examples of how to use theGRIDSessionManager class.
Creating an Instance
Initializes aGRIDSessionManager instance.