01QubesDisposableVm.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. from qubes.qubes import QubesDispVmLabels
  26. class QubesDisposableVm(QubesVm):
  27. """
  28. A class that represents an DisposableVM. A child of QubesVm.
  29. """
  30. # In which order load this VM type from qubes.xml
  31. load_order = 120
  32. def get_attrs_config(self):
  33. attrs_config = super(QubesDisposableVm, self).get_attrs_config()
  34. # New attributes
  35. attrs_config['dispid'] = { 'save': lambda: str(self.dispid) }
  36. attrs_config['include_in_backups']['func'] = lambda x: False
  37. return attrs_config
  38. def __init__(self, **kwargs):
  39. super(QubesDisposableVm, self).__init__(dir_path="/nonexistent", **kwargs)
  40. assert self.template is not None, "Missing template for DisposableVM!"
  41. # Use DispVM icon with the same color
  42. if self._label:
  43. self._label = QubesDispVmLabels[self._label.name]
  44. self.icon_path = self._label.icon_path
  45. @property
  46. def type(self):
  47. return "DisposableVM"
  48. def is_disposablevm(self):
  49. return True
  50. @property
  51. def ip(self):
  52. if self.netvm is not None:
  53. return self.netvm.get_ip_for_dispvm(self.dispid)
  54. else:
  55. return None
  56. def get_xml_attrs(self):
  57. # Minimal set - do not inherit rest of attributes
  58. attrs = {}
  59. attrs["qid"] = str(self.qid)
  60. attrs["name"] = self.name
  61. attrs["dispid"] = str(self.dispid)
  62. attrs["template_qid"] = str(self.template.qid)
  63. attrs["label"] = self.label.name
  64. attrs["firewall_conf"] = self.relative_path(self.firewall_conf)
  65. attrs["netvm_qid"] = str(self.netvm.qid) if self.netvm is not None else "none"
  66. return attrs
  67. def verify_files(self):
  68. return True
  69. # register classes
  70. register_qubes_vm_class(QubesDisposableVm)