Commit 26731381 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: factorizes the code used to remove instances.

The code in the view is lighter, and the generic part could have been moved to utils
parent ea7e927b
......@@ -450,10 +450,9 @@ def svcStartAll(config):
except:
pass
def removeInstanceRoot(config):
"""Clean instance directory and stop all its running processes"""
def removeInstanceRootDirectory(config):
"""Clean instance directory"""
if os.path.exists(config['instance_root']):
svcStopAll(config)
for instance_directory in os.listdir(config['instance_root']):
instance_directory = os.path.join(config['instance_root'], instance_directory)
# XXX: hardcoded
......@@ -468,6 +467,27 @@ def removeInstanceRoot(config):
os.chmod(fullPath, 0744)
shutil.rmtree(instance_directory)
def removeCurrentInstance(config):
if isInstanceRunning(config):
return "Instantiation in progress, cannot remove instance"
# Stop all processes
svcStopAll(config)
if stopProxy(config):
removeProxyDb(config)
else:
return "Something went wrong when trying to stop slapproxy."
# Remove Instance directory and data related to the instance
try:
removeInstanceRootDirectory(config)
param_path = os.path.join(config['etc_dir'], ".parameter.xml")
if os.path.exists(param_path):
os.remove(param_path)
except IOError:
return "The filesystem couldn't been cleaned properly"
return True
def getSvcStatus(config):
"""Return all Softwares Instances process Information"""
......@@ -545,13 +565,7 @@ def configNewSR(config, projectpath):
if folder:
sup_process.stopProcess(config, 'slapgrid-cp')
sup_process.stopProcess(config, 'slapgrid-sr')
stopProxy(config)
removeProxyDb(config)
startProxy(config)
removeInstanceRoot(config)
param_path = os.path.join(config['etc_dir'], ".parameter.xml")
if os.path.exists(param_path):
os.remove(param_path)
removeCurrentInstance(config)
open(os.path.join(config['etc_dir'], ".project"), 'w').write(projectpath)
return True
else:
......
......@@ -25,7 +25,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, checkUserCred
isSoftwareRunning, isSoftwareReleaseReady, isText,
loadSoftwareRList, md5sum, newSoftware,
readFileFrom, readParameters, realpath,
removeInstanceRoot, removeProxyDb,
removeCurrentInstance,
removeSoftwareByName, runSlapgridUntilSuccess,
saveBuildAndRunParams,
setMiniShellHistory,
......@@ -216,17 +216,9 @@ def supervisordStatus():
def removeInstance():
if isInstanceRunning(app.config):
flash('Instantiation in progress, cannot remove')
else:
removeProxyDb(app.config)
stopProxy(app.config)
svcStopAll(app.config) # Stop All instance process
removeInstanceRoot(app.config)
param_path = os.path.join(app.config['etc_dir'], ".parameter.xml")
if os.path.exists(param_path):
os.remove(param_path)
flash('Instance removed')
result = removeCurrentInstance(app.config)
if isinstance(result, str):
flash(result)
return redirect(url_for('inspectInstance'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment