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.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.deploy_mlflow(cluster_config, user_config, config_folder, maia_config_dict, 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, maia_config_dict, config_folder)[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 maia_config_dict: :param maia_config_dict: Dictionary containing the MAIA configuration. :type maia_config_dict: 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(docker_server, docker_username, docker_password)[source]#

Encode Docker registry credentials into a base64-encoded string.

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

  • docker_username (str) – The Docker registry username.

  • docker_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_random_password(length=12)[source]#
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.