DB2 Module
The db2 module provides functions for DB2 database configuration and validation.
db2
Functions
get_db2u_instance_cr(custom_objects_api, mas_instance_id, mas_app_id, database_role='primary')
Retrieve the Db2uInstance custom resource for a specific MAS application database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_objects_api
|
CustomObjectsApi
|
Kubernetes custom objects API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The Db2uInstance custom resource as a dictionary |
Raises:
| Type | Description |
|---|---|
ApiException
|
If the custom resource is not found or cannot be retrieved |
Source code in src/mas/devops/db2.py
db2_pod_exec(core_v1_api, mas_instance_id, mas_app_id, command, database_role='primary')
Execute a command in a DB2 pod for a specific MAS application database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core_v1_api
|
CoreV1Api
|
Kubernetes Core V1 API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
command
|
list
|
The command to execute as a list of strings |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The standard output from the command execution |
Raises:
| Type | Description |
|---|---|
Exception
|
If the command execution fails |
Source code in src/mas/devops/db2.py
db2_pod_exec_db2_get_db_cfg(core_v1_api, mas_instance_id, mas_app_id, db_name, database_role='primary')
Execute 'db2 get db cfg' command in a DB2 pod to retrieve database configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core_v1_api
|
CoreV1Api
|
Kubernetes Core V1 API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
db_name
|
str
|
The name of the database to query |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The output of the 'db2 get db cfg' command |
Raises:
| Type | Description |
|---|---|
Exception
|
If the command execution fails |
Source code in src/mas/devops/db2.py
db2_pod_exec_db2_get_dbm_cfg(core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Execute 'db2 get dbm cfg' command in a DB2 pod to retrieve database manager configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core_v1_api
|
CoreV1Api
|
Kubernetes Core V1 API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The output of the 'db2 get dbm cfg' command |
Raises:
| Type | Description |
|---|---|
Exception
|
If the command execution fails |
Source code in src/mas/devops/db2.py
db2_pod_exec_db2set(core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Execute 'db2set' command in a DB2 pod to retrieve registry configuration variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
core_v1_api
|
CoreV1Api
|
Kubernetes Core V1 API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The output of the 'db2set' command |
Raises:
| Type | Description |
|---|---|
Exception
|
If the command execution fails |
Source code in src/mas/devops/db2.py
cr_pod_v_matches(cr_k, cr_v, pod_v)
Compare a configuration value from the Db2uInstance CR with the actual value from the DB2 pod.
This function handles special cases where the CR and pod values are expressed differently even when they represent the same configuration (e.g., "8192 AUTOMATIC" vs "AUTOMATIC(8192)").
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cr_k
|
str
|
The configuration parameter key/name |
required |
cr_v
|
str
|
The configuration value from the Db2uInstance CR |
required |
pod_v
|
str
|
The actual configuration value from the DB2 pod |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the values match (considering special cases), False otherwise |
Source code in src/mas/devops/db2.py
check_db_cfgs(db2u_instance_cr, core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Runs check_db_cfg for each database in the provided Db2uInstance CR
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db2u_instance_cr
|
dict
|
the Db2uInstanceCR as a dict (use get_db2u_instance_cr) |
required |
core_v1_api
|
CoreV1Api
|
The Kubernetes API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance. |
required |
mas_app_id
|
str
|
The ID of the MAS app the DB2 database is for (e.g. "manage", "iot") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The outputs of each call to check_db_cfg concatenated together |
Source code in src/mas/devops/db2.py
check_db_cfg(db_dr, core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Check that the parameters in the provided db dict taken from the Db2uInstance CR align with those in the output of the db2 get db cfg command (i.e. the configuration that is actually active in DB2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_dr
|
dict
|
one element under spec.environment.databases taken from the Db2uInstance CR |
required |
core_v1_api
|
CoreV1Api
|
The Kubernetes API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance. |
required |
mas_app_id
|
str
|
The ID of the MAS app the DB2 database is for (e.g. "manage", "iot") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of strings describing any mismatches found between the CR and active DB2 configuration. Any empty list implies all configuration matches. |
Source code in src/mas/devops/db2.py
check_dbm_cfg(db2u_instance_cr, core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Check that the database manager (dbmConfig) parameters from the Db2uInstance CR align with those in the output of the db2 get dbm cfg command (i.e. the configuration that is actually active in DB2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db2u_instance_cr
|
dict
|
the Db2uInstanceCR as a dict (use get_db2u_instance_cr) |
required |
core_v1_api
|
CoreV1Api
|
The Kubernetes API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance. |
required |
mas_app_id
|
str
|
The ID of the MAS app the DB2 database is for (e.g. "manage", "iot") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of strings describing any mismatches found between the CR and active DB2 configuration. Any empty list implies all configuration matches. |
Source code in src/mas/devops/db2.py
check_reg_cfg(db2u_instance_cr, core_v1_api, mas_instance_id, mas_app_id, database_role='primary')
Check that the registry parameters from the Db2uInstance CR align with those in the output of the db2set command (i.e. the configuration that is actually active in DB2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db2u_instance_cr
|
dict
|
the Db2uInstanceCR as a dict (use get_db2u_instance_cr) |
required |
core_v1_api
|
CoreV1Api
|
The Kubernetes API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance. |
required |
mas_app_id
|
str
|
The ID of the MAS app the DB2 database is for (e.g. "manage", "iot") |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of strings describing any mismatches found between the CR and active DB2 configuration. Any empty list implies all configuration matches. |
Source code in src/mas/devops/db2.py
validate_db2_config(k8s_client, mas_instance_id, mas_app_id, database_role='primary')
Validate that the DB2 configuration in the Db2uInstance CR matches the actual configuration in the DB2 pods.
This function orchestrates validation of database configuration (db cfg), database manager configuration (dbm cfg), and registry configuration (db2set) by comparing values from the Db2uInstance custom resource against the actual running configuration in DB2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k8s_client
|
ApiClient
|
Kubernetes API client |
required |
mas_instance_id
|
str
|
The ID of the MAS instance |
required |
mas_app_id
|
str
|
The ID of the MAS application (e.g., "manage", "iot") |
required |
database_role
|
str
|
The database role, either 'primary' or 'standby'. Defaults to 'primary'. |
'primary'
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
Logs results and raises an exception if any validation checks fail |
Raises:
| Type | Description |
|---|---|
Exception
|
If any configuration mismatches are detected between the CR and actual DB2 configuration. The exception contains a dict with 'message' and 'details' keys listing all failures. |