MAIA.dashboard_utils module#

MAIA.dashboard_utils.decrypt_string(private_key, string)[source]#

Decrypts an encrypted string using a given private key.

Parameters:
  • private_key (str) – Path to the private key file in PEM format.

  • string (bytes) – The encrypted string to be decrypted.

Returns:

str – The decrypted string.

Raises:

ValueError – If the decryption process fails.

MAIA.dashboard_utils.encrypt_string(public_key, string)[source]#

Encrypts a given string using the provided public key.

Parameters:
  • public_key (str) – The file path to the public key in PEM format.

  • string (str) – The string to be encrypted.

Returns:

str – The encrypted string in hexadecimal format.

Raises:

ValueError – If the public key file cannot be read or is invalid.

MAIA.dashboard_utils.generate_encryption_keys(folder_path)[source]#

Generate RSA encryption keys and save them to files.

Parameters:

folder_path (str) – The path to the folder where the keys will be saved.

Returns:

None

MAIA.dashboard_utils.get_allocation_date_for_project(maia_project_model, group_id, is_namespace_style=False)[source]#

Retrieves the allocation date for a project based on the given group ID.

Parameters:
  • maia_project_model (Model) – The Django model representing the MAIA project.

  • group_id (str) – The group ID to match against the project’s namespace.

  • is_namespace_style (bool, optional) – If True, the group ID comparison will be done in a namespace style (lowercase and underscores replaced with hyphens). Default is False.

Returns:

date or None – The allocation date of the project if a match is found, otherwise None.

MAIA.dashboard_utils.get_argocd_project_status(argocd_namespace, project_id)[source]#
async MAIA.dashboard_utils.get_list_of_deployed_projects()[source]#

Asynchronously retrieves a list of deployed projects from the Argo CD namespace. This function uses a Kubernetes client to list all releases in the “argocd” namespace and returns the names of these releases.

Returns:

list of str – A list containing the names of the deployed projects.

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

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

MAIA.dashboard_utils.get_pending_projects(settings, maia_project_model)[source]#

Retrieve a list of pending projects that are not in the active groups.

Parameters:
  • settings (dict) – Configuration settings required to access Keycloak.

  • maia_project_model (Django model) – The Django model representing the MAIA projects.

Returns:

list – A list of namespaces of pending projects.

MAIA.dashboard_utils.get_project(group_id, settings, maia_project_model, is_namespace_style=False)[source]#

Retrieve project details and associated cluster ID based on the group ID.

Parameters:
  • group_id (str) – The ID of the group to search for.

  • settings (object) – The settings object containing OIDC configuration.

  • maia_project_model (Django model) – The Django model representing MAIA projects.

  • is_namespace_style (bool, optional) – Flag indicating whether the group ID is in namespace style (default is False).

Returns:

tuple – A tuple containing: - namespace_form (dict): A dictionary with project details and resource limits. - cluster_id (str or None): The ID of the associated cluster, or None if not applicable.

MAIA.dashboard_utils.get_project_argo_status_and_user_table(request, settings, maia_user_model, maia_project_model)[source]#

Retrieves the Argo CD project status and user table information.

Parameters:
  • request (HttpRequest) – The HTTP request object containing session and user information.

  • settings (Settings) – The settings object containing configuration values.

  • maia_user_model (Model) – The Django model representing MAIA users.

  • maia_project_model (Model) – The Django model representing MAIA projects.

Returns:

tuple – A tuple containing: - user_table (dict): The user table information. - to_register_in_groups (list): List of users to register in groups. - to_register_in_keycloak (list): List of users to register in Keycloak. - maia_groups_dict (dict): Dictionary of MAIA groups. - project_argo_status (dict): Dictionary containing the Argo CD project status for each project.

MAIA.dashboard_utils.get_user_table(settings, maia_user_model, maia_project_model)[source]#

Retrieve user and project information from Keycloak and Minio, and organize it into a dictionary.

Parameters:
  • settings (object) – An object containing configuration settings such as OIDC and Minio credentials.

  • maia_user_model (Django model) – The Django model representing MAIA users.

  • maia_project_model (Django model) – The Django model representing MAIA projects.

Returns:

tuple – A tuple containing: - users_to_register_in_group (dict): Users to be registered in Keycloak groups. - users_to_register_in_keycloak (list): Users to be registered in Keycloak. - maia_group_dict (dict): Dictionary containing group information including users, conda environments, and project details. - users_to_remove_from_group (dict): Users to be removed from Keycloak groups.

