MAIA.maia_fn module#

MAIA.maia_fn.convert_username_to_jupyterhub_username(username)[source]#

Convert a username to a JupyterHub-compatible username.

Parameters:

username (str) – The original username.

Returns:

str – The JupyterHub-compatible username.

MAIA.maia_fn.copy_certificate_authority_secret(namespace, source_secret_name='kubernetes-ca', target_secret_name='kubernetes-ca', source_namespace='cert-manager', opaque=False, cert_name='tls.crt', key_name='tls.key')[source]#
MAIA.maia_fn.create_config_map_from_data(data, config_map_name, namespace, kubeconfig_dict, data_key='values.yaml')[source]#

Create a ConfigMap on a Kubernetes Cluster.

Parameters:
  • data (str) – String containing the content of the ConfigMap to dump.

  • config_map_name (str) – ConfigMap name.

  • namespace (str) – Namespace where to create the ConfigMap.

  • data_key (str, optional) – Value to use as the filename for the content in the ConfigMap.

  • kubeconfig_dict (dict) – Kube Configuration dictionary for Kubernetes cluster authentication.

MAIA.maia_fn.create_filebrowser_values(namespace_config, cluster_config, config_folder, mlflow_configs=None, mount_cifs=True)[source]#

Create and write configuration values for deploying the MAIA Filebrowser Helm chart. This function generates a dictionary of configuration values required to deploy the MAIA Filebrowser application in a Kubernetes namespace. It handles image configuration, environment variables, volume mounts, CIFS volume setup, and ingress settings for both NGINX and Traefik ingress controllers. The resulting configuration is written to a YAML file in the specified config folder.

Parameters:
  • namespace_config (dict) – Dictionary containing namespace-specific configuration, including group ID, subdomain, and users.

  • cluster_config (dict) – Dictionary containing cluster-specific configuration, such as docker server, image pull secrets, domain, and optional ingress settings.

  • config_folder (str or Path) – Path to the folder where the generated configuration YAML file will be saved.

  • mlflow_configs (dict, optional) – Optional dictionary containing MLflow configuration, specifically the base64-encoded ‘mlflow_password’. If not provided, a new human-memorable password is generated.

Returns:

dict

A dictionary containing:
  • ’namespace’: The Kubernetes namespace for deployment.

  • ’release’: The Helm release name.

  • ’chart’: The Helm chart name.

  • ’repo’: The Helm chart repository URL.

  • ’version’: The Helm chart version.

  • ’values’: Path to the generated YAML values file.

Notes

  • The function expects certain helper functions and environment variables to be available, such as generate_human_memorable_password, convert_username_to_jupyterhub_username, and OmegaConf.

  • The CIFS server address is read from the ‘CIFS_SERVER’ environment variable.

MAIA.maia_fn.create_maia_namespace_values(namespace_config, cluster_config, config_folder, minio_configs=None, mlflow_configs=None)[source]#

Create MAIA namespace values for deployment.

Parameters:
  • namespace_config (dict) – Configuration for the namespace, including group ID and users.

  • cluster_config (dict) – Configuration for the cluster, including SSH port type, port range, and storage class.

  • config_folder (str) – Path to the folder where configuration files will be saved.

  • minio_configs (dict, optional) – Configuration for MinIO, including access keys and console keys. Defaults to None.

  • mlflow_configs (dict, optional) – Configuration for MLflow, including user and password. Defaults to None.

Returns:

dict – A dictionary containing the namespace, release name, chart name, repository URL, chart version, and the path to the generated values file.

MAIA.maia_fn.create_nvflare_dashboard_values(namespace_config, cluster_config, config_folder)[source]#

Create and write configuration values for deploying the MAIA NVFlare Dashboard Helm chart. This function generates a dictionary of configuration values required to deploy the MAIA NVFlare Dashboard application in a Kubernetes namespace. It handles image configuration, environment variables, volume mounts, CIFS volume setup, and ingress settings for both NGINX and Traefik ingress controllers. The resulting configuration is written to a YAML file in the specified config folder.

MAIA.maia_fn.deploy_kubeflow_project(cluster_config, user_config, config_folder, project_config_dict=None, minimal=True)[source]#

Deploy a Kubeflow project using the provided configuration. :type cluster_config: :param cluster_config: Dictionary containing the cluster configuration. :type cluster_config: dict :type user_config: :param user_config: Dictionary containing the user configuration. :type user_config: dict :type config_folder: :param config_folder: Path to the configuration folder. :type config_folder: str or Path :type project_config_dict: :param project_config_dict: Dictionary containing the project configuration. :type project_config_dict: dict, optional

Returns:

dict – A dictionary containing deployment details such as namespace, release, chart, repo, version, and values file path.

MAIA.maia_fn.deploy_mlflow(cluster_config, user_config, config_folder, mysql_config=None, minio_config=None)[source]#

Deploy an MLflow instance on a Kubernetes cluster using Helm.

