Commit a537db8b authored by Antoine Catton's avatar Antoine Catton

Skeleton of slapcontainer script

parent 873a5b35
......@@ -41,6 +41,7 @@ setup(name=name,
'slapos.core', # as it provides library for slap
'xml_marshaller', # needed to dump information
'GitPython', #needed for git manipulation into slaprunner
'lockfile', #needed for interprocess exclusion (in slapcontainer)
] + additional_install_requires,
extras_require = {
'lampconfigure': ["mysql-python"], #needed for MySQL Database access
......@@ -73,6 +74,7 @@ setup(name=name,
'pubsubnotifier = slapos.pubsub.notifier:main',
'slaprunnertest = slapos.runner.testRunner:run',
'zodbpack = slapos.zodbpack:run [zodbpack]',
'slapcontainer = slapos.container:main',
]
},
)
# -*- coding: utf-8 -*-
import ConfigParser
import sys
import os
from . import prepare
def main():
slapos_conf = ConfigParser.ConfigParser()
slapos_conf.read(sys.argv[1])
current_binary = os.path.join(os.getcwd(), sys.argv[0])
binary_directory = os.path.dirname(current_binary)
sr_directory = os.path.realpath(os.path.join(binary_directory, '..'))
partition_amount = slapos_conf.getint('slapformat', 'partition_amount')
partition_base_name = slapos_conf.get('slapformat', 'partition_base_name')
instance_root = slapos_conf.get('slapos', 'instance_root')
partition_base_path = os.path.join(instance_root, partition_base_name)
partition_list = ['%s%d' % (partition_base_path, i)
for i in range(partition_amount)]
prepare.main(sr_directory, partition_list)
# -*- coding: utf-8 -*-
import ConfigParser
import os
import lockfile
def main(sr_directory, partition_list):
overall_failure = 0
for partition_path in partition_list:
slapcontainer_filename = os.path.join(partition_path,
'.slapcontainer')
if os.path.isfile(slapcontainer_filename):
failure = 0
lock = lockfile.FileLock(slapcontainer_filename)
try:
lock.acquire(timeout=0)
slapcontainer_conf = ConfigParser.ConfigParser()
slapcontainer_conf.read(slapcontainer_filename)
requested_status = slapcontainer_conf.get('requested', 'status')
if not slapcontainer_conf.has_section('current'):
slapcontainer_conf.add_section('current')
if not slapcontainer_conf.has_option('current', 'created'):
slapcontainer_conf.set('current', 'created', 'no')
if not slapcontainer_conf.has_option('current', 'status'):
slapcontainer_conf.set('current', 'status', 'stopped')
if requested_status == 'started':
failure |= start(sr_directory, partition_path,
slapcontainer_conf)
else:
failure |= stop(sr_directory, partition_path,
slapcontainer_conf)
with open(slapcontainer_filename, 'w') as slapcontainer_fp:
slapcontainer_conf.write(slapcontainer_fp)
except lockfile.LockTimeout:
# Can't do anything, we'll see on the next run
pass
finally:
lock.release()
overall_failure |= failure
return overall_failure
def start(sr_directory, partition_path, conf):
failure = 0
if conf.get('current', 'created') == 'no':
failure |= create(sr_directory, partition_path, conf)
if failure:
return failure
else:
conf.set('current', 'created', 'yes')
# TODO: Check if container is started,
# Start container
conf.set('current', 'status', 'started')
return failure
def stop(sr_directory, partition_path, conf):
failure = 0
# TODO : Check if container is stopped
# Stop container
if conf.get('current', 'created') == 'yes':
failure |= destroy(partition_path, conf)
return failure
def create(sr_directory, partition_path, conf):
failure = 0
# TODO : Create container
return failure
def destroy(partition_path, conf):
failure = 0
# TODO: Destroy container
return failure
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