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!
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

88 Zeilen
2.7KB

  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_destroy(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 = [ [ args.properties[i], a[2] ] for i, a in enumerate(res) ]
  56. print(tabulate(res, headers=['Property', 'Value']))
  57. def command_volume_protect(args):
  58. for ref in args.references:
  59. name, _ = zfs_find(ref, focker_type='volume')
  60. print('Protecting:', name)
  61. zfs_protect(name)
  62. def command_volume_unprotect(args):
  63. for ref in args.references:
  64. name, _ = zfs_find(ref, focker_type='volume')
  65. print('Unprotecting:', name)
  66. zfs_unprotect(name)