Skip to content
Snippets Groups Projects
Commit 29da9688539e authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

docker dev start: only import netifaces if needed

parent 81f7aa6ad0e3
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,6 @@
import ConfigParser
import docker # apt python-docker (1.9)
from netifaces import interfaces, ifaddresses, AF_INET # apt python-netifaces
from psycopg2 import connect, OperationalError # apt python-psycopg2
# TODO auto create list of module
......@@ -22,7 +21,7 @@
__version__ = '0.1.0'
__date__ = '2017-08-11'
__updated__ = '2017-08-24'
__updated__ = '2017-08-25'
# Check the version of the "docker" package
if docker.__version__.split('.') < [2]:
......@@ -124,7 +123,7 @@
)
network_group.add_argument(
'--docker-network',
help="Use docker network [default: %(default)s]",
help="Use docker network (work better with python-netifaces installed) [default: %(default)s]",
action='store_true',
)
......@@ -217,9 +216,14 @@
options.append('--network')
options.append('host')
else:
ifaceName = 'docker0'
addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}])]
if addresses:
local_ip = addresses[0]
else:
local_ip = None
try:
from netifaces import ifaddresses, AF_INET # apt python-netifaces
ifaceName = 'docker0'
addresses = [i['addr'] for i in ifaddresses(ifaceName).setdefault(AF_INET, [{'addr':'No IP addr'}])]
if addresses:
local_ip = addresses[0]
except ImportError:
logging.warn('Consider installing python netifaces to ease local IP detection')
if not local_ip:
import socket
......@@ -225,4 +229,5 @@
import socket
logging.info('Contacting Google Public DNS to find our IP')
local_ip = [(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]
logging.debug('IP found %s', local_ip)
arg.append('--db_host')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment