Commit d2df81f3 authored by Antoine Catton's avatar Antoine Catton

Switch to image use

parent ce197340
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
import ConfigParser import ConfigParser
import os import os
import subprocess import subprocess
import shutil
import lockfile import lockfile
...@@ -32,7 +31,6 @@ def main(sr_directory, partition_list, bridge_name): ...@@ -32,7 +31,6 @@ def main(sr_directory, partition_list, bridge_name):
'status') 'status')
if requested_status == 'started': if requested_status == 'started':
if not created(partition_path, slapcontainer_conf):
create(sr_directory, partition_path, create(sr_directory, partition_path,
slapcontainer_conf, bridge_name) slapcontainer_conf, bridge_name)
if status(sr_directory, partition_path) == 'stopped': if status(sr_directory, partition_path) == 'stopped':
...@@ -67,47 +65,10 @@ def stop(sr_directory, partition_path): ...@@ -67,47 +65,10 @@ def stop(sr_directory, partition_path):
def created(partition_path, conf):
return os.path.exists(conf.get('rootfs', 'directory')) and \
os.path.exists(conf.get('config', 'file'))
def extract_rootfs(partition_path, conf):
tmp_dir = conf.get('rootfs', 'tmp')
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.mkdir(tmp_dir)
call([conf.get('tar', 'binary'),
'-xf', conf.get('tar', 'archive'),
'-C', tmp_dir],
{'PATH': '%s:%s' % (os.environ, conf.get('tar', 'path'))})
lst_tmp_dir = os.listdir(tmp_dir)
if len(lst_tmp_dir) > 1:
rootfs = tmp_dir
else:
rootfs = os.path.join(tmp_dir, lst_tmp_dir[0])
shutil.move(rootfs, conf.get('rootfs', 'directory'))
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
def create(sr_directory, partition_path, conf, bridge_name): def create(sr_directory, partition_path, conf, bridge_name):
tmp_dir = conf.get('rootfs', 'tmp') lxc_filename = conf.get('config', 'file')
rootfs_dir = conf.get('rootfs', 'directory')
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
if os.path.exists(rootfs_dir):
shutil.rmtree(rootfs_dir)
extract_rootfs(partition_path, conf)
lxc_filename = os.path.join(partition_path, 'config')
lxc = LXCConfig() lxc = LXCConfig()
lxc.utsname = os.path.basename(partition_path) lxc.utsname = conf.get('requested', 'name')
lxc.network.type = 'veth' lxc.network.type = 'veth'
lxc.network.link = bridge_name lxc.network.link = bridge_name
lxc.network.veth.pair = 'lxc%s' % conf.get('network', 'interface') lxc.network.veth.pair = 'lxc%s' % conf.get('network', 'interface')
...@@ -130,11 +91,13 @@ def create(sr_directory, partition_path, conf, bridge_name): ...@@ -130,11 +91,13 @@ def create(sr_directory, partition_path, conf, bridge_name):
'c 5:2 rwm', 'c 5:2 rwm',
'c 254:0 rwm', 'c 254:0 rwm',
] ]
lxc.mount.entry = [ # XXX : This is a relic of previous code, even if it is versionned
'proc %s proc nodev,noexec,nosuid 0 0' % os.path.join(rootfs_dir, 'proc'), # this could be usefull in future
'sysfs %s sysfs defaults 0 0' % os.path.join(rootfs_dir, 'sys'), # lxc.mount.entry = [
] # 'proc %s proc nodev,noexec,nosuid 0 0' % os.path.join(rootfs_dir, 'proc'),
lxc.rootfs = rootfs_dir # 'sysfs %s sysfs defaults 0 0' % os.path.join(rootfs_dir, 'sys'),
# ]
lxc.rootfs = conf.get('rootfs', 'image')
with open(lxc_filename, 'w') as lxc_file: with open(lxc_filename, 'w') as lxc_file:
lxc_file.write(str(lxc)) lxc_file.write(str(lxc))
......
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