dom0/core: check if object has attr before using it

This commit is contained in:
Marek Marczykowski 2012-02-24 04:22:14 +01:00
parent 8b3a895317
commit 85c5074dbe
2 changed files with 35 additions and 20 deletions

View File

@ -778,7 +778,8 @@ class QubesVm(object):
def get_config_params(self, source_template=None):
args = {}
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['pcidev'] = str(self.pcidevs).strip('[]')
args['mem'] = str(self.memory)
@ -794,11 +795,13 @@ class QubesVm(object):
args['rootdev'] = self.get_rootdev(source_template=source_template)
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)
modulesmode='r'
if self.is_updateable() and self.kernel is None:
modulesmode='w'
args['otherdevs'] = "'script:file:{dir}/modules.img,xvdd,{mode}',".format(dir=self.kernels_dir, mode=modulesmode)
args['kernelopts'] = self.kernelopts
if hasattr(self, 'kernel'):
modulesmode='r'
if self.is_updateable() and self.kernel is None:
modulesmode='w'
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

View File

@ -51,22 +51,29 @@ def do_list(vm):
print fmt.format ("root COW img", vm.rootcow_img)
if vm.template_vm is not None:
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 ("memory", vm.memory)
print fmt.format ("maxmem", vm.maxmem)
if vm.template_vm is not None:
print fmt.format ("kernel", "%s (from template)" % vm.kernel)
elif vm.uses_default_kernel:
print fmt.format ("kernel", "%s (default)" % vm.kernel)
else:
print fmt.format ("kernel", vm.kernel)
if vm.uses_default_kernelopts:
print fmt.format ("kernelopts", "%s (default)" % vm.kernelopts)
else:
print fmt.format ("kernelopts", vm.kernelopts)
if hasattr(vm, 'maxmem'):
print fmt.format ("maxmem", vm.maxmem)
if hasattr(vm, 'kernel'):
if vm.template_vm is not None:
print fmt.format ("kernel", "%s (from template)" % vm.kernel)
elif vm.uses_default_kernel:
print fmt.format ("kernel", "%s (default)" % vm.kernel)
else:
print fmt.format ("kernel", vm.kernel)
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):
@ -309,6 +316,10 @@ def do_set(vms, vm, property, args):
print >> sys.stderr, "ERROR: Wrong property name: '{0}'".format(property)
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)
@ -353,7 +364,8 @@ def main():
print >> sys.stderr, "You must specify the property you wish to set..."
print >> sys.stderr, "Available properties:"
for p in properties.keys():
print >> sys.stderr, "--> '{0}'".format(p)
if hasattr(vm, p):
print >> sys.stderr, "--> '{0}'".format(p)
exit (1)
property = args[1]