|
@@ -9,12 +9,17 @@ from api.utils.docker_api import (
|
|
|
run_container,
|
|
|
start_container,
|
|
|
stop_container,
|
|
|
- copy_in
|
|
|
+ copy_in,
|
|
|
+ container_is_running
|
|
|
)
|
|
|
from api.utils.git_api import clone_repo
|
|
|
from api.utils.command import execute
|
|
|
from api.utils.email import send_email
|
|
|
-from api.utils.logger import info
|
|
|
+from api.utils.logger import (
|
|
|
+ info,
|
|
|
+ error,
|
|
|
+ warning
|
|
|
+)
|
|
|
import os
|
|
|
import socket
|
|
|
import time
|
|
@@ -215,33 +220,44 @@ def install_modules(system_name=None, module_names=[]):
|
|
|
if len(module_names) == 0:
|
|
|
return {'error': 'module names is required'}
|
|
|
|
|
|
- # 1. check system path
|
|
|
+ # 1. check system path
|
|
|
system_path = os.path.join(settings.ODOO_ROOT_PATH, system_name)
|
|
|
|
|
|
if not os.path.exists(system_path):
|
|
|
+ error('%s path not exists' % system_name)
|
|
|
return {'error': 'system path not exists'}
|
|
|
+
|
|
|
+ info('%s path checked' % system_name)
|
|
|
|
|
|
- # # 2. stop system container
|
|
|
- # stopped = stop_container(system_name)
|
|
|
+ # 2. check system status
|
|
|
+ system_is_up = container_is_running(system_name)
|
|
|
+ info('%s system state detected' % system_name)
|
|
|
+
|
|
|
+ # 3. stop system container if necesary
|
|
|
+ if system_is_up:
|
|
|
+ stopped = stop_container(system_name)
|
|
|
|
|
|
- # if not stopped:
|
|
|
- # return {'error': 'cannot stop system'}
|
|
|
+ if not stopped:
|
|
|
+ error('%s system cannot be stopped' % system_name)
|
|
|
+ return {'error': 'cannot stop system'}
|
|
|
+
|
|
|
+ info('%s system state successfully passed [state=%s]' % (system_name, system_is_up))
|
|
|
|
|
|
for module_name in module_names:
|
|
|
- # 3. check module path and remove it
|
|
|
+ # 4. check module path and remove it
|
|
|
module_path = os.path.join(system_path, 'custom-addons', module_name)
|
|
|
|
|
|
if os.path.exists(module_path):
|
|
|
execute(['rm', '-Rf', module_path])
|
|
|
|
|
|
- # 4. clone repo
|
|
|
+ # 5. clone repo
|
|
|
addons_path = os.path.join(system_path, 'custom-addons')
|
|
|
cloned = clone_repo(module_name, addons_path)
|
|
|
|
|
|
if not cloned:
|
|
|
return {'error': 'cannot clone repo'}
|
|
|
|
|
|
- # 5. remove git data
|
|
|
+ # 6. remove git data
|
|
|
git_data_path = os.path.join(module_path, '.git')
|
|
|
|
|
|
if os.path.exists(git_data_path):
|
|
@@ -251,26 +267,21 @@ def install_modules(system_name=None, module_names=[]):
|
|
|
execute(['chmod', '-R', '777', module_path])
|
|
|
except Exception:
|
|
|
pass
|
|
|
+
|
|
|
+ info('%s is installed in %s system' % (module_name, system_name))
|
|
|
|
|
|
- # # 7. start system container
|
|
|
- # started = start_container(system_name)
|
|
|
+ # 7. start system container
|
|
|
+ if system_is_up:
|
|
|
+ started = start_container(system_name)
|
|
|
|
|
|
- # if not started:
|
|
|
- # return {'error': 'cannot start system'}
|
|
|
+ if not started:
|
|
|
+ error('%s system cannot be started' % system_name)
|
|
|
+ return {'error': 'cannot start system'}
|
|
|
|
|
|
+ info('all modules requested installed')
|
|
|
return {'result': '%s installed' % module_name}
|
|
|
|
|
|
'''
|
|
|
'''
|
|
|
def install_module(system_name=None, module_name=None):
|
|
|
return install_modules(system_name, [module_name])
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-def up():
|
|
|
- pass
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-def kill():
|
|
|
- pass
|