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 0633e35fa6
commit 28666c47f5
2 changed files with 31 additions and 18 deletions

View File

@ -856,7 +856,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)
@ -883,11 +884,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.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.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

@ -53,21 +53,26 @@ def do_list(vm):
print fmt.format ("root COW img", vm.rootcow_img)
if vm.template is not None:
print fmt.format ("root img", vm.template.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 hasattr(vm, 'maxmem'):
print fmt.format ("maxmem", vm.maxmem)
print fmt.format ("MAC", "%s%s" % (vm.mac, " (auto)" if vm._mac is None else ""))
if 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, 'kernel'):
if 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):
if len (args) != 1:
@ -293,6 +298,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)
@ -337,7 +346,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]