Integration of OSM Charms with new MongoDB
[osm/devops.git] / installers / charm / layers / osm-common / lib / charms / osm / k8s.py
1 # Copyright 2020 Canonical Ltd.
2 #
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 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from charmhelpers.core.hookenv import (
16 network_get,
17 relation_id,
18 log,
19 )
20
21
22 def get_service_ip(endpoint):
23 try:
24 info = network_get(endpoint, relation_id())
25 if 'ingress-addresses' in info:
26 addr = info['ingress-addresses'][0]
27 if len(addr):
28 return addr
29 else:
30 log("No ingress-addresses: {}".format(info))
31 except Exception as e:
32 log("Caught exception checking for service IP: {}".format(e))
33
34 return None
35
36
37 def is_pod_up(endpoint):
38 """Check to see if the pod of a relation is up.
39
40 application-vimdb: 19:29:10 INFO unit.vimdb/0.juju-log network info
41
42 In the example below:
43 - 10.1.1.105 is the address of the application pod.
44 - 10.152.183.199 is the service cluster ip
45
46 {
47 'bind-addresses': [{
48 'macaddress': '',
49 'interfacename': '',
50 'addresses': [{
51 'hostname': '',
52 'address': '10.1.1.105',
53 'cidr': ''
54 }]
55 }],
56 'egress-subnets': [
57 '10.152.183.199/32'
58 ],
59 'ingress-addresses': [
60 '10.152.183.199',
61 '10.1.1.105'
62 ]
63 }
64 """
65 try:
66 info = network_get(endpoint, relation_id())
67
68 # Check to see if the pod has been assigned it's internal and
69 # external ips
70 for ingress in info['ingress-addresses']:
71 if len(ingress) == 0:
72 return False
73 except:
74 return False
75
76 return True