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!
Quellcode durchsuchen

Added focker image tag

tags/0.92
Stanislaw Adaszewski vor 4 Jahren
Ursprung
Commit
0435624b8d
4 geänderte Dateien mit 36 neuen und 2 gelöschten Zeilen
  1. +6
    -0
      focker.py
  2. +6
    -0
      image.py
  3. +1
    -1
      jail.py
  4. +23
    -1
      zfs.py

+ 6
- 0
focker.py Datei anzeigen

@@ -3,6 +3,7 @@ import yaml
import os
# from weir import zfs, process
from .image import command_image_build, \
command_image_tag, \
command_image_untag, \
command_image_list, \
command_image_prune, \
@@ -22,6 +23,11 @@ def create_parser():
parser.add_argument('focker_dir', type=str)
parser.add_argument('--tag', '-t', type=str, nargs='+', default=[])
parser = subparsers.add_parser('tag')
parser.set_defaults(func=command_image_tag)
parser.add_argument('reference', type=str)
parser.add_argument('tags', type=str, nargs='+')
parser = subparsers.add_parser('untag')
parser.set_defaults(func=command_image_untag)
parser.add_argument('tags', type=str, nargs='+', default=[])


+ 6
- 0
image.py Datei anzeigen

@@ -78,6 +78,12 @@ def command_image_build(args):
zfs_tag(image.split('@')[0], args.tag)
def command_image_tag(args):
zfs_untag(args.tags)
name, _ = zfs_find(args.reference, focker_type='image', zfs_type='filesystem')
zfs_tag(name, args.tags)
def command_image_untag(args):
zfs_untag(args.tags)


+ 1
- 1
jail.py Datei anzeigen

@@ -20,6 +20,7 @@ def jail_run(path, command):
command = ['jail', '-c', 'host.hostname=' + os.path.split(path)[1], 'persist=1', 'mount.devfs=1', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + path, 'command', '/bin/sh', '-c', command]
print('Running:', ' '.join(command))
try:
shutil.copyfile('/etc/resolv.conf', os.path.join(path, 'etc/resolv.conf'))
res = subprocess.run(command)
finally:
try:
@@ -42,7 +43,6 @@ def command_jail_run(args):
break
zfs_run(['zfs', 'clone', base, name])
try:
shutil.copyfile('/etc/resolv.conf', os.path.join(zfs_mountpoint(name), 'etc/resolv.conf'))
jail_run(zfs_mountpoint(name), args.command)
# subprocess.check_output(['jail', '-c', 'interface=lo1', 'ip4.addr=127.0.1.0', 'path=' + zfs_mountpoint(name), 'command', command])
finally:


+ 23
- 1
zfs.py Datei anzeigen

@@ -32,6 +32,23 @@ def zfs_snapshot_by_tag_or_sha256(s):
return (lst[0][3], lst[0][0])
def zfs_find(reference, focker_type='image', zfs_type='filesystem'):
poolname = zfs_poolname()
lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:sha256,focker:tags,type,name', '-H', '-t', zfs_type, '-r', poolname + '/focker/' + focker_type + 's'])
def match(sha256, tags, type, name):
if sha256.startswith(reference) or \
any(map(lambda a: a.startswith(reference), tags.split(' '))) or \
name.split('/')[-1].startswith(reference):
return True
return False
lst = list(filter(lambda a: match(*a), lst))
if len(lst) == 0:
raise ValueError('Reference not found: ' + reference)
if len(lst) > 1:
raise ValueError('Ambiguous reference: ' + reference)
return (lst[0][3], lst[0][0])
def zfs_clone(name, target_name):
zfs_run(['zfs', 'clone', name, target_name])
@@ -97,11 +114,16 @@ def zfs_untag(tags):
zfs_tag(row[0], cur_tags, replace=True)
def zfs_init():
def zfs_poolname():
poolname = zfs_parse_output(['zfs', 'list', '-H', '/'])
if len(poolname) == 0:
raise ValueError('Not a ZFS root')
poolname = poolname[0][0].split('/')[0]
return poolname
def zfs_init():
poolname = zfs_poolname()
print('poolname:', poolname)
for path in ['/focker', '/focker/images', '/focker/volumes', '/focker/jails']:
if not os.path.exists(path):


Laden…
Abbrechen
Speichern