Commit d9355e2e authored by Adrian Pino's avatar Adrian Pino Committed by GitHub
Browse files

Merge pull request #79 from SunriseOpenOperatorPlatform/feature/update-sdk-invocation-naming

Update common invocation file names
parents 4e2739e1 a8df70f5
Loading
Loading
Loading
Loading
+21 −15
Original line number Diff line number Diff line
from src.common.sdk_catalog_client import SdkCatalogClient
from src.common.sdk import Sdk as sdkclient

# Note: that is equivalent to "from sunrise6g-sdk import Sdk as sdkclient"


def main():
    # The module importing the SDK, loads the config
    # The module that imports the SDK library, must specify "client_specs"
    client_specs = {
        "edgecloud": {
            "client_name": "i2edge",
            "base_url": "http://192.168.123.237:30769/",
            "base_url": "http://IP:PORT",
        },
        "network": {
            "client_name": "open5gs",
            "base_url": "http://IP:PORT",
            "scs_as_id": "id_example",
        },
        # "network": {
        #     "client_name": "open5gs",
        #     "base_url": "http://IP:PORT",
        #     "scs_as_id": "id_example"
        # }
    }

    clients = SdkCatalogClient.create_clients_from(client_specs)
    clients = sdkclient.create_clients_from(client_specs)
    edgecloud_client = clients.get("edgecloud")
    network_client = clients.get("network")

    print("EdgeCloud client ready to be used:", edgecloud_client)
    print("EdgeCloud client ready to be used:", network_client)

    # Examples:
    # EdgeCloud
    edgecloud_client = clients.get("edgecloud")
    print("Testing edgecloud client function: get_edge_cloud_zones:")
    zones = edgecloud_client.get_edge_cloud_zones()
    print(zones)
    # print("Testing edgecloud client function: get_edge_cloud_zones:")
    # zones = edgecloud_client.get_edge_cloud_zones()
    # print(zones)

    # # Network
    # network_client = clients.get("network")
    # Network
    # print("Testing network client function: EXAMPLE_FUNCTION:")
    # network_client.get_qod_session(session_id="example_session_id")

+14 −4
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
##
# Copyright 2025-present by Software Networks Area, i2CAT.
# All rights reserved.
#
# This file is part of the Open SDK
#
# Contributors:
#   - Adrián Pino Martínez (adrian.pino@i2cat.net)
##
from typing import Dict

from src.common.sdk_catalog import SdkClientCatalog
from src.common.sdk_factory import SdkFactory


