Commit 9b3849c1 by Dudás Ádám

vm: simplify method

parent 6456ad7f
...@@ -382,19 +382,20 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel): ...@@ -382,19 +382,20 @@ class Instance(AclBase, VirtualMachineDescModel, TimeStampedModel):
tags = template.tags.all() if tags is None else tags tags = template.tags.all() if tags is None else tags
# prepare parameters # prepare parameters
kwargs['template'] = template common_fields = ['name', 'description', 'num_cores', 'ram_size',
kwargs['owner'] = owner 'max_ram_size', 'arch', 'priority', 'boot_menu',
kwargs.setdefault('pw', pwgen()) 'raw_data', 'lease', 'access_method']
ca = ['name', 'description', 'num_cores', 'ram_size', 'max_ram_size', params = dict(template=template, owner=owner, pw=pwgen())
'arch', 'priority', 'boot_menu', 'raw_data', 'lease', params.update([(f, getattr(template, f)) for f in common_fields])
'access_method'] params.update(kwargs) # override defaults w/ user supplied values
for attr in ca:
kwargs.setdefault(attr, getattr(template, attr))
# create instance and do additional setup # create instance and do additional setup
inst = cls(**kwargs) inst = cls(**params)
# save instance # save instance
inst.clean() inst.clean()
inst.save() inst.save()
# create related entities # create related entities
inst.disks.add(*[disk.get_exclusive() for disk in disks]) inst.disks.add(*[disk.get_exclusive() for disk in disks])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment