01QubesDisposableVm.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/usr/bin/python2
  2. # -*- coding: utf-8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2010 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2013 Marek Marczykowski <marmarek@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or
  10. # modify it under the terms of the GNU General Public License
  11. # as published by the Free Software Foundation; either version 2
  12. # of the License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program; if not, write to the Free Software
  21. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22. #
  23. #
  24. import sys
  25. from qubes.qubes import QubesVm,QubesVmLabel,register_qubes_vm_class
  26. from qubes.qubes import QubesDispVmLabels
  27. class QubesDisposableVm(QubesVm):
  28. """
  29. A class that represents an DisposableVM. A child of QubesVm.
  30. """
  31. # In which order load this VM type from qubes.xml
  32. load_order = 120
  33. def get_attrs_config(self):
  34. attrs_config = super(QubesDisposableVm, self).get_attrs_config()
  35. # New attributes
  36. attrs_config['dispid'] = { 'save': lambda: str(self.dispid) }
  37. attrs_config['include_in_backups']['func'] = lambda x: False
  38. return attrs_config
  39. def __init__(self, **kwargs):
  40. super(QubesDisposableVm, self).__init__(dir_path="/nonexistent", **kwargs)
  41. assert self.template is not None, "Missing template for DisposableVM!"
  42. # Use DispVM icon with the same color
  43. if self._label:
  44. self._label = QubesDispVmLabels[self._label.name]
  45. self.icon_path = self._label.icon_path
  46. @property
  47. def type(self):
  48. return "DisposableVM"
  49. def is_disposablevm(self):
  50. return True
  51. @property
  52. def ip(self):
  53. if self.netvm is not None:
  54. return self.netvm.get_ip_for_dispvm(self.dispid)
  55. else:
  56. return None
  57. def get_xml_attrs(self):
  58. # Minimal set - do not inherit rest of attributes
  59. attrs = {}
  60. attrs["qid"] = str(self.qid)
  61. attrs["name"] = self.name
  62. attrs["dispid"] = str(self.dispid)
  63. attrs["template_qid"] = str(self.template.qid)
  64. attrs["label"] = self.label.name
  65. attrs["firewall_conf"] = self.relative_path(self.firewall_conf)
  66. attrs["netvm_qid"] = str(self.netvm.qid) if self.netvm is not None else "none"
  67. return attrs
  68. def verify_files(self):
  69. return True
  70. # register classes
  71. register_qubes_vm_class(QubesDisposableVm)