X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Fcharm%2Fosm-nbi%2Fsrc%2Flegacy_interfaces.py;h=5deb3f5f7cc6becc4e9830175429c1af2329e732;hb=a569df75794cf1eb5f504ea88faea7ceba030630;hp=4750cffca0439fa625095244e22bf1bdf0d7153b;hpb=9f20805a3d9c9cecdd5fce4ff7b311c1c3655c23;p=osm%2Fdevops.git diff --git a/installers/charm/osm-nbi/src/legacy_interfaces.py b/installers/charm/osm-nbi/src/legacy_interfaces.py index 4750cffc..5deb3f5f 100644 --- a/installers/charm/osm-nbi/src/legacy_interfaces.py +++ b/installers/charm/osm-nbi/src/legacy_interfaces.py @@ -141,3 +141,65 @@ class KeystoneClient(BaseRelationClient): @property def admin_project_name(self): return self.get_data_from_app("admin_project_name") + + +class MongoClient(BaseRelationClient): + """Requires side of a Mongo Endpoint""" + + mandatory_fields_mapping = { + "reactive": ["connection_string"], + "ops": ["replica_set_uri", "replica_set_name"], + } + + def __init__(self, charm: ops.charm.CharmBase, relation_name: str): + super().__init__(charm, relation_name, mandatory_fields=[]) + + @property + def connection_string(self): + if self.is_opts(): + replica_set_uri = self.get_data_from_unit("replica_set_uri") + replica_set_name = self.get_data_from_unit("replica_set_name") + return f"{replica_set_uri}?replicaSet={replica_set_name}" + else: + return self.get_data_from_unit("connection_string") + + def is_opts(self): + return not self.is_missing_data_in_unit_ops() + + def is_missing_data_in_unit(self): + return self.is_missing_data_in_unit_ops() and self.is_missing_data_in_unit_reactive() + + def is_missing_data_in_unit_ops(self): + return not all( + [self.get_data_from_unit(field) for field in self.mandatory_fields_mapping["ops"]] + ) + + def is_missing_data_in_unit_reactive(self): + return not all( + [self.get_data_from_unit(field) for field in self.mandatory_fields_mapping["reactive"]] + ) + + +class PrometheusClient(BaseRelationClient): + """Requires side of a Prometheus Endpoint""" + + mandatory_fields = ["hostname", "port"] + + def __init__(self, charm: ops.charm.CharmBase, relation_name: str): + super().__init__(charm, relation_name, self.mandatory_fields) + + @property + def hostname(self): + return self.get_data_from_app("hostname") + + @property + def port(self): + return self.get_data_from_app("port") + + @property + def user(self): + return self.get_data_from_app("user") + + @property + def password(self): + return self.get_data_from_app("password")