SD-Core NRF K8s

  • Canonical Telco
Channel Revision Published Runs on
latest/beta 10 03 Jan 2024
Ubuntu 22.04
latest/edge 16 21 Jan 2024
Ubuntu 22.04
1.4/beta 142 26 Apr 2024
Ubuntu 22.04
1.4/edge 688 29 Oct 2024
Ubuntu 22.04
1.5/edge 707 Yesterday
Ubuntu 22.04
1.3/beta 10 22 Jan 2024
Ubuntu 22.04
1.3/edge 94 05 Apr 2024
Ubuntu 22.04
juju deploy sdcore-nrf-k8s --channel 1.4/beta
Show information

Platform:

charms.sdcore_nrf_k8s.v0.fiveg_nrf_k8s

Library for the fiveg_nrf_k8s relation.

This library contains the Requires and Provides classes for handling the fiveg_nrf_k8s interface.

The purpose of this library is to relate a charm claiming to provide NRF information and another charm requiring this information.

Getting Started

From a charm directory, fetch the library using charmcraft:

charmcraft fetch-lib charms.sdcore_nrf_k8s.v0.fiveg_nrf_k8s

Add the following libraries to the charm's requirements.txt file:

  • pydantic
Requirer charm

The requirer charm is the one requiring the NRF information.

Example:


from ops.charm import CharmBase
from ops.main import main

from charms.sdcore_nrf_k8s.v0.fiveg_nrf_k8s import NRFAvailableEvent, NRFRequires

logger = logging.getLogger(__name__)


class DummyFiveGNRFRequirerCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)
        self.nrf_requirer = NRFRequires(self, "fiveg-nrf")
        self.framework.observe(self.nrf_requirer.on.nrf_available, self._on_nrf_available)

    def _on_nrf_available(self, event: NRFAvailableEvent):
        nrf_url = self.nrf_requirer.nrf_url
        <do something with the nrf_url>


if __name__ == "__main__":
    main(DummyFiveGNRFRequirerCharm)
Provider charm

The provider charm is the one providing the information about the NRF.

Example:


from ops.charm import CharmBase, RelationJoinedEvent
from ops.main import main

from charms.sdcore_nrf_k8s.v0.fiveg_nrf_k8s import NRFProvides


class DummyFiveGNRFProviderCharm(CharmBase):

    NRF_URL = "https://nrf.example.com"

    def __init__(self, *args):
        super().__init__(*args)
        self.nrf_provider = NRFProvides(self, "fiveg-nrf")
        self.framework.observe(
            self.on.fiveg_nrf_relation_joined, self._on_fiveg_nrf_relation_joined
        )

    def _on_fiveg_nrf_relation_joined(self, event: RelationJoinedEvent):
        relation_id = event.relation.id
        self.nrf_provider.set_nrf_information(
            url=self.NRF_URL,
            relation_id=relation_id,
        )

    def _on_nrf_url_changed(
        self,
    ):
        self.nrf_provider.set_nrf_information_in_all_relations(
            url="https://different.nrf.com",
        )


if __name__ == "__main__":
    main(DummyFiveGNRFProviderCharm)

class ProviderAppData

Description

Provider app data for fiveg_nrf_k8s. None

class ProviderSchema

Description

Provider schema for fiveg_nrf_k8s. None

def data_matches_provider_schema(data: dict)

Returns whether data matches provider schema.

Arguments

data (dict)

Data to be validated.

Returns

True if data matches provider schema, False otherwise.

class NRFAvailableEvent

Description

Charm event emitted when a NRF is available. It carries the NRF url. None

Methods

NRFAvailableEvent. __init__( self , handle: Handle , url: str )

Description

Init. None

NRFAvailableEvent. snapshot( self )

Description

Returns snapshot. None

NRFAvailableEvent. restore( self , snapshot: dict )

Description

Restores snapshot. None

class NRFBrokenEvent

Description

Charm event emitted when a NRF goes down. None

Methods

NRFBrokenEvent. __init__( self , handle: Handle )

Description

Init. None

class NRFRequirerCharmEvents

Description

List of events that the NRF requirer charm can leverage. None

class NRFRequires

Description

Class to be instantiated by the NRF requirer charm. None

Methods

NRFRequires. __init__( self , charm: CharmBase , relation_name: str )

Description

Init. None

NRFRequires. nrf_url( self )

Returns NRF url.

Returns

str

NRF url.

class NRFProvides

Description

Class to be instantiated by the charm providing the NRF data. None

Methods

NRFProvides. __init__( self , charm: CharmBase , relation_name: str )

Description

Init. None

NRFProvides. set_nrf_information( self , url: str , relation_id: int )

Sets NRF url in the application(s) relation data.

Arguments

url (str)

NRF url.

relation_id (int)

Relation ID.

Returns

None

NRFProvides. set_nrf_information_in_all_relations( self , url: str )

Sets NRF url in applications for all applications.

Arguments

url (str)

NRF url.

Returns

None