|
@@ -3,10 +3,12 @@ from django.conf import settings
|
|
|
from random import randint
|
|
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
|
|
from api.utils.docker_api import (
|
|
|
+ get_all_external_ports,
|
|
|
execute_command,
|
|
|
run_container,
|
|
|
copy_in
|
|
|
)
|
|
|
+from api.utils.logger import info
|
|
|
from api.utils.command import execute
|
|
|
import os
|
|
|
import socket
|
|
@@ -39,7 +41,7 @@ def randomize_port():
|
|
|
ports = settings.ODOO_PORTS_RANGE
|
|
|
port = 0
|
|
|
|
|
|
- while not check_port(port):
|
|
|
+ while not check_port_from_docker(port):
|
|
|
time.sleep(1)
|
|
|
port = randint(ports[0], ports[1])
|
|
|
|
|
@@ -52,17 +54,32 @@ def check_port(port=0):
|
|
|
return False
|
|
|
|
|
|
ok = False
|
|
|
+ info('cheking port %d at %s' % (settings.EXTERNAL_IP, port))
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
|
try:
|
|
|
s.bind((settings.EXTERNAL_IP, port))
|
|
|
+ info('%s checked at %s is success' % (settings.EXTERNAL_IP, port))
|
|
|
ok = True
|
|
|
except socket.error:
|
|
|
+ info('%s checked at %s is failed' % (settings.EXTERNAL_IP, port))
|
|
|
ok = False
|
|
|
+
|
|
|
|
|
|
s.close()
|
|
|
return ok
|
|
|
|
|
|
+'''
|
|
|
+'''
|
|
|
+def check_port_from_docker(port=0):
|
|
|
+ if port == 0:
|
|
|
+ return False
|
|
|
+
|
|
|
+ if port in get_all_external_ports():
|
|
|
+ return False
|
|
|
+
|
|
|
+ return True
|
|
|
+
|
|
|
'''
|
|
|
'''
|
|
|
def check_name(name=None):
|