---
title: Charmhub | Deploy Osm Nbi using Charmhub - The Open Operator Collection
description: Deploy the latest version of Osm Nbi as a Kubernetes Operator on any
  cloud.
url: https://charmhub.io/osm-nbi/libraries/nbi
---

# Osm Nbi

[Charmed Distribution of OSM](https://charmhub.io/publisher/charmed-osm "View all packages from Charmed Distribution of OSM")

* [Charmed Distribution of OSM](https://charmhub.io/publisher/charmed-osm "View all packages from Charmed Distribution of OSM")

Platform:

stable 1

```
juju deploy osm-nbi
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/osm-nbi/libraries/nbi#drawer)

## charms.osm\_nbi.v0.nbi

* [*Docstrings*Docstrings](https://charmhub.io/osm-nbi/libraries/nbi)
  [*Code*Source code](https://charmhub.io/osm-nbi/libraries/nbi/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.osm_nbi.v0.nbi
    ```

    [Download nbi.py](https://charmhub.io/osm-nbi/libraries/nbi/download)
  + *Last updated* 16 Jun 2022
  + *Revision* Library version 0.1

Nbi library.

This [library](https://juju.is/docs/sdk/libraries) implements both sides of the
`nbi` [interface](https://juju.is/docs/sdk/relations).

The *provider* side of this interface is implemented by the
[osm-nbi Charmed Operator](https://charmhub.io/osm-nbi).

Any Charmed Operator that *requires* NBI for providing its
service should implement the *requirer* side of this interface.

In a nutshell using this library to implement a Charmed Operator *requiring*
NBI would look like

```
$ charmcraft fetch-lib charms.osm_nbi.v0.nbi
```

`metadata.yaml`:

```
requires:
  nbi:
    interface: nbi
    limit: 1
```

`src/charm.py`:

```
from charms.osm_nbi.v0.nbi import NbiRequires
from ops.charm import CharmBase

class MyCharm(CharmBase):

    def __init__(self, *args):
        super().__init__(*args)
        self.nbi = NbiRequires(self)
        self.framework.observe(
            self.on["nbi"].relation_changed,
            self._on_nbi_relation_changed,
        )
        self.framework.observe(
            self.on["nbi"].relation_broken,
            self._on_nbi_relation_broken,
        )
        self.framework.observe(
            self.on["nbi"].relation_broken,
            self._on_nbi_broken,
        )

    def _on_nbi_relation_broken(self, event):
        # Get NBI host and port
        host: str = self.nbi.host
        port: int = self.nbi.port
        # host => "osm-nbi"
        # port => 9999

    def _on_nbi_broken(self, event):
        # Stop service
        # ...
        self.unit.status = BlockedStatus("need nbi relation")
```

You can file bugs
[here](https://osm.etsi.org/bugzilla/enter_bug.cgi), selecting the `devops` module!

---

Index

* [class NbiRequires](https://charmhub.io/osm-nbi/libraries/nbi#nbirequires)
* + [def \_\_init\_\_(
    self,
    charm,
    endpoint\_name)](https://charmhub.io/osm-nbi/libraries/nbi#nbirequires-__init__)
* + [def host(
    self)](https://charmhub.io/osm-nbi/libraries/nbi#nbirequires-host)
* + [def port(
    self)](https://charmhub.io/osm-nbi/libraries/nbi#nbirequires-port)
* [class NbiProvides](https://charmhub.io/osm-nbi/libraries/nbi#nbiprovides)
* + [def \_\_init\_\_(
    self,
    charm,
    endpoint\_name)](https://charmhub.io/osm-nbi/libraries/nbi#nbiprovides-__init__)
* + [def set\_host\_info(
    self,
    host,
    port,
    relation)](https://charmhub.io/osm-nbi/libraries/nbi#nbiprovides-set_host_info)

#### class NbiRequires

Description

Requires-side of the Nbi relation. None

Methods

NbiRequires.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
endpoint\_name: str
)

NbiRequires.
host(

*self*
)

Description

Get nbi hostname. None

NbiRequires.
port(

*self*
)

Description

Get nbi port number. None

#### class NbiProvides

Description

Provides-side of the Nbi relation. None

Methods

NbiProvides.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
endpoint\_name: str
)

NbiProvides.
set\_host\_info(

*self*

,
host: str

,
port: int

,
relation
)

Set Nbi host and port.

Arguments

host
(str)

Nbi hostname or IP address.

port
(int)

Nbi port.

relation
(Optional[Relation])

Relation to update.
If not specified, all relations will be updated.

Description

This function writes in the application data of the relation, therefore,
only the unit leader can call it.
