Integration of OSM Charms with new MongoDB
[osm/devops.git] / installers / charm / interfaces / osm-nbi / README.md
1 <!--
2 Copyright 2020 Canonical Ltd.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6     http://www.apache.org/licenses/LICENSE-2.0
7     Unless required by applicable law or agreed to in writing, software
8     distributed under the License is distributed on an "AS IS" BASIS,
9     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10     See the License for the specific language governing permissions and
11     limitations under the License. -->
12
13 # Overview
14
15 This interface layer handles communication between Mongodb and its clients.
16
17 ## Usage
18
19 ### Provides
20
21 To implement this relation to offer an nbi:
22
23 In your charm's metadata.yaml:
24
25 ```yaml
26 provides:
27     nbi:
28         interface: osm-nbi
29 ```
30
31 reactive/mynbi.py:
32
33 ```python
34 @when('nbi.joined')
35 def send_config(nbi):
36     nbi.send_connection(
37         unit_get('private-address'),
38         get_nbi_port()
39     )
40 ```
41
42 ### Requires
43
44 If you would like to use an nbi from your charm:
45
46 metadata.yaml:
47
48 ```yaml
49 requires:
50     nbi:
51         interface: osm-nbi
52 ```
53
54 reactive/mycharm.py:
55
56 ```python
57 @when('nbi.ready')
58 def nbi_ready():
59     nbi = endpoint_from_flag('nbi.ready')
60     if nbi:
61         for unit in nbi.nbis():
62             add_nbi(unit['host'], unit['port'])
63 ```