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")
|
||||
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
|
||||
def template(self):
|
||||
return self._template
|
||||
|
||||
@template.setter
|
||||
def template(self, value):
|
||||
# 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 value and (not value.is_template() or value.type != "TemplateVM"):
|
||||
raise QubesException("Only PV template can be a template for the PV VM")
|
||||
if value and not self.is_template_compatible(value):
|
||||
raise QubesException("Incompatible template type %s with VM of type %s" % (value.type, self.type))
|
||||
self._template = value
|
||||
|
||||
def is_template(self):
|
||||
|
@ -101,15 +101,11 @@ class QubesHVm(QubesVm):
|
||||
# Any non-template based HVM can be a template itself
|
||||
return self.template is None
|
||||
|
||||
@property
|
||||
def template(self):
|
||||
return self._template
|
||||
|
||||
@template.setter
|
||||
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
|
||||
@classmethod
|
||||
def is_template_compatible(cls, template):
|
||||
if template and (not template.is_template() or template.type != "HVM"):
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_clone_attrs(self):
|
||||
attrs = super(QubesHVm, self).get_clone_attrs()
|
||||
|
Loading…
Reference in New Issue
Block a user