forked from GeoNode/geoserver-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_nginxhost_ip.py
45 lines (40 loc) · 1.31 KB
/
get_nginxhost_ip.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
import logging
import os
import docker
client = docker.from_env()
# print client.info()
# TODO avoid this script can fail and fall in the loop where the geoserver
# service is not available and consequently the nginx too which has geoserver
# as a reference link
for network in client.networks.list():
if 'geonode' in network.name:
geonode_network = network.name
else:
geonode_network = 'geonode_default'
try:
containers = {
c.attrs['Config']['Image']: c.attrs['NetworkSettings']['\
Networks'][geonode_network]['\
IPAddress'] for c in client.containers.list() if c.status in 'running'
}
for item in containers.items():
if "geonode/nginx" in item[0]:
ipaddr = item[1]
try:
os.environ["NGINX_BASE_URL"] = "http://" + ipaddr + ":" + "80"
nginx_base_url = "http://{}:80".format(ipaddr)
except NameError as er:
logging.info("NGINX container is not running maybe exited! Running\
containers are:{0}".format(containers))
except KeyError as ke:
logging.info("There has been a problem with the docker\
network which has raised the following exception: {0}".format(ke))
else:
# nginx_base_url = None
pass
finally:
try:
print nginx_base_url
except NameError as ne:
print "http://geonode:80"