OSM Libs

  • By OSM Charmers
Channel Revision Published Runs on
latest/edge 1 12 May 2022
Ubuntu 20.04
juju deploy osm-libs --channel edge
Show information

Platform:

Ubuntu
20.04

charms.osm_libs.v0.osm_config

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")

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 )