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,6 +778,7 @@ 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
if hasattr(self, 'kernels_dir'):
args['kerneldir'] = 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('[]')
@ -794,10 +795,12 @@ 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)
if hasattr(self, 'kernel'):
modulesmode='r' modulesmode='r'
if self.is_updateable() and self.kernel is None: if self.is_updateable() and self.kernel is None:
modulesmode='w' modulesmode='w'
args['otherdevs'] = "'script:file:{dir}/modules.img,xvdd,{mode}',".format(dir=self.kernels_dir, mode=modulesmode) args['otherdevs'] = "'script:file:{dir}/modules.img,xvdd,{mode}',".format(dir=self.kernels_dir, mode=modulesmode)
if hasattr(self, 'kernelopts'):
args['kernelopts'] = self.kernelopts args['kernelopts'] = self.kernelopts
return args return args

View File

@ -51,18 +51,25 @@ 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)
if hasattr(vm, 'volatile_img'):
print fmt.format ("root volatile img", vm.volatile_img) print fmt.format ("root volatile img", vm.volatile_img)
if hasattr(vm, 'private_img'):
print fmt.format ("private img", 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)
if hasattr(vm, 'maxmem'):
print fmt.format ("maxmem", vm.maxmem) print fmt.format ("maxmem", vm.maxmem)
if hasattr(vm, 'kernel'):
if vm.template_vm is not None: if vm.template_vm is not None:
print fmt.format ("kernel", "%s (from template)" % vm.kernel) print fmt.format ("kernel", "%s (from template)" % vm.kernel)
elif vm.uses_default_kernel: elif vm.uses_default_kernel:
print fmt.format ("kernel", "%s (default)" % vm.kernel) print fmt.format ("kernel", "%s (default)" % vm.kernel)
else: else:
print fmt.format ("kernel", vm.kernel) print fmt.format ("kernel", vm.kernel)
if hasattr(vm, 'kernelopts'):
if vm.uses_default_kernelopts: if vm.uses_default_kernelopts:
print fmt.format ("kernelopts", "%s (default)" % vm.kernelopts) print fmt.format ("kernelopts", "%s (default)" % vm.kernelopts)
else: else:
@ -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,6 +364,7 @@ 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():
if hasattr(vm, p):
print >> sys.stderr, "--> '{0}'".format(p) print >> sys.stderr, "--> '{0}'".format(p)
exit (1) exit (1)