[Erp5-report] r45226 luke - in /slapos/trunk/util/slapos.tool.runner: ./ src/ src/slapos/ s...
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 8 11:29:51 CEST 2011
Author: luke
Date: Fri Apr 8 11:29:51 2011
New Revision: 45226
URL: http://svn.erp5.org?rev=45226&view=rev
Log:
- SlapOS web based development tool
Added:
slapos/trunk/util/slapos.tool.runner/
slapos/trunk/util/slapos.tool.runner/CHANGES.txt
slapos/trunk/util/slapos.tool.runner/MANIFEST.in
slapos/trunk/util/slapos.tool.runner/README.txt
slapos/trunk/util/slapos.tool.runner/setup.cfg
slapos/trunk/util/slapos.tool.runner/setup.py
slapos/trunk/util/slapos.tool.runner/src/
slapos/trunk/util/slapos.tool.runner/src/slapos/
slapos/trunk/util/slapos.tool.runner/src/slapos/__init__.py
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/__init__.py
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/__init__.py
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/index.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/instanceInspect.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/layout.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/runResult.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateInstanceProfile.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateSoftwareProfile.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/viewLog.html
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/utils.py
slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/views.py
Added: slapos/trunk/util/slapos.tool.runner/CHANGES.txt
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/CHANGES.txt?rev=45226&view=auto
==============================================================================
(empty)
Added: slapos/trunk/util/slapos.tool.runner/MANIFEST.in
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/MANIFEST.in?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/MANIFEST.in (added)
+++ slapos/trunk/util/slapos.tool.runner/MANIFEST.in [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1 @@
+recursive-include src/slapos/tool/runner/templates *.html
Added: slapos/trunk/util/slapos.tool.runner/README.txt
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/README.txt?rev=45226&view=auto
==============================================================================
(empty)
Added: slapos/trunk/util/slapos.tool.runner/setup.cfg
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/setup.cfg?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/setup.cfg (added)
+++ slapos/trunk/util/slapos.tool.runner/setup.cfg [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,3 @@
+[egg_info]
+tag_build = .dev
+tag_svn_revision = 1
Added: slapos/trunk/util/slapos.tool.runner/setup.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/setup.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/setup.py (added)
+++ slapos/trunk/util/slapos.tool.runner/setup.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,37 @@
+from setuptools import setup, find_packages
+
+name = "slapos.tool.runner"
+version = "1.0"
+
+def read(name):
+ return open(name).read()
+
+long_description=( read('README.txt')
+ + '\n' +
+ read('CHANGES.txt')
+ )
+setup(
+ name=name,
+ version=version,
+ description="Web based runner for SlapOS",
+ classifiers=[
+ "Environment :: Web Environment",
+ "Intended Audience :: Developers",
+ "Intended Audience :: Education",
+ "Programming Language :: Python",
+ ],
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['slapos', 'slapos.tool'],
+ install_requires=[
+ 'Flask', # based on Flask
+ 'setuptools', # namespaces
+ 'slapos.slap', # runner is using this to communicate with proxy
+ 'xml_marshaller', # needed to dump information
+ ],
+ entry_points = """
+ [console_scripts]
+ slaprunner = %(name)s:run
+ """ % dict(name=name),
+)
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/__init__.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/__init__.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/__init__.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/__init__.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,6 @@
+# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
+try:
+ __import__('pkg_resources').declare_namespace(__name__)
+except ImportError:
+ from pkgutil import extend_path
+ __path__ = extend_path(__path__, __name__)
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/__init__.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/__init__.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/__init__.py (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/__init__.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,117 @@
+from optparse import OptionParser, Option
+import ConfigParser
+import logging
+import logging.handlers
+import os
+import sys
+
+class Parser(OptionParser):
+ """
+ Parse all arguments.
+ """
+ def __init__(self, usage=None, version=None):
+ """
+ Initialize all options possibles.
+ """
+ OptionParser.__init__(self, usage=usage, version=version,
+ option_list=[
+ Option("-l", "--log_file",
+ help="The path to the log file used by the script.",
+ type=str),
+ Option("-v", "--verbose",
+ default=False,
+ action="store_true",
+ help="Verbose output."),
+ Option("-c", "--console",
+ default=False,
+ action="store_true",
+ help="Console output."),
+ Option("-d", "--debug",
+ default=False,
+ action="store_true",
+ help="Debug mode."),
+ ])
+
+ def check_args(self):
+ """
+ Check arguments
+ """
+ (options, args) = self.parse_args()
+ if len(args) != 1:
+ self.error("Incorrect number of arguments")
+
+ return options, args[0]
+
+class Config:
+ def setConfig(self, option_dict, configuration_file_path):
+ """
+ Set options given by parameters.
+ """
+ self.configuration_file_path = os.path.abspath(configuration_file_path)
+ # Set options parameters
+ for option, value in option_dict.__dict__.items():
+ setattr(self, option, value)
+
+ # Load configuration file
+ configuration_parser = ConfigParser.SafeConfigParser()
+ configuration_parser.read(configuration_file_path)
+ # Merges the arguments and configuration
+ for section in ("slaprunner", "slapos", "slapproxy", "slapformat"):
+ configuration_dict = dict(configuration_parser.items(section))
+ for key in configuration_dict:
+ if not getattr(self, key, None):
+ setattr(self, key, configuration_dict[key])
+
+ # set up logging
+ self.logger = logging.getLogger("slaprunner")
+ self.logger.setLevel(logging.INFO)
+ if self.console:
+ self.logger.addHandler(logging.StreamHandler())
+
+ if self.log_file:
+ if not os.path.isdir(os.path.dirname(self.log_file)):
+ # fallback to console only if directory for logs does not exists and
+ # continue to run
+ raise ValueError('Please create directory %r to store %r log file' % (
+ os.path.dirname(self.log_file), self.log_file))
+ else:
+ file_handler = logging.FileHandler(self.log_file)
+ file_handler.setFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
+ self.logger.addHandler(file_handler)
+ self.logger.info('Configured logging to file %r' % self.log_file)
+
+ self.logger.info("Started.")
+ if self.verbose:
+ self.logger.setLevel(logging.DEBUG)
+ self.logger.debug("Verbose mode enabled.")
+
+
+def run():
+ "Run default configuration."
+ usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
+
+ try:
+ # Parse arguments
+ config = Config()
+ config.setConfig(*Parser(usage=usage).check_args())
+
+ serve(config)
+ return_code = 0
+ except SystemExit, err:
+ # Catch exception raise by optparse
+ return_code = err
+
+ sys.exit(return_code)
+
+def serve(config):
+ from views import app
+ app.config.update(**config.__dict__)
+ app.config.update(
+ software_log=config.software_root.rstrip('/') + '.log',
+ instance_log=config.instance_root.rstrip('/') + '.log',
+ instance_profile=os.path.join(config.runner_workdir, 'instance.cfg'),
+ software_profile=os.path.join(config.runner_workdir, 'software.cfg'),
+ SECRET_KEY='123',
+ )
+ app.run(host=config.runner_host, port=int(config.runner_port),
+ debug=config.debug, threaded=True)
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/index.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/index.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/index.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/index.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,6 @@
+{% extends "layout.html" %}
+{% block body %}
+Welcome!<br>
+
+This is SlapOS buildout web based runner.
+{% endblock %}
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/instanceInspect.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/instanceInspect.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/instanceInspect.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/instanceInspect.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,13 @@
+{% extends "layout.html" %}
+{% block body %}
+Instance inspection<br>
+Supervisor:<br>
+<textarea cols=100 rows=10 readonly>{{ supervisor }}</textarea><br>
+SLAP:<br>
+{% for item in slap_status %}
+<b>{{ item[0 ]}}</b><br>
+<textarea cols=100 rows=5 readonly>{{ item[1] }}</textarea><br>
+{% endfor %}
+File content:<br>
+<textarea cols=100 rows=40 readonly>{{ file_content }}</textarea><br>
+{% endblock %}
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/layout.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/layout.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/layout.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/layout.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,31 @@
+<!doctype html>
+<title>Buildout runner</title>
+<div class=menu>
+<a href="{{ url_for('home') }}">Home</a> |
+Software:
+<a href="{{ url_for('editSoftwareProfile') }}">Edit</a>
+<a href="{{ url_for('runSoftwareProfile') }}">Run</a>
+<a href="{{ url_for('viewSoftwareLog') }}">Build log</a>
+<a href="{{ url_for('inspectSoftware') }}">Inspect</a>
+<a href="{{ url_for('removeSoftware') }}">Remove</a>
+|
+Instance
+<a href="{{ url_for('editInstanceProfile') }}">Edit</a>
+<a href="{{ url_for('runInstanceProfile') }}">Run</a>
+<a href="{{ url_for('viewInstanceLog') }}">Build log</a>
+<a href="{{ url_for('inspectInstance') }}">Inspect</a>
+<a href="{{ url_for('stopAllPartition') }}">Stop all</a>
+<a href="{{ url_for('removeInstance') }}">Remove</a>
+</div>
+{% with messages = get_flashed_messages() %}
+ {% if messages %}
+ <ul class=flashes>
+ {% for message in messages %}
+ <li>{{ message }}</li>
+ {% endfor %}
+ </ul>
+ {% endif %}
+{% endwith %}
+<div class=page>
+ {% block body %}{% endblock %}
+</div>
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/runResult.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/runResult.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/runResult.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/runResult.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,5 @@
+{% extends "layout.html" %}
+{% block body %}
+Result for {{ type }}<br>
+<textarea cols=100 rows=40 readonly>{{ result }}</textarea>
+{% endblock %}
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateInstanceProfile.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateInstanceProfile.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateInstanceProfile.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateInstanceProfile.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,11 @@
+{% extends "layout.html" %}
+{% block body %}
+<form action="{{ url_for('updateInstanceProfile') }}" method=post class=add-entry>
+ <dl>
+ <dt>Instance Profile:
+ <dd><textarea name=content rows=20 cols=100>{{ profile }}</textarea>
+ <dd><input type=submit value=Update>
+ </dl>
+ </form>
+{% endblock %}
+
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateSoftwareProfile.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateSoftwareProfile.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateSoftwareProfile.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/updateSoftwareProfile.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,12 @@
+{% extends "layout.html" %}
+{% block body %}
+<form action="{{ url_for('updateSoftwareProfile') }}" method=post class=add-entry>
+ <dl>
+ <dt>Note: Url of instance.cfg is <tt>{{ instance_url }}</tt>
+ <dt>Software Profile:
+ <dd><textarea name=content rows=20 cols=100>{{ profile }}</textarea>
+ <dd><input type=submit value=Update>
+ </dl>
+ </form>
+{% endblock %}
+
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/viewLog.html
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/viewLog.html?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/viewLog.html (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/templates/viewLog.html [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,7 @@
+{% extends "layout.html" %}
+{% block body %}
+Currently running: {{ running }}<br>
+Notre: You can refresh this page from time to time to have updates.<br>
+Result for {{ type }}<br>
+<textarea cols=100 rows=40 readonly>{{ result }}</textarea>
+{% endblock %}
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/utils.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/utils.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/utils.py (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/utils.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,187 @@
+import slapos.slap
+import time
+import subprocess
+import os
+from xml_marshaller import xml_marshaller
+
+
+class Popen(subprocess.Popen):
+ def __init__(self, *args, **kwargs):
+ kwargs['stdin'] = subprocess.PIPE
+ kwargs['stderr'] = subprocess.STDOUT
+ kwargs.setdefault('stdout', subprocess.PIPE)
+ kwargs.setdefault('close_fds', True)
+ subprocess.Popen.__init__(self, *args, **kwargs)
+ self.stdin.flush()
+ self.stdin.close()
+ self.stdin = None
+
+
+def updateProxy(config):
+ if not os.path.exists(config['instance_root']):
+ os.mkdir(config['instance_root'])
+ slap = slapos.slap.slap()
+ slap.initializeConnection(config['master_url'])
+ slap.registerSupply().supply(config['software_profile'], computer_guid=config['computer_id'])
+ computer = slap.registerComputer(config['computer_id'])
+ prefix = 'slappart'
+ slap_config = {
+ 'address': config['ipv4_address'],
+ 'instance_root': config['instance_root'],
+ 'netmask': '255.255.255.255',
+ 'partition_list': [
+ ],
+ 'reference': config['computer_id'],
+ 'software_root': config['software_root']}
+ for i in xrange(0, int(config['partition_amount'])):
+ partition_reference = '%s%s' % (prefix, i)
+ partition_path = os.path.join(config['instance_root'], partition_reference)
+ if not os.path.exists(partition_path):
+ os.mkdir(partition_path)
+ os.chmod(partition_path, 0750)
+ slap_config['partition_list'].append({'address_list': [{'addr': config['ipv4_address'],
+ 'netmask': '255.255.255.255'},
+ {'addr': config['ipv6_address'],
+ 'netmask': 'ffff:ffff:ffff::'},
+ ],
+ 'path': partition_path,
+ 'reference': partition_reference,
+ 'tap': {'name': partition_reference},
+ })
+
+ computer.updateConfiguration(xml_marshaller.dumps(slap_config))
+ slap.registerOpenOrder().request(config['software_profile'],
+ partition_reference=partition_reference)
+
+
+def readPid(file):
+ if os.path.exists(file):
+ data = open(file).read().strip()
+ try:
+ return int(data)
+ except Exception:
+ return 0
+ return 0
+
+
+def writePid(file, pid):
+ open(file, 'w').write(str(pid))
+
+
+def startProxy(config):
+ proxy_pid = os.path.join(config['runner_workdir'], 'proxy.pid')
+ pid = readPid(proxy_pid)
+ running = False
+ if pid:
+ try:
+ os.kill(pid, 0)
+ except Exception:
+ pass
+ else:
+ running = True
+ if not running:
+ proxy = Popen([config['slapproxy'], config['configuration_file_path']])
+ proxy_pid = os.path.join(config['runner_workdir'], 'proxy.pid')
+ writePid(proxy_pid, proxy.pid)
+ time.sleep(5)
+
+
+def stopProxy(config):
+ pid = readPid(os.path.join(config['runner_workdir'], 'proxy.pid'))
+ if pid:
+ try:
+ os.kill(pid)
+ except:
+ pass
+
+
+def removeProxyDb(config):
+ if os.path.exists(config['database_uri']):
+ os.unlink(config['database_uri'])
+
+def isSoftwareRunning(config):
+ slapgrid_pid = os.path.join(config['runner_workdir'], 'slapgrid-sr.pid')
+ pid = readPid(slapgrid_pid)
+ if pid:
+ try:
+ os.kill(pid, 0)
+ except Exception:
+ running = False
+ else:
+ running = True
+ else:
+ running = False
+ return running
+
+
+def runSoftwareWithLock(config):
+ slapgrid_pid = os.path.join(config['runner_workdir'], 'slapgrid-sr.pid')
+ if not isSoftwareRunning(config):
+ if not os.path.exists(config['software_root']):
+ os.mkdir(config['software_root'])
+ stopProxy(config)
+ removeProxyDb(config)
+ startProxy(config)
+ logfile = open(config['software_log'], 'w')
+ updateProxy(config)
+ slapgrid = Popen([config['slapgrid_sr'], '-vc', config['configuration_file_path']], stdout=logfile)
+ writePid(slapgrid_pid, slapgrid.pid)
+ slapgrid.wait()
+ return True
+ return False
+
+
+def isInstanceRunning(config):
+ slapgrid_pid = os.path.join(config['runner_workdir'], 'slapgrid-cp.pid')
+ pid = readPid(slapgrid_pid)
+ if pid:
+ try:
+ os.kill(pid, 0)
+ except Exception:
+ running = False
+ else:
+ running = True
+ else:
+ running = False
+ return running
+
+
+def runInstanceWithLock(config):
+ slapgrid_pid = os.path.join(config['runner_workdir'], 'slapgrid-cp.pid')
+ if not isInstanceRunning(config):
+ startProxy(config)
+ logfile = open(config['instance_log'], 'w')
+ updateProxy(config)
+ slapgrid = Popen([config['slapgrid_cp'], '-vc', config['configuration_file_path']], stdout=logfile)
+ writePid(slapgrid_pid, slapgrid.pid)
+ slapgrid.wait()
+ return True
+ return False
+
+
+def getProfile(profile):
+ if os.path.exists(profile):
+ return open(profile).read()
+ else:
+ return ''
+
+
+def getSlapStatus(config):
+ slap = slapos.slap.slap()
+ slap.initializeConnection(config['master_url'])
+ partition_list = []
+ computer = slap.registerComputer(config['computer_id'])
+ try:
+ for partition in computer.getComputerPartitionList():
+ # Note: Internal use of API, as there is no reflexion interface in SLAP
+ partition_list.append((partition.getId(), partition._connection_dict.copy()))
+ except Exception:
+ pass
+ return partition_list
+
+
+def svcStopAll(config):
+ return Popen([config['supervisor'], '-c', config['supervisord_config'], 'shutdown']).communicate()[0]
+
+def getSvcStatus(config):
+ return Popen([config['supervisor'], '-c', config['supervisord_config'], 'status']).communicate()[0]
Added: slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/views.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/views.py?rev=45226&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/views.py (added)
+++ slapos/trunk/util/slapos.tool.runner/src/slapos/tool/runner/views.py [utf8] Fri Apr 8 11:29:51 2011
@@ -0,0 +1,122 @@
+from flask import Flask, request, redirect, url_for, \
+ render_template, flash
+from utils import getProfile, runInstanceWithLock, runSoftwareWithLock, Popen, isInstanceRunning, isSoftwareRunning, getSvcStatus, getSlapStatus, svcStopAll
+import os
+import shutil
+
+app = Flask(__name__)
+
+# general views
+ at app.route('/')
+def home():
+ return render_template('index.html')
+
+# software views
+ at app.route('/editSoftwareProfile')
+def editSoftwareProfile():
+ return render_template('updateSoftwareProfile.html',
+ profile=getProfile(app.config['software_profile']), instance_url=url_for('getInstance', _external=True))
+
+ at app.route('/software.cfg', methods=['GET', 'POST'])
+def getSoftware():
+ return getProfile(app.config['software_profile'])
+
+ at app.route('/inspectSoftware', methods=['GET'])
+def inspectSoftware():
+ if not os.path.exists(app.config['software_root']):
+ result = "Does not exists yet"
+ else:
+ process = Popen(['find'], cwd=app.config['software_root'])
+ result = process.communicate()[0]
+ return render_template('runResult.html', type='Software',
+ result=result)
+
+ at app.route('/removeSoftware')
+def removeSoftware():
+ if isSoftwareRunning(app.config) or isInstanceRunning(app.config):
+ flash('Software installation or instantiation in progress, cannot remove')
+ elif os.path.exists(app.config['software_root']):
+ svcStopAll(app.config)
+ shutil.rmtree(app.config['software_root'])
+ flash('Software removed')
+ return redirect(url_for('inspectSoftware'))
+
+ at app.route('/runSoftwareProfile', methods=['GET'])
+def runSoftwareProfile():
+ if runSoftwareWithLock(app.config):
+ flash('Started.')
+ else:
+ flash('Already running.')
+ return redirect(url_for('viewSoftwareLog'))
+
+ at app.route('/viewSoftwareLog', methods=['GET'])
+def viewSoftwareLog():
+ if os.path.exists(app.config['software_log']):
+ result = open(app.config['software_log'], 'r').read()
+ else:
+ result = 'Not found yet'
+ return render_template('viewLog.html', type='Software',
+ result=result, running=isSoftwareRunning(app.config))
+
+ at app.route('/updateSoftwareProfile', methods=['POST'])
+def updateSoftwareProfile():
+ open(app.config['software_profile'], 'w').write(request.form['content'])
+ return redirect(url_for('editSoftwareProfile'))
+
+# instance views
+ at app.route('/editInstanceProfile')
+def editInstanceProfile():
+ return render_template('updateInstanceProfile.html',
+ profile=getProfile(app.config['instance_profile']))
+
+ at app.route('/instance.cfg', methods=['GET', 'POST'])
+def getInstance():
+ return getProfile(app.config['instance_profile'])
+
+ at app.route('/inspectInstance', methods=['GET'])
+def inspectInstance():
+ file_content = 'Does not exists yet.'
+ if os.path.exists(app.config['instance_root']):
+ process = Popen(['find'], cwd=app.config['instance_root'])
+ file_content = process.communicate()[0]
+ return render_template('instanceInspect.html',
+ file_content=file_content, supervisor=getSvcStatus(app.config), slap_status=getSlapStatus(app.config))
+
+ at app.route('/removeInstance')
+def removeInstance():
+ if isInstanceRunning(app.config):
+ flash('Instantiation in progress, cannot remove')
+ elif os.path.exists(app.config['instance_root']):
+ svcStopAll(app.config)
+ shutil.rmtree(app.config['instance_root'])
+ flash('Instance removed')
+ return redirect(url_for('inspectInstance'))
+
+ at app.route('/runInstanceProfile', methods=['GET'])
+def runInstanceProfile():
+ if not os.path.exists(app.config['instance_root']):
+ os.mkdir(app.config['instance_root'])
+ if runInstanceWithLock(app.config):
+ flash('Started.')
+ else:
+ flash('Already running.')
+ return redirect(url_for('viewInstanceLog'))
+
+ at app.route('/viewInstanceLog', methods=['GET'])
+def viewInstanceLog():
+ if os.path.exists(app.config['instance_log']):
+ result = open(app.config['instance_log'], 'r').read()
+ else:
+ result = 'Not found yet'
+ return render_template('viewLog.html', type='Instance',
+ result=result, running=isInstanceRunning(app.config))
+
+ at app.route('/updateInstanceProfile', methods=['POST'])
+def updateInstanceProfile():
+ open(app.config['instance_profile'], 'w').write(request.form['content'])
+ return redirect(url_for('editInstanceProfile'))
+
+ at app.route('/stopAllPartition', methods=['GET'])
+def stopAllPartition():
+ svcStopAll(app.config)
+ return redirect(url_for('inspectInstance'))
More information about the Erp5-report
mailing list