class SdkCatalogClient:
class Sdk:
    @staticmethod
    def create_clients_from(
        client_specs: Dict[str, Dict[str, str]],
@@ -46,7 +56,7 @@ class SdkCatalogClient:
            >>> edgecloud_client.get_edge_cloud_zones()
            >>> network_client.get_qod_session(session_id="example_session_id")
        """
        sdk_client_catalog = SdkClientCatalog()
        sdk_client = SdkFactory()
        clients = {}

        for domain, config in client_specs.items():
@@ -58,7 +68,7 @@ class SdkCatalogClient:
                k: v for k, v in config.items() if k not in ("client_name", "base_url")
            }

            client = sdk_client_catalog.instantiate_and_retrieve_clients(
            client = sdk_client.instantiate_and_retrieve_clients(
                domain, client_name, base_url, **kwargs
            )
            clients[domain] = client
+17 −7
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
##
# Copyright 2025-present by Software Networks Area, i2CAT.
# All rights reserved.
#
# This file is part of the Open SDK
#
# Contributors:
#   - Adrián Pino Martínez (adrian.pino@i2cat.net)
##
from src.edgecloud.clients.aeros.client import EdgeApplicationManager as AerosClient
from src.edgecloud.clients.i2edge.client import EdgeApplicationManager as I2EdgeClient
from src.network.clients.oai.client import NetworkManager as OaiCoreClient
@@ -7,7 +17,7 @@ from src.network.clients.open5gs.client import NetworkManager as Open5GSClient
# from src.edgecloud.clients.piedge.client import EdgeApplicationManager as PiEdgeClient


def _edgecloud_catalog(client_name: str, base_url: str, **kwargs):
def _edgecloud_factory(client_name: str, base_url: str, **kwargs):
    edge_cloud_factory = {
        "aeros": lambda url, **kw: AerosClient(base_url=url, **kw),
        "i2edge": lambda url: I2EdgeClient(base_url=url),
@@ -21,7 +31,7 @@ def _edgecloud_catalog(client_name: str, base_url: str, **kwargs):
        )


def _network_catalog(client_name: str, base_url: str, **kwargs):
def _network_factory(client_name: str, base_url: str, **kwargs):
    if "scs_as_id" not in kwargs:
        raise ValueError("Missing required 'scs_as_id' for network clients.")
    scs_as_id = kwargs.pop("scs_as_id")
@@ -45,15 +55,15 @@ def _network_catalog(client_name: str, base_url: str, **kwargs):
        )


# def _oran_catalog(client_name: str, base_url: str):
# def _oran_factory(client_name: str, base_url: str):
#     # TODO


class SdkClientCatalog:
class SdkFactory:
    _domain_factories = {
        "edgecloud": _edgecloud_catalog,
        "network": _network_catalog,
        # "oran": _oran_catalog,
        "edgecloud": _edgecloud_factory,
        "network": _network_factory,
        # "oran": _oran_factory,
    }

    @classmethod
+14 −12
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
import pytest

from src.common.sdk_catalog_client import SdkCatalogClient
from src.common.sdk import Sdk as sdkclient

EDGE_CLOUD_TEST_CASES = [
    {"edgecloud": {"client_name": "i2edge", "base_url": "http://test-i2edge.url"}},
    {
        "edgecloud": {
            "client_name": "i2edge",
            "base_url": "http://test-nbi-i2edge.sunrise6g",
        }
    },
    {
        "edgecloud": {
            "client_name": "aeros",
            "base_url": "http://test-aeros.url",
            # Additional parameters for aerOS client:
            "aerOS_API_URL": "http://fake.api.url",
            "aerOS_ACCESS_TOKEN": "fake-access",
            "aerOS_HLO_TOKEN": "fake-hlo",
@@ -24,18 +30,14 @@ EDGE_CLOUD_TEST_CASES = [
]


@pytest.mark.parametrize(
    "client_specs",
    EDGE_CLOUD_TEST_CASES,
    ids=[
        "i2edge",
        "aeros",
        # "piedge"
    ],
)
def id_func(val):
    return val["edgecloud"]["client_name"]


@pytest.mark.parametrize("client_specs", EDGE_CLOUD_TEST_CASES, ids=id_func)
def test_edgecloud_platform_instantiation(client_specs):
    """Test instantiation of all edgecloud platform clients"""
    clients = SdkCatalogClient.create_clients_from(client_specs)
    clients = sdkclient.create_clients_from(client_specs)

    assert "edgecloud" in clients
    edge_client = clients["edgecloud"]
+7 −5
Original line number Diff line number Diff line
# -*- coding: utf-8 -*-
import pytest

from src.common.sdk_catalog_client import SdkCatalogClient
from src.common.sdk import Sdk as sdkclient

NETWORK_TEST_CASES = [
    {
@@ -30,12 +30,14 @@ NETWORK_TEST_CASES = [
]


@pytest.mark.parametrize(
    "client_specs", NETWORK_TEST_CASES, ids=["open5gs", "oai"]  # TODO add Open5gcore
)
def id_func(val):
    return val["network"]["client_name"]


@pytest.mark.parametrize("client_specs", NETWORK_TEST_CASES, ids=id_func)
def test_network_platform_instantiation(client_specs):
    """Test instantiation of all network platform clients"""
    clients = SdkCatalogClient.create_clients_from(client_specs)
    clients = sdkclient.create_clients_from(client_specs)

    assert "network" in clients
    network_client = clients["network"]
Loading