Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo scripts
Commits
29da9688539e
Commit
29da9688539e
authored
7 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
docker dev start: only import netifaces if needed
parent
81f7aa6ad0e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
docker_dev_start.py
+13
-8
13 additions, 8 deletions
docker_dev_start.py
with
13 additions
and
8 deletions
docker_dev_start.py
+
13
−
8
View file @
29da9688
...
...
@@ -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-2
4
'
__updated__
=
'
2017-08-2
5
'
# 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
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment