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

Implemented focker volume commands.

tags/0.92
parent
commit
d486942530
4 changed files with 36 additions and 5 deletions
  1. +2
    -0
      focker.py
  2. +2
    -1
      image.py
  3. +12
    -4
      volume.py
  4. +20
    -0
      zfs.py

+ 2
- 0
focker.py View File

@@ -69,9 +69,11 @@ def create_parser():
parser = subparsers.add_parser('list') parser = subparsers.add_parser('list')
parser.set_defaults(func=command_volume_list) parser.set_defaults(func=command_volume_list)
parser.add_argument('--full-sha256', '-f', action='store_true')
parser = subparsers.add_parser('tag') parser = subparsers.add_parser('tag')
parser.set_defaults(func=command_volume_tag) parser.set_defaults(func=command_volume_tag)
parser.add_argument('reference', type=str)
parser.add_argument('tags', type=str, nargs='+') parser.add_argument('tags', type=str, nargs='+')
parser = subparsers.add_parser('untag') parser = subparsers.add_parser('untag')


+ 2
- 1
image.py View File

@@ -98,10 +98,11 @@ def command_image_list(args):
def command_image_prune(args): def command_image_prune(args):
poolname = zfs_poolname()
again = True again = True
while again: while again:
again = False again = False
lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:sha256,focker:tags,origin,name', '-H'])
lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:sha256,focker:tags,origin,name', '-H', '-r', poolname + '/focker/images'])
used = set() used = set()
for r in lst: for r in lst:
if r[2] == '-': if r[2] == '-':


+ 12
- 4
volume.py View File

@@ -1,5 +1,6 @@
from .misc import random_sha256_hexdigest from .misc import random_sha256_hexdigest
from .zfs import * from .zfs import *
from tabulate import tabulate
def command_volume_create(args): def command_volume_create(args):
@@ -14,16 +15,23 @@ def command_volume_create(args):
def command_volume_prune(args): def command_volume_prune(args):
raise NotImplementedError
zfs_prune(focker_type='volume')
def command_volume_list(args): def command_volume_list(args):
raise NotImplementedError
poolname = zfs_poolname()
lst = zfs_parse_output(['zfs', 'list', '-o', 'name,refer,focker:sha256,focker:tags', '-H', '-r', poolname + '/focker/volumes'])
lst = list(filter(lambda a: a[2] != '-', lst))
lst = list(map(lambda a: [ a[3], a[1],
a[2] if args.full_sha256 else a[2][:7] ], lst))
print(tabulate(lst, headers=['Tags', 'Size', 'SHA256']))
def command_volume_tag(args): def command_volume_tag(args):
raise NotImplementedError
name, _ = zfs_find(args.reference, focker_type='volume')
zfs_untag(args.tags)
zfs_tag(name, args.tags)
def command_volume_untag(args): def command_volume_untag(args):
raise NotImplementedError
zfs_untag(args.tags)

+ 20
- 0
zfs.py View File

@@ -49,6 +49,26 @@ def zfs_find(reference, focker_type='image', zfs_type='filesystem'):
return (lst[0][3], lst[0][0]) return (lst[0][3], lst[0][0])
def zfs_prune(focker_type='image'):
poolname = zfs_poolname()
again = True
while again:
again = False
lst = zfs_parse_output(['zfs', 'list', '-o', 'focker:sha256,focker:tags,origin,name', '-H', '-r', poolname + '/focker/' + focker_type + 's'])
used = set()
for r in lst:
if r[2] == '-':
continue
used.add(r[2].split('@')[0])
for r in lst:
if r[0] == '-' or r[1] != '-':
continue
if r[3] not in used:
print('Removing:', r[3])
zfs_run(['zfs', 'destroy', '-r', '-f', r[3]])
again = True
def zfs_clone(name, target_name): def zfs_clone(name, target_name):
zfs_run(['zfs', 'clone', name, target_name]) zfs_run(['zfs', 'clone', name, target_name])


Loading…
Cancel
Save