def test_config_simple(self): obj = config.LibvirtConfigCPUFeature("mtrr") xml = obj.to_xml() self.assertXmlEqual(xml, """ <feature name="mtrr"/> """)
def test_config_complex(self): obj = config.LibvirtConfigCPU() obj.model = "Penryn" obj.vendor = "Intel" obj.arch = "x86_64" obj.add_feature(config.LibvirtConfigCPUFeature("mtrr")) obj.add_feature(config.LibvirtConfigCPUFeature("apic")) xml = obj.to_xml() self.assertXmlEqual(xml, """ <cpu> <arch>x86_64</arch> <model>Penryn</model> <vendor>Intel</vendor> <feature name="mtrr"/> <feature name="apic"/> </cpu> """)
def detail(self, req): context = req.environ['nova.context'] authorize(context) compute_nodes = self.host_api.compute_node_get_all(context) # begin:<wangzh21>:<Bugzilla - bug 75256>:<a>:<2016-11-17> server_id = req.GET.get('server_id', None) if server_id: compute_nodes_after_filter = [] instance = common.get_instance(self.compute_api, context, server_id) src_compute_info = objects.ComputeNode. \ get_first_node_by_host_for_old_compat(context, instance.host) if not instance.vcpu_model or not instance.vcpu_model.model: source_cpu_info = src_compute_info['cpu_info'] info = jsonutils.loads(source_cpu_info) LOG.info(_LI('Instance launched has CPU info: %s'), source_cpu_info) cpu = vconfig.LibvirtConfigCPU() cpu.arch = info['arch'] cpu.model = info['model'] cpu.vendor = info['vendor'] cpu.sockets = info['topology']['sockets'] cpu.cores = info['topology']['cores'] cpu.threads = info['topology']['threads'] for f in info['features']: cpu.add_feature(vconfig.LibvirtConfigCPUFeature(f)) else: cpu = self._vcpu_model_to_cpu_config(instance.vcpu_model) cpu_xml = cpu.to_xml() for compute_node in compute_nodes: dst_cpu_info = jsonutils.loads(compute_node['cpu_info']) ret = self._compareCPU(cpu_xml, dst_cpu_info) service = self.host_api.service_get_by_compute_host( context, compute_node.host) state_is_up = self.servicegroup_api.service_is_up(service) status_is_disabled = service.disabled if compute_node['host'] == instance.host or not state_is_up or \ status_is_disabled: continue if ret > 0 and src_compute_info['hypervisor_type'] == \ compute_node['hypervisor_type'] and \ src_compute_info['hypervisor_version'] <= \ compute_node['hypervisor_version']: compute_nodes_after_filter.append(compute_node) compute_nodes = compute_nodes_after_filter # end:<wangzh21>:<Bugzilla - bug 75256>:<a>:<2016-11-17> req.cache_db_compute_nodes(compute_nodes) return dict(hypervisors=[ self._view_hypervisor( hyp, self.host_api.service_get_by_compute_host(context, hyp.host), True) for hyp in compute_nodes ])
def parse_dom(self, xmldoc): super(LibvirtConfigGuestCPU, self).parse_dom(xmldoc) for c in xmldoc.getchildren(): if c.tag == "arch": self.arch = c.text elif c.tag == "model": self.model = c.text elif c.tag == "vendor": self.vendor = c.text elif c.tag == "topology": self.sockets = int(c.get("sockets")) self.cores = int(c.get("cores")) self.threads = int(c.get("threads")) elif c.tag == "feature": f = config_original.LibvirtConfigCPUFeature() f.parse_dom(c) self.add_feature(f)