Commit 079c8333 authored by Antoine Catton's avatar Antoine Catton

Implement stopping/destroy of partitions

parent ad426dc5
...@@ -17,6 +17,7 @@ class SlapContainerError(Exception): ...@@ -17,6 +17,7 @@ class SlapContainerError(Exception):
def main(sr_directory, partition_list, bridge_name): def main(sr_directory, partition_list, bridge_name):
started_containers = set()
for partition_path in partition_list: for partition_path in partition_list:
slapcontainer_filename = os.path.join(partition_path, slapcontainer_filename = os.path.join(partition_path,
'.slapcontainer') '.slapcontainer')
...@@ -37,6 +38,9 @@ def main(sr_directory, partition_list, bridge_name): ...@@ -37,6 +38,9 @@ def main(sr_directory, partition_list, bridge_name):
slapcontainer_conf) == 'stopped': slapcontainer_conf) == 'stopped':
start(sr_directory, partition_path, start(sr_directory, partition_path,
slapcontainer_conf) slapcontainer_conf)
started_containers.add(
slapcontainer_conf.get('requested', 'name')
)
else: else:
if status(sr_directory, partition_path, if status(sr_directory, partition_path,
slapcontainer_conf) == 'started': slapcontainer_conf) == 'started':
...@@ -47,6 +51,26 @@ def main(sr_directory, partition_list, bridge_name): ...@@ -47,6 +51,26 @@ def main(sr_directory, partition_list, bridge_name):
finally: finally:
lock.release() lock.release()
try:
active_containers = set(call(
[os.path.join(sr_directory, 'parts/lxc/bin/lxc-ls'),
'--active']
).split('\n'))
except SlapContainerError:
active_containers = set()
to_stop = active_containers - started_containers
for container in to_stop:
try:
call(
[os.path.join(sr_directory, 'parts/lxc/bin/lxc-stop'),
'-n', container
]
)
except SlapContainerError:
pass # TODO : put some log
def start(sr_directory, partition_path, conf): def start(sr_directory, partition_path, conf):
...@@ -107,12 +131,6 @@ def create(sr_directory, partition_path, conf, bridge_name): ...@@ -107,12 +131,6 @@ def create(sr_directory, partition_path, conf, bridge_name):
def destroy(partition_path):
# TODO: Destroy container
pass
def status(sr_directory, partition_path, conf): def status(sr_directory, partition_path, conf):
lxc_info = call([os.path.join(sr_directory, 'parts/lxc/bin/lxc-info'), lxc_info = call([os.path.join(sr_directory, 'parts/lxc/bin/lxc-info'),
'-n', conf.get('requested', 'name')]) '-n', conf.get('requested', 'name')])
......
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