---
title: Charmhub | Deploy OSM Libs using Charmhub - The Open Operator Collection
description: Deploy the latest version of OSM Libs on any cloud.
url: https://charmhub.io/osm-libs/libraries/osm_config
---

# OSM Libs

[OSM Charmers](https://charmhub.io/publisher/osm-charmers "View all packages from OSM Charmers")

* [OSM Charmers](https://charmhub.io/publisher/osm-charmers "View all packages from OSM Charmers")

Platform:

20.04

edge 1

```
juju deploy osm-libs --channel edge
```

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

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

## charms.osm\_libs.v0.osm\_config

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

    Fetch library

    ```
    charmcraft fetch-lib charms.osm_libs.v0.osm_config
    ```

    [Download osm\_config.py](https://charmhub.io/osm-libs/libraries/osm_config/download)
  + *Last updated* 13 May 2022
  + *Revision* Library version 0.1

OSM Config Library.

This library provides a simple way of getting information injected
by OSM in the osm-config configuration option.

#### Schema

This is the JSON schema that is supported by the library

```
{
    "v0": {
        "k8s" : {
            "services": {
                <service_name>: {
                    "ip": [<ip>],
                    "ports": {
                        <port_name>: {
                            "port": <port_number>,
                            "protocol": "TCP",
                        }
                    }
                }
            }
        }
    }
}
```

#### Getting started

Execute the following command inside your Charmed Operator folder to fetch the library.

```
charmcraft fetch-lib charms.osm_libs.v0.osm_config
```

Import the library, and initialize it you charm constructor.

```
# ...
from charms.osm_libs.v0.osm_config import OsmConfig

class SomeCharm(CharmBase):
    def __init__(self, *args):
        # ...
        self.osm_config = OsmConfig(self)
        # ...
```

#### K8s services

The `OsmConfig` class allows you to easily get information about the K8s services
injected by OSM.

This is an example on how to get information the IP and port of a particular K8s service.

```
class SomeCharm(CharmBase):
    def _on_some_action(self, event):
        openldap_service = self.osm_config.k8s.get_service("openldap")
        openldap_ip = openldap_service.ip
        openldap_port = openldap_service.get_port("openldap")
```

---

Index

* [class K8sService](https://charmhub.io/osm-libs/libraries/osm_config#k8sservice)
* + [def \_\_init\_\_(
    self,
    info)](https://charmhub.io/osm-libs/libraries/osm_config#k8sservice-__init__)
* + [def ip(
    self)](https://charmhub.io/osm-libs/libraries/osm_config#k8sservice-ip)
* + [def get\_port(
    self,
    port\_name)](https://charmhub.io/osm-libs/libraries/osm_config#k8sservice-get_port)
* [class K8sConfig](https://charmhub.io/osm-libs/libraries/osm_config#k8sconfig)
* + [def \_\_init\_\_(
    self,
    k8s\_config)](https://charmhub.io/osm-libs/libraries/osm_config#k8sconfig-__init__)
* + [def get\_service(
    self,
    service\_name)](https://charmhub.io/osm-libs/libraries/osm_config#k8sconfig-get_service)
* + [def get\_services(
    self)](https://charmhub.io/osm-libs/libraries/osm_config#k8sconfig-get_services)
* [class OsmConfig](https://charmhub.io/osm-libs/libraries/osm_config#osmconfig)
* + [def \_\_init\_\_(
    self,
    charm)](https://charmhub.io/osm-libs/libraries/osm_config#osmconfig-__init__)

#### class K8sService

Description

Represents a K8s Service. None

Methods

K8sService.
\_\_init\_\_(

*self*

,
info
)

K8sService.
ip(

*self*
)

Description

Get the first IP of the service. None

K8sService.
get\_port(

*self*

,
port\_name: str
)

Get port by name.

Arguments

port\_name

Name of the port.

#### class K8sConfig

Description

Represents the K8s configuration in OsmConfig. None

Methods

K8sConfig.
\_\_init\_\_(

*self*

,
k8s\_config
)

K8sConfig.
get\_service(

*self*

,
service\_name: str
)

Get K8s service by name.

Arguments

service\_name

Name of the K8s service.

Returns

K8sService

the Kubernetes Service.

Description

This function will only return one K8s service, the first that contains
the `service_name` provided as argument.

K8sConfig.
get\_services(

*self*
)

Get all K8s services.

Returns

Dict[str, K8sService]

Dictionary with service names as keys,
and K8sService objects as values.

#### class OsmConfig

Description

Represents the configuration injected by OSM. None

Methods

OsmConfig.
\_\_init\_\_(

*self*

,
charm: CharmBase
)