Parameters:
  • cluster_config (dict) – Configuration dictionary for the Kubernetes cluster.

  • user_config (dict) – Configuration dictionary for the user, including group_ID.

  • config_folder (str) – Path to the folder where configuration files will be stored.

  • mysql_config (dict, optional) – Configuration dictionary for MySQL, including mysql_user and mysql_password. Defaults to None.

  • minio_config (dict, optional) – Configuration dictionary for MinIO, including console_access_key and console_secret_key. Defaults to None.

Returns:

dict – A dictionary containing deployment details such as namespace, release name, chart name, repository URL, chart version, and path to the values file.

MAIA.maia_fn.deploy_mysql(cluster_config, user_config, config_folder, mysql_configs)[source]#

Deploy a MySQL instance on a Kubernetes cluster using Helm.

Parameters:
  • cluster_config (dict) – Configuration dictionary for the cluster, including storage class.

  • user_config (dict) – Configuration dictionary for the user, including group ID.

  • config_folder (str) – Path to the folder where configuration files will be stored.

  • mysql_configs (dict) – Configuration dictionary for MySQL, including user, password, and other settings.

Returns:

dict – A dictionary containing deployment details such as namespace, release name, chart name, repository URL, version, and values file path.

MAIA.maia_fn.deploy_oauth2_proxy(cluster_config, user_config, config_folder=None)[source]#

Deploy an OAuth2 Proxy using the provided cluster and user configurations.

Parameters:
  • cluster_config (dict) –

    Configuration dictionary for the cluster. Expected keys include:
    • ”keycloak”: A dictionary with “issuer_url”, “client_id”, and “client_secret”.

    • ”domain”: The domain name for the cluster.

    • ”url_type”: The type of URL, either “subpath” or other.

    • ”storage_class”: The storage class for Redis.

    • ”nginx_cluster_issuer” (optional): The cluster issuer for NGINX.

    • ”traefik_resolver” (optional): The resolver for Traefik.

  • user_config (dict) –

    Configuration dictionary for the user. Expected keys include:
    • ”group_ID”: The group ID for the user.

    • ”group_subdomain”: The subdomain for the user’s group.

  • config_folder (str, optional) – The folder path where the configuration files will be saved. Defaults to None.

Returns:

dict

A dictionary containing deployment details:
  • ”namespace”: The namespace for the deployment.

  • ”release”: The release name for the deployment.

  • ”chart”: The chart name for the deployment.

  • ”repo”: The repository URL for the chart.

  • ”version”: The chart version.

  • ”values”: The path to the generated values YAML file.

MAIA.maia_fn.deploy_orthanc(cluster_config, user_config, config_folder, project_config_dict=None)[source]#

Deploys Orthanc using the provided configuration. :type cluster_config: :param cluster_config: Dictionary containing the cluster configuration. :type cluster_config: dict :type user_config: :param user_config: Dictionary containing the user configuration. :type user_config: dict :type config_folder: :param config_folder: Path to the configuration folder. :type config_folder: str or Path

Returns:

dict – A dictionary containing deployment details such as namespace, release, chart, repo, version, and values file path.

MAIA.maia_fn.edit_orthanc_configuration(orthanc_config_template, orthanc_edit_dict)[source]#
MAIA.maia_fn.encode_docker_registry_secret(registry_server, registry_username, registry_password)[source]#

Encode Docker registry credentials into a base64-encoded string.

Parameters:
  • registry_server (str) – The Docker registry server.

  • registry_username (str) – The Docker registry username.

  • registry_password (str) – The Docker registry password.

Returns:

str – The base64-encoded Docker registry credentials.

MAIA.maia_fn.generate_human_memorable_password(length=12)[source]#
MAIA.maia_fn.generate_minio_configs(namespace, project_config_dict=None)[source]#

Generate configuration settings for MinIO.

Parameters:
  • namespace (int or str) – The unique identifier for the project.

  • project_config_dict (dict, optional) – A dictionary containing the custom configuration for the MinIO.

Returns:

dict – A dictionary with the following keys: - access_key (str): The access key for MinIO. - secret_key (str): A randomly generated secret key for MinIO. - console_access_key (str): A base64 encoded access key for console access. - console_secret_key (str): A base64 encoded secret key for console access.

MAIA.maia_fn.generate_mlflow_configs(namespace, project_config_dict=None)[source]#

Generate MLflow configuration dictionary with encoded user and password.

Parameters:
  • namespace (str) – The namespace to be encoded as the MLflow user.

  • project_config_dict (dict, optional) – A dictionary containing the custom configuration for the MLflow.

Returns:

dict – A dictionary containing the encoded MLflow user and password.

MAIA.maia_fn.generate_mysql_configs(namespace, project_config_dict=None)[source]#

Generate MySQL configuration dictionary.

Parameters:
  • namespace (str) – The namespace to be used as the MySQL user.

  • project_config_dict (dict, optional) – A dictionary containing the custom configuration for the MySQL.

