dom0/core: check if object has attr before using it
This commit is contained in:
parent
8b3a895317
commit
85c5074dbe
@ -778,7 +778,8 @@ class QubesVm(object):
|
|||||||
def get_config_params(self, source_template=None):
|
def get_config_params(self, source_template=None):
|
||||||
args = {}
|
args = {}
|
||||||
args['name'] = self.name
|
args['name'] = self.name
|
||||||
args['kerneldir'] = self.kernels_dir
|
if hasattr(self, 'kernels_dir'):
|
||||||
|
args['kerneldir'] = self.kernels_dir
|
||||||
args['vmdir'] = self.dir_path
|
args['vmdir'] = self.dir_path
|
||||||
args['pcidev'] = str(self.pcidevs).strip('[]')
|
args['pcidev'] = str(self.pcidevs).strip('[]')
|
||||||
args['mem'] = str(self.memory)
|
args['mem'] = str(self.memory)
|
||||||
@ -794,11 +795,13 @@ class QubesVm(object):
|
|||||||
args['rootdev'] = self.get_rootdev(source_template=source_template)
|
args['rootdev'] = self.get_rootdev(source_template=source_template)
|
||||||
args['privatedev'] = "'script:file:{dir}/private.img,xvdb,w',".format(dir=self.dir_path)
|
args['privatedev'] = "'script:file:{dir}/private.img,xvdb,w',".format(dir=self.dir_path)
|
||||||
args['volatiledev'] = "'script:file:{dir}/volatile.img,xvdc,w',".format(dir=self.dir_path)
|
args['volatiledev'] = "'script:file:{dir}/volatile.img,xvdc,w',".format(dir=self.dir_path)
|
||||||
modulesmode='r'
|
if hasattr(self, 'kernel'):
|
||||||
if self.is_updateable() and self.kernel is None:
|
modulesmode='r'
|
||||||
modulesmode='w'
|
if self.is_updateable() and self.kernel is None:
|
||||||
args['otherdevs'] = "'script:file:{dir}/modules.img,xvdd,{mode}',".format(dir=self.kernels_dir, mode=modulesmode)
|
modulesmode='w'
|
||||||
args['kernelopts'] = self.kernelopts
|
args['otherdevs'] = "'script:file:{dir}/modules.img,xvdd,{mode}',".format(dir=self.kernels_dir, mode=modulesmode)
|
||||||
|
if hasattr(self, 'kernelopts'):
|
||||||
|
args['kernelopts'] = self.kernelopts
|
||||||
|
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -51,22 +51,29 @@ def do_list(vm):
|
|||||||
print fmt.format ("root COW img", vm.rootcow_img)
|
print fmt.format ("root COW img", vm.rootcow_img)
|
||||||
if vm.template_vm is not None:
|
if vm.template_vm is not None:
|
||||||
print fmt.format ("root img", vm.template_vm.root_img)
|
print fmt.format ("root img", vm.template_vm.root_img)
|
||||||
print fmt.format ("root volatile img", vm.volatile_img)
|
if hasattr(vm, 'volatile_img'):
|
||||||
|
print fmt.format ("root volatile img", vm.volatile_img)
|
||||||
|
|
||||||
print fmt.format ("private img", vm.private_img)
|
if hasattr(vm, 'private_img'):
|
||||||
|
print fmt.format ("private img", vm.private_img)
|
||||||
print fmt.format ("vcpus", str(vm.vcpus))
|
print fmt.format ("vcpus", str(vm.vcpus))
|
||||||
print fmt.format ("memory", vm.memory)
|
print fmt.format ("memory", vm.memory)
|
||||||
print fmt.format ("maxmem", vm.maxmem)
|
if hasattr(vm, 'maxmem'):
|
||||||
if vm.template_vm is not None:
|
print fmt.format ("maxmem", vm.maxmem)
|
||||||
print fmt.format ("kernel", "%s (from template)" % vm.kernel)
|
|
||||||
elif vm.uses_default_kernel:
|
if hasattr(vm, 'kernel'):
|
||||||
print fmt.format ("kernel", "%s (default)" % vm.kernel)
|
if vm.template_vm is not None:
|
||||||
else:
|
print fmt.format ("kernel", "%s (from template)" % vm.kernel)
|
||||||
print fmt.format ("kernel", vm.kernel)
|
elif vm.uses_default_kernel:
|
||||||
if vm.uses_default_kernelopts:
|
print fmt.format ("kernel", "%s (default)" % vm.kernel)
|
||||||
print fmt.format ("kernelopts", "%s (default)" % vm.kernelopts)
|
else:
|
||||||
else:
|
print fmt.format ("kernel", vm.kernel)
|
||||||
print fmt.format ("kernelopts", vm.kernelopts)
|
|
||||||
|
if hasattr(vm, 'kernelopts'):
|
||||||
|
if vm.uses_default_kernelopts:
|
||||||
|
print fmt.format ("kernelopts", "%s (default)" % vm.kernelopts)
|
||||||
|
else:
|
||||||
|
print fmt.format ("kernelopts", vm.kernelopts)
|
||||||
|
|
||||||
|
|
||||||
def set_label(vms, vm, args):
|
def set_label(vms, vm, args):
|
||||||
@ -309,6 +316,10 @@ def do_set(vms, vm, property, args):
|
|||||||
print >> sys.stderr, "ERROR: Wrong property name: '{0}'".format(property)
|
print >> sys.stderr, "ERROR: Wrong property name: '{0}'".format(property)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not hasattr(vm, property):
|
||||||
|
print >> sys.stderr, "ERROR: Property '{0}' not available for this VM".format(property)
|
||||||
|
return False
|
||||||
|
|
||||||
return properties[property](vms, vm, args)
|
return properties[property](vms, vm, args)
|
||||||
|
|
||||||
|
|
||||||
@ -353,7 +364,8 @@ def main():
|
|||||||
print >> sys.stderr, "You must specify the property you wish to set..."
|
print >> sys.stderr, "You must specify the property you wish to set..."
|
||||||
print >> sys.stderr, "Available properties:"
|
print >> sys.stderr, "Available properties:"
|
||||||
for p in properties.keys():
|
for p in properties.keys():
|
||||||
print >> sys.stderr, "--> '{0}'".format(p)
|
if hasattr(vm, p):
|
||||||
|
print >> sys.stderr, "--> '{0}'".format(p)
|
||||||
exit (1)
|
exit (1)
|
||||||
|
|
||||||
property = args[1]
|
property = args[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user