core: more flexible mechanism for template compatibility check
Using class method allow the users (Qubes Manager at least) to check for compatibility without having any particular VM instance - useful while creating the VM.
This commit is contained in:
parent
efeb284ab1
commit
a457b62728
@ -459,17 +459,24 @@ class QubesVm(object):
|
|||||||
raise QubesException("Failed to set autostart for VM via systemctl")
|
raise QubesException("Failed to set autostart for VM via systemctl")
|
||||||
self._autostart = bool(value)
|
self._autostart = bool(value)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def is_template_compatible(cls, template):
|
||||||
|
"""Check if given VM can be a template for this VM"""
|
||||||
|
# FIXME: check if the value is instance of QubesTemplateVM, not the VM
|
||||||
|
# type. The problem is while this file is loaded, QubesTemplateVM is
|
||||||
|
# not defined yet.
|
||||||
|
if template and (not template.is_template() or template.type != "TemplateVM"):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def template(self):
|
def template(self):
|
||||||
return self._template
|
return self._template
|
||||||
|
|
||||||
@template.setter
|
@template.setter
|
||||||
def template(self, value):
|
def template(self, value):
|
||||||
# FIXME: check if the value is instance of QubesTemplateVM, not the VM
|
if value and not self.is_template_compatible(value):
|
||||||
# type. The problem is while this file is loaded, QubesTemplateVM is
|
raise QubesException("Incompatible template type %s with VM of type %s" % (value.type, self.type))
|
||||||
# not defined yet.
|
|
||||||
if value and (not value.is_template() or value.type != "TemplateVM"):
|
|
||||||
raise QubesException("Only PV template can be a template for the PV VM")
|
|
||||||
self._template = value
|
self._template = value
|
||||||
|
|
||||||
def is_template(self):
|
def is_template(self):
|
||||||
|
@ -101,15 +101,11 @@ class QubesHVm(QubesVm):
|
|||||||
# Any non-template based HVM can be a template itself
|
# Any non-template based HVM can be a template itself
|
||||||
return self.template is None
|
return self.template is None
|
||||||
|
|
||||||
@property
|
@classmethod
|
||||||
def template(self):
|
def is_template_compatible(cls, template):
|
||||||
return self._template
|
if template and (not template.is_template() or template.type != "HVM"):
|
||||||
|
return False
|
||||||
@template.setter
|
return True
|
||||||
def template(self, value):
|
|
||||||
if value and (not value.is_template() or value.type != "HVM"):
|
|
||||||
raise QubesException("Only HVM can be a template for the HVM")
|
|
||||||
self._template = value
|
|
||||||
|
|
||||||
def get_clone_attrs(self):
|
def get_clone_attrs(self):
|
||||||
attrs = super(QubesHVm, self).get_clone_attrs()
|
attrs = super(QubesHVm, self).get_clone_attrs()
|
||||||
|
Loading…
Reference in New Issue
Block a user