server_config
This module represents everything that goes into server configuration
ServerStatus
Bases: Enum
Represents different states that a server can be in.
Attributes:
| Name | Type | Description |
|---|---|---|
RUNNING |
int
|
Indicates the server is running and operational. Numeric value: 0. |
NOT_INITIALIZED |
int
|
Indicates the server has not been initialized yet. Numeric value: 1. |
MISSING_CONTAINER |
int
|
Indicates the server is missing a required container. Numeric value: 2. |
NOT_RUNNING |
int
|
Indicates the server is not currently running. Numeric value: 3. |
ERROR |
int
|
Indicates the server encountered an error. Numeric value: 4. |
Source code in merlin/server/server_config.py
check_process_file_format(data)
Validates the format of a process file.
This function checks if the given process file data (in dictionary format) contains all the required keys: "parent_pid", "image_pid", "port", and "hostname".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict
|
The process file data to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the process file contains all required keys, False otherwise. |
Source code in merlin/server/server_config.py
config_merlin_server()
Configures the Merlin server with necessary settings, including username and password.
This function sets up the Merlin server by generating and storing a password file, creating a user file, and configuring Redis settings. If the password or user files already exist, it skips the respective setup steps. The function ensures that default and environment-specific users are added to the user file.
Source code in merlin/server/server_config.py
copy_container_command_files(config_dir)
Copies YAML files containing command instructions for container types to the specified configuration directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_dir
|
str
|
The path to the configuration directory where the YAML files will be copied. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if all files are successfully copied or already exist. False otherwise. |
Source code in merlin/server/server_config.py
create_server_config()
Creates the main configuration file for the Merlin server in the Merlin configuration directory.
This function checks for the existence of the Merlin configuration directory and creates a default
server configuration if none exists. It also copies necessary container command files, applies the
server configuration to app.yaml, and initializes the server configuration directory. If the
configuration already exists, it will not overwrite it.
Returns:
| Type | Description |
|---|---|
bool
|
True if the configuration is successfully created and applied. False otherwise. |
Source code in merlin/server/server_config.py
dump_process_file(data, file_path)
Writes process data to a specified file.
This function takes a dictionary containing process data and writes it to the specified
file path in YAML format. Before writing, the function validates the format of the data.
If the data format is invalid, the function returns False. If the operation is successful,
it returns True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dict
|
The process data to be written to the file. |
required |
file_path
|
str
|
The path to the file where the data will be written. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the data is successfully written to the file, False if the data format is invalid or the operation fails. |
Source code in merlin/server/server_config.py
generate_password(length, pass_command=None)
Generates a password for a Redis container.
If a specific command is provided, the password will be generated using the output of the given command. Otherwise, a random password will be created by combining characters (letters, digits, and special symbols) based on the specified length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
length
|
int
|
The desired length of the password. |
required |
pass_command
|
str
|
A shell command to generate the password. If provided, the command's output will be used as the password. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The generated password. |
Source code in merlin/server/server_config.py
get_server_status()
Determines the current status of the server.
This function checks the server's state by verifying the existence of necessary files, including configuration files, the container image, and the process file. It also checks if the server process is actively running.
Returns:
| Type | Description |
|---|---|
ServerStatus
|
An enum value representing the server's current state:
|
Source code in merlin/server/server_config.py
load_server_config(server_config)
Given a dictionary containing server configuration values, load them into a
ServerConfig instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
server_config
|
Dict
|
A dictionary containing server configuration values. Should have a 'container' entry and a 'process' entry. |
required |
Returns:
| Type | Description |
|---|---|
ServerConfig
|
A |
Source code in merlin/server/server_config.py
parse_redis_output(redis_stdout)
Parses the Redis output from a Redis container.
This function processes the Redis container's output to extract necessary information, such as configuration details and server state. It determines whether the server was successfully initialized and ready to accept connections, or if an error occurred.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
redis_stdout
|
BufferedReader
|
A buffered reader object containing the Redis container's output. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
A tuple containing:
|
Source code in merlin/server/server_config.py
pull_process_file(file_path)
Reads and parses data from a process file.
This function attempts to load the contents of a process file located at the specified
file path. If the file exists and its format is valid, the data is returned as a dictionary.
If the format is invalid or the file cannot be processed, None is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the process file. |
required |
Returns:
| Type | Description |
|---|---|
Dict
|
A dictionary containing the data from the process file if the format is valid. |
Source code in merlin/server/server_config.py
pull_server_config(app_yaml_path=None)
Retrieves the main configuration file and its corresponding format configuration file for the Merlin server.
This function reads the app.yaml configuration file and additional format-specific configuration files
to construct a complete configuration dictionary. It validates the presence of required keys in the format
and process configurations. If any required configuration is missing, an error is logged and None is returned.
Returns:
| Type | Description |
|---|---|
ServerConfig
|
An instance of |
Source code in merlin/server/server_config.py
pull_server_image()
Fetches the server image and ensures the necessary configuration files are in place.
This function retrieves the server image from a specified URL and saves it locally if it does not already exist. Additionally, it copies the default Redis configuration file to the appropriate location if it is missing. The function relies on the server configuration to determine the image URL, image path, and configuration file details.
Returns:
| Type | Description |
|---|---|
bool
|
True if the server image and configuration file are successfully set up, False if an error occurs. |