IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Browse Source

Compose seems to work pretty much.

tags/0.92
parent
commit
715893d6b2
2 changed files with 38 additions and 3 deletions
  1. +35
    -2
      focker/compose.py
  2. +3
    -1
      focker/jail.py

+ 35
- 2
focker/compose.py View File

@@ -2,10 +2,17 @@ import os
import yaml import yaml
from .zfs import AmbiguousValueError, \ from .zfs import AmbiguousValueError, \
zfs_find, \ zfs_find, \
zfs_tag
zfs_tag, \
zfs_untag, \
zfs_mountpoint
from .jail import jail_fs_create, \
jail_create, \
jail_remove
from .misc import random_sha256_hexdigest, \ from .misc import random_sha256_hexdigest, \
find_prefix find_prefix
import subprocess import subprocess
import jailconf
import os
def build_volumes(spec): def build_volumes(spec):
@@ -34,7 +41,33 @@ def build_images(spec, path):
def build_jails(spec): def build_jails(spec):
print('build_jails(): NotImplementedError')
#if os.path.exists('/etc/jail.conf'):
# conf = jailconf.load('/etc/jail.conf')
#else:
# conf = jailconf.JailConf()
for (jailname, jailspec) in spec.items():
try:
name, _ = zfs_find(jailname, focker_type='jail')
jail_remove(zfs_mountpoint(name))
except AmbiguousValueError:
raise
except ValueError:
pass
name = jail_fs_create(jailspec['image'])
zfs_untag([ jailname ], focker_type='jail')
zfs_tag(name, [ jailname ])
path = zfs_mountpoint(name)
jail_create(path,
jailspec.get('exec.start', '/bin/sh /etc/rc'),
jailspec.get('env', {}),
[ [from_, on] \
for (from_, on) in jailspec.get('mounts', {}).items() ],
hostname=jailname,
overrides={
'exec.stop': jailspec.get('exec.stop', '/bin/sh /etc/rc.shutdown'),
'ip4.addr': jailspec.get('ip4.addr', '127.0.1.0'),
'interface': jailspec.get('interface', 'lo1')
})
def command_compose_build(args): def command_compose_build(args):


+ 3
- 1
focker/jail.py View File

@@ -47,7 +47,7 @@ def quote(s):
return s return s
def jail_create(path, command, env, mounts, hostname=None):
def jail_create(path, command, env, mounts, hostname=None, overrides={}):
name = os.path.split(path)[-1] name = os.path.split(path)[-1]
if os.path.exists('/etc/jail.conf'): if os.path.exists('/etc/jail.conf'):
conf = jailconf.load('/etc/jail.conf') conf = jailconf.load('/etc/jail.conf')
@@ -83,6 +83,8 @@ def jail_create(path, command, env, mounts, hostname=None):
blk['mount.devfs'] = True blk['mount.devfs'] = True
blk['exec.clean'] = True blk['exec.clean'] = True
blk['host.hostname'] = hostname or name blk['host.hostname'] = hostname or name
for (k, v) in overrides.items():
blk[k] = quote(v)
conf.write('/etc/jail.conf') conf.write('/etc/jail.conf')
return name return name


Loading…
Cancel
Save