01QubesDisposableVm.py 3.2 KB

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