Returns:

dict – A dictionary containing MySQL user and password.

MAIA.maia_fn.generate_nvflare_dashboard_configs(project_id, project_config_dict=None)[source]#

Generates NVFlare Dashboard configuration dictionary.

MAIA.maia_fn.generate_orthanc_configs(project_id, project_config_dict=None)[source]#

Generates Orthanc configuration dictionary.

MAIA.maia_fn.generate_random_password(length=12)[source]#
MAIA.maia_fn.get_minio_config_if_exists(project_id)[source]#

Retrieves MinIO configuration if it exists for the given project ID. This function loads the Kubernetes configuration from the environment, accesses the Kubernetes API to list secrets in the specified namespace, and extracts MinIO-related configuration from the secrets.

Parameters:

project_id (str) – The ID of the project for which to retrieve the MinIO configuration.

Returns:

dict – A dictionary containing MinIO configuration keys and their corresponding values. The dictionary may contain the following keys: - “access_key”: The default access key (always “admin”). - “console_access_key”: The console access key, if found. - “console_secret_key”: The console secret key, if found. - “secret_key”: The MinIO root password, if found.

MAIA.maia_fn.get_mlflow_config_if_exists(project_id)[source]#

Retrieve MLflow configuration from Kubernetes secrets if they exist.

Parameters:

project_id (str) – The ID of the project for which to retrieve the MLflow configuration. This ID is used to locate the corresponding Kubernetes namespace and secrets.

Returns:

dict – A dictionary containing the MLflow configuration with keys “mlflow_user” and “mlflow_password” if they exist in the Kubernetes secrets. If the secrets are not found, an empty dictionary is returned.

Raises:
  • KeyError – If the “KUBECONFIG” environment variable is not set.

  • yaml.YAMLError – If there is an error parsing the Kubernetes configuration file.

  • kubernetes.client.exceptions.ApiException – If there is an error communicating with the Kubernetes API.

MAIA.maia_fn.get_mysql_config_if_exists(project_id)[source]#

Retrieves MySQL configuration from Kubernetes environment variables if they exist.

Parameters:

project_id (str) – The ID of the project for which to retrieve the MySQL configuration. This ID is used to identify the namespace and the MySQL deployment within the Kubernetes cluster.

Returns:

dict – A dictionary containing the MySQL user and password if they exist in the environment variables of the MySQL deployment. The dictionary keys are: - “mysql_user”: The MySQL user. - “mysql_password”: The MySQL password.

Notes

This function assumes that the Kubernetes configuration file is specified in the environment variable “KUBECONFIG” and that the MySQL deployment name starts with the project ID followed by “-mysql-mkg”.

MAIA.maia_fn.get_nvflare_dashboard_config_if_exists(project_id)[source]#

Retrieves NVFlare Dashboard configuration from Kubernetes environment variables if they exist.

MAIA.maia_fn.get_orthanc_config_if_exists(project_id)[source]#

Retrieves Orthanc configuration from Kubernetes environment variables if they exist.

MAIA.maia_fn.get_ssh_port_dict(port_type, namespace, port_range, maia_metallb_ip=None)[source]#

Retrieve a dictionary of used SSH ports for services in a Kubernetes cluster.

Parameters:
  • port_type (str) – The type of port to check (‘LoadBalancer’ or ‘NodePort’).

  • namespace (str) – The namespace to filter services by.

  • port_range (tuple) – A tuple specifying the range of ports to check (start, end).

  • maia_metallb_ip (str, optional) – The IP address of the MetalLB load balancer (default is None).

Returns:

list of dict – A list of dictionaries with service names as keys and their corresponding used SSH ports as values. Returns None if an exception occurs.

MAIA.maia_fn.get_ssh_ports(n_requested_ports, port_type, ip_range, maia_metallb_ip=None)[source]#

Retrieve a list of available SSH ports based on the specified criteria.

Parameters:
  • n_requested_ports (int) – The number of SSH ports requested.

  • port_type (str) – The type of port to search for (‘LoadBalancer’ or ‘NodePort’).

  • ip_range (tuple) – A tuple specifying the range of IPs to search within (start, end).

  • maia_metallb_ip (str, optional) – The specific IP address to match for ‘LoadBalancer’ type. Defaults to None.

Returns:

  • list – A list of available SSH ports that meet the specified criteria.

  • None – If an error occurs during the process.

MAIA.maia_fn.gpu_list_from_nodes()[source]#

Retrieves a list of GPUs from the nodes in a Kubernetes cluster.

This function loads the Kubernetes configuration from the environment, initializes the Kubernetes client, and retrieves the list of nodes. It then checks each node to see if it is ready and has GPU labels, and constructs a dictionary with the node names as keys and a list containing the GPU product and count as values.

Returns:

dict – A dictionary where the keys are node names and the values are lists containing the GPU product and GPU count.