MAIA.dashboard_utils.register_cluster_for_project_in_db(project_model, settings, namespace, cluster)[source]#

Registers a cluster for a project in the database. This function connects to Keycloak to retrieve group information and associates a cluster with a project based on the provided namespace. If the project already exists, it updates the cluster information; otherwise, it creates a new project entry with the specified cluster.

Parameters:
  • project_model (Django model) – The Django model representing the project.

  • settings (object) – An object containing configuration settings.

  • namespace (str) – The namespace associated with the project.

  • cluster (str) – The cluster to be registered for the project.

Returns:

None

MAIA.dashboard_utils.send_approved_registration_email(receiver_email, login_url, temp_password)[source]#

Sends an email to notify the user that their MAIA account registration has been approved.

Parameters:
  • receiver_email (str) – The email address of the recipient.

  • login_url (str) – The URL where the user can log in to MAIA.

  • temp_password (str) – The temporary password assigned to the user.

Raises:
  • KeyError – If the environment variables ‘email_account’ or ‘email_password’ are not set.

  • smtplib.SMTPException – If there is an error sending the email.

MAIA.dashboard_utils.send_discord_message(username, namespace, url)[source]#

Sends a message to a Discord webhook to request a MAIA account.

Parameters:
  • username (str) – The username of the person requesting the account.

  • namespace (str) – The project namespace for which the account is being requested.

  • url (str) – The Discord webhook URL to which the message will be sent.

Raises:
  • requests.exceptions.HTTPError – If the HTTP request returned an unsuccessful status code.

  • Prints

  • ------

  • str – Success message with the HTTP status code if the payload is delivered successfully.

  • str – Error message if the HTTP request fails.

MAIA.dashboard_utils.send_maia_info_email(receiver_email, register_project_url, register_user_url, discord_support_link)[source]#

Send an email with registration information for the MAIA platform. :type receiver_email: :param receiver_email: The email address of the recipient. :type receiver_email: str :type register_project_url: :param register_project_url: The URL for project registration. :type register_project_url: str :type register_user_url: :param register_user_url: The URL for user registration. :type register_user_url: str :type discord_support_link: :param discord_support_link: The URL for the MAIA support Discord. :type discord_support_link: str

Returns:

None

MAIA.dashboard_utils.send_maia_message_email(receiver_emails, subject, message_body)[source]#

Send an email with a custom message to multiple recipients with improved deliverability.

MAIA.dashboard_utils.update_user_table(form, user_model, maia_user_model, project_model)[source]#

Updates user and project information based on the cleaned data from a form.

Parameters:
  • form (Form) – The form containing cleaned data to update the user and project models.

  • user_model (Model) – The user model to query and update user information.

  • maia_user_model (Model) – The MAIA user model to query and update namespace information.

  • project_model (Model) – The project model to query and update project information.

Notes

  • The function processes entries in the form’s cleaned data to update user namespaces and project details.

  • User namespaces are updated or created in the maia_user_model based on the user’s email.

  • Project details are updated or created in the project_model based on the namespace.

MAIA.dashboard_utils.verify_gpu_availability(global_existing_bookings, new_booking, gpu_specs)[source]#

Verify GPU availability for a new booking.

Parameters:
  • global_existing_bookings (list of dict) – A list of existing bookings where each booking is represented as a dictionary with keys “gpu”, “start_date”, and “end_date”.

  • new_booking (dict) – A dictionary representing the new booking with keys “gpu”, “start_date”, and “end_date”.

  • gpu_specs (list of dict) – A list of GPU specifications where each specification is represented as a dictionary with keys “name”, “replicas”, and “count”.

Returns:

  • overlapping_time_points (list of datetime) – A list of time points where bookings overlap.

  • gpu_availability_per_slot (list of int) – A list of available GPU counts for each overlapping time slot.

  • total_gpus (int) – The total number of GPUs available for the specified GPU type.

MAIA.dashboard_utils.verify_gpu_booking_policy(existing_bookings, new_booking)[source]#
MAIA.dashboard_utils.verify_minio_availability(settings)[source]#

Verifies the availability of a MinIO server.

Parameters:

settings (object) –

An object containing the MinIO configuration settings. - settings.MINIO_URL : str

The URL of the MinIO server.

  • settings.MINIO_ACCESS_KEYstr

    The access key for the MinIO server.

  • settings.MINIO_SECRET_KEYstr

    The secret key for the MinIO server.

  • settings.BUCKET_NAMEstr

    The name of the bucket to check for existence.

Returns:

bool – True if the MinIO server is available and the bucket exists, False otherwise.