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): ...@@ -450,10 +450,9 @@ def svcStartAll(config):
except: except:
pass pass
def removeInstanceRoot(config): def removeInstanceRootDirectory(config):
"""Clean instance directory and stop all its running processes""" """Clean instance directory"""
if os.path.exists(config['instance_root']): if os.path.exists(config['instance_root']):
svcStopAll(config)
for instance_directory in os.listdir(config['instance_root']): for instance_directory in os.listdir(config['instance_root']):
instance_directory = os.path.join(config['instance_root'], instance_directory) instance_directory = os.path.join(config['instance_root'], instance_directory)
# XXX: hardcoded # XXX: hardcoded
...@@ -468,6 +467,27 @@ def removeInstanceRoot(config): ...@@ -468,6 +467,27 @@ def removeInstanceRoot(config):
os.chmod(fullPath, 0744) os.chmod(fullPath, 0744)
shutil.rmtree(instance_directory) 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): def getSvcStatus(config):
"""Return all Softwares Instances process Information""" """Return all Softwares Instances process Information"""
...@@ -545,13 +565,7 @@ def configNewSR(config, projectpath): ...@@ -545,13 +565,7 @@ def configNewSR(config, projectpath):
if folder: if folder:
sup_process.stopProcess(config, 'slapgrid-cp') sup_process.stopProcess(config, 'slapgrid-cp')
sup_process.stopProcess(config, 'slapgrid-sr') sup_process.stopProcess(config, 'slapgrid-sr')
stopProxy(config) removeCurrentInstance(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)
open(os.path.join(config['etc_dir'], ".project"), 'w').write(projectpath) open(os.path.join(config['etc_dir'], ".project"), 'w').write(projectpath)
return True return True
else: else:
......
...@@ -25,7 +25,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, checkUserCred ...@@ -25,7 +25,7 @@ from slapos.runner.utils import (checkSoftwareFolder, configNewSR, checkUserCred
isSoftwareRunning, isSoftwareReleaseReady, isText, isSoftwareRunning, isSoftwareReleaseReady, isText,
loadSoftwareRList, md5sum, newSoftware, loadSoftwareRList, md5sum, newSoftware,
readFileFrom, readParameters, realpath, readFileFrom, readParameters, realpath,
removeInstanceRoot, removeProxyDb, removeCurrentInstance,
removeSoftwareByName, runSlapgridUntilSuccess, removeSoftwareByName, runSlapgridUntilSuccess,
saveBuildAndRunParams, saveBuildAndRunParams,
setMiniShellHistory, setMiniShellHistory,
...@@ -216,17 +216,9 @@ def supervisordStatus(): ...@@ -216,17 +216,9 @@ def supervisordStatus():
def removeInstance(): def removeInstance():
if isInstanceRunning(app.config): result = removeCurrentInstance(app.config)
flash('Instantiation in progress, cannot remove') if isinstance(result, str):
else: flash(result)
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')
return redirect(url_for('inspectInstance')) 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