qvm-grow-root 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/python2
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2014 Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License
  9. # as published by the Free Software Foundation; either version 2
  10. # of the License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. #
  21. #
  22. from qubes.qubes import QubesVmCollection
  23. from qubes.qubes import QubesException
  24. from qubes.qubesutils import parse_size
  25. from optparse import OptionParser
  26. import subprocess
  27. import os
  28. import re
  29. import sys
  30. def main():
  31. usage = "usage: %prog <vm-name> <size>"
  32. parser = OptionParser (usage)
  33. (options, args) = parser.parse_args ()
  34. if (len (args) != 2):
  35. parser.error ("You must specify VM name and new size!")
  36. vmname = args[0]
  37. size = args[1]
  38. qvm_collection = QubesVmCollection()
  39. qvm_collection.lock_db_for_reading()
  40. qvm_collection.load()
  41. qvm_collection.unlock_db()
  42. vm = qvm_collection.get_vm_by_name(vmname)
  43. if vm is None:
  44. print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
  45. exit(1)
  46. size_bytes = parse_size(size)
  47. if not hasattr(vm, 'resize_root_img'):
  48. print >> sys.stderr, "Operation not supported for this VM type"
  49. exit(1)
  50. try:
  51. vm.resize_root_img(size_bytes)
  52. except (IOError, OSError, QubesException) as err:
  53. print >> sys.stderr, "ERROR: {0}".format(err)
  54. exit (1)
  55. exit (0)
  56. main()