X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=deploy%2Fenvironments%2Fexecution_environment.py;h=af0e130dd74219bc4bc574e50fdb3d71dbb053dd;hb=1e499d12e3ac1c76d04f02c57f9d578415117fcb;hp=c2e7a0b2341360e03678d78d139345b7eada5359;hpb=1ef2a5abcdacf3274e4ed17c612835ae10cb34d8;p=fuel.git diff --git a/deploy/environments/execution_environment.py b/deploy/environments/execution_environment.py index c2e7a0b23..af0e130dd 100644 --- a/deploy/environments/execution_environment.py +++ b/deploy/environments/execution_environment.py @@ -50,7 +50,32 @@ class ExecutionEnvironment(object): for file in disk_files: delete(file) - def define_vm(self, vm_name, temp_vm_file, disk_path, number_cpus): + def overwrite_xml(self, vm_xml, vm_definition_overwrite): + if not vm_definition_overwrite: + return + for key, value in vm_definition_overwrite.iteritems(): + if key == 'attribute_equlas': + continue + if key == 'value': + vm_xml.text = str(value) + return + if key == 'attribute': + for attr_key, attr_value in value.iteritems(): + vm_xml.set(attr_key, str(attr_value)) + return + + if isinstance(value, dict): + only_when_attribute = value.get('attribute_equlas') + for xml_element in vm_xml.xpath(key): + if only_when_attribute: + for attr_key, attr_value in \ + only_when_attribute.iteritems(): + if attr_value != xml_element.get(attr_key): + continue + self.overwrite_xml(xml_element, value) + + def define_vm(self, vm_name, temp_vm_file, disk_path, + vm_definition_overwrite): log('Creating VM %s with disks %s' % (vm_name, disk_path)) with open(temp_vm_file) as f: vm_xml = etree.parse(f) @@ -60,10 +85,8 @@ class ExecutionEnvironment(object): uuids = vm_xml.xpath('/domain/uuid') for uuid in uuids: uuid.getparent().remove(uuid) - if number_cpus: - vcpus = vm_xml.xpath('/domain/vcpu') - for vcpu in vcpus: - vcpu.text = str(number_cpus) + self.overwrite_xml(vm_xml.xpath('/domain')[0], + vm_definition_overwrite) disks = vm_xml.xpath('/domain/devices/disk') for disk in disks: if (disk.get('type') == 'file' and