qvm-grow-private 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/python2
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2011 Marek Marczykowski <marmarek@mimuw.edu.pl>
  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. qvm_run_path = "/usr/bin/qvm-run"
  31. def main():
  32. usage = "usage: %prog <vm-name> <size>"
  33. parser = OptionParser (usage)
  34. (options, args) = parser.parse_args ()
  35. if (len (args) != 2):
  36. parser.error ("You must specify VM name and new size!")
  37. vmname = args[0]
  38. size = args[1]
  39. qvm_collection = QubesVmCollection()
  40. qvm_collection.lock_db_for_reading()
  41. qvm_collection.load()
  42. qvm_collection.unlock_db()
  43. vm = qvm_collection.get_vm_by_name(vmname)
  44. if vm is None:
  45. print >> sys.stderr, "A VM with the name '{0}' does not exist in the system.".format(vmname)
  46. exit(1)
  47. size_bytes = parse_size(size)
  48. try:
  49. vm.resize_private_img(size_bytes)
  50. except (IOError, OSError, QubesException) as err:
  51. print >> sys.stderr, "ERROR: {0}".format(err)
  52. exit (1)
  53. exit (0)
  54. main()