Commit 4ced4a21 authored by Adrian Pino's avatar Adrian Pino
Browse files

Add factory class that contains the edge cloud platform clients

parent 83dcf903
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
from __future__ import annotations
from enum import Enum
from typing import TYPE_CHECKING

from src.edgecloud.clients.i2edge.client import EdgeApplicationManager as I2EdgeClient
from src.edgecloud.clients.aeros.client import EdgeApplicationManager as AerosClient
from src.edgecloud.clients.piedge.client import EdgeApplicationManager as PiEdgeClient
from src.edgecloud.clients.dmo.client import EdgeApplicationManager as DmoClient

if TYPE_CHECKING:
    from .edgecloud_interface import EdgeCloudInterface

class EdgeCloudFactory:
    """
    Factory class for creating EdgeCloud Clients
    """

    @staticmethod
    def create_edgecloud_client(client_name: str, base_url: str) -> EdgeCloudInterface:
        try:
            return EdgeCloudTypes.edgecloud_types[client_name](base_url)
        except KeyError:
            # Get the list of supported client names
            supported_clients = list(EdgeCloudTypes.edgecloud_types.keys())
            raise ValueError(
                f"Invalid edgecloud client name: '{client_name}'. "
                f"Supported clients are: {', '.join(supported_clients)}"
            )
        
class EdgeCloudTypes():
    """
    Class dedicated for the different types of edgecloud clients.
    """
    I2EDGE = "i2edge"
    AEROS = "aeros"
    DMO = "dmo"
    PIEDGE="piedge"

    edgecloud_types = {
        I2EDGE: lambda url: I2EdgeClient(base_url=url),
        AEROS: lambda url: AerosClient(base_url=url),
        DMO: lambda url: DmoClient(base_url=url),
        PIEDGE: lambda url: PiEdgeClient(base_url=url)
    }