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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3KB

  1. #
  2. # Copyright (C) Stanislaw Adaszewski, 2020
  3. # License: GNU General Public License v3.0
  4. # URL: https://github.com/sadaszewski/focker
  5. # URL: https://adared.ch/focker
  6. #
  7. from .misc import random_sha256_hexdigest
  8. from .zfs import *
  9. from tabulate import tabulate
  10. def command_volume_create(args):
  11. sha256 = random_sha256_hexdigest()
  12. poolname = zfs_poolname()
  13. for pre in range(7, 64):
  14. name = poolname + '/focker/volumes/' + sha256[:pre]
  15. if not zfs_exists(name):
  16. break
  17. zfs_run(['zfs', 'create', '-o', 'focker:sha256=' + sha256, name])
  18. zfs_untag(args.tags, focker_type='volume')
  19. zfs_tag(name, args.tags)
  20. def command_volume_prune(args):
  21. zfs_prune(focker_type='volume')
  22. def command_volume_list(args):
  23. poolname = zfs_poolname()
  24. lst = zfs_parse_output(['zfs', 'list', '-o', 'name,refer,focker:sha256,focker:tags,mountpoint', '-H', '-r', poolname + '/focker/volumes'])
  25. lst = list(filter(lambda a: a[2] != '-', lst))
  26. lst = list(map(lambda a: [ a[3], a[1],
  27. a[2] if args.full_sha256 else a[2][:7],
  28. a[4] ], lst))
  29. print(tabulate(lst, headers=['Tags', 'Size', 'SHA256', 'Mountpoint']))
  30. def command_volume_tag(args):
  31. name, _ = zfs_find(args.reference, focker_type='volume')
  32. zfs_untag(args.tags, focker_type='volume')
  33. zfs_tag(name, args.tags)
  34. def command_volume_untag(args):
  35. zfs_untag(args.tags, focker_type='volume')
  36. def command_volume_remove(args):
  37. for ref in args.references:
  38. try:
  39. name, _ = zfs_find(ref, focker_type='volume')
  40. print('Removing:', name)
  41. zfs_run(['zfs', 'destroy', '-r', '-f', name])
  42. except:
  43. if not args.force:
  44. raise
  45. def command_volume_set(args):
  46. name, _ = zfs_find(args.reference, focker_type='volume')
  47. if not args.properties:
  48. raise ValueError('You must specify some properties')
  49. zfs_run(['zfs', 'set'] + args.properties + [name])
  50. def command_volume_get(args):
  51. name, _ = zfs_find(args.reference, focker_type='volume')
  52. if not args.properties:
  53. raise ValueError('You must specify some properties')
  54. res = zfs_parse_output(['zfs', 'get', '-H', ','.join(args.properties), name])
  55. res = map(lambda a: a[2], res)
  56. print('\n'.join(res))