blob: 92b7b8f9a30771613caa82696451a87dd6e5fdda [file] [log] [blame]
Clark Boylanedd60482015-03-27 09:19:57 -07001#!/usr/bin/env python
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15# This small script updates the libvirt CPU map to add a gate64 cpu model
16# that can be used to enable a common 64bit capable feature set across
17# devstack nodes so that features like nova live migration work.
18
19import sys
20import xml.etree.ElementTree as ET
21from xml.dom import minidom
22
23
24def update_cpu_map(tree):
25 root = tree.getroot()
26 cpus = root#.find("cpus")
27 x86 = None
28 for arch in cpus.findall("arch"):
29 if arch.get("name") == "x86":
30 x86 = arch
31 break
32 if x86 is not None:
Clark Boylanba6fb272016-01-19 08:15:36 -080033 # Create a gate64 cpu model that is core2duo less monitor, pse36,
34 # vme, and ssse3.
Clark Boylanedd60482015-03-27 09:19:57 -070035 gate64 = ET.SubElement(x86, "model")
36 gate64.set("name", "gate64")
37 ET.SubElement(gate64, "vendor").set("name", "Intel")
38 ET.SubElement(gate64, "feature").set("name", "fpu")
39 ET.SubElement(gate64, "feature").set("name", "de")
40 ET.SubElement(gate64, "feature").set("name", "pse")
41 ET.SubElement(gate64, "feature").set("name", "tsc")
42 ET.SubElement(gate64, "feature").set("name", "msr")
43 ET.SubElement(gate64, "feature").set("name", "pae")
44 ET.SubElement(gate64, "feature").set("name", "mce")
45 ET.SubElement(gate64, "feature").set("name", "cx8")
46 ET.SubElement(gate64, "feature").set("name", "apic")
47 ET.SubElement(gate64, "feature").set("name", "sep")
48 ET.SubElement(gate64, "feature").set("name", "pge")
49 ET.SubElement(gate64, "feature").set("name", "cmov")
50 ET.SubElement(gate64, "feature").set("name", "pat")
51 ET.SubElement(gate64, "feature").set("name", "mmx")
52 ET.SubElement(gate64, "feature").set("name", "fxsr")
53 ET.SubElement(gate64, "feature").set("name", "sse")
54 ET.SubElement(gate64, "feature").set("name", "sse2")
Clark Boylanedd60482015-03-27 09:19:57 -070055 ET.SubElement(gate64, "feature").set("name", "mtrr")
56 ET.SubElement(gate64, "feature").set("name", "mca")
57 ET.SubElement(gate64, "feature").set("name", "clflush")
58 ET.SubElement(gate64, "feature").set("name", "pni")
59 ET.SubElement(gate64, "feature").set("name", "nx")
Clark Boylanedd60482015-03-27 09:19:57 -070060 ET.SubElement(gate64, "feature").set("name", "syscall")
61 ET.SubElement(gate64, "feature").set("name", "lm")
62
63
64def format_xml(root):
65 # Adapted from http://pymotw.com/2/xml/etree/ElementTree/create.html
66 # thank you dhellmann
67 rough_string = ET.tostring(root, encoding="UTF-8")
68 dom_parsed = minidom.parseString(rough_string)
69 return dom_parsed.toprettyxml(" ", encoding="UTF-8")
70
71
72def main():
73 if len(sys.argv) != 2:
74 raise Exception("Must pass path to cpu_map.xml to update")
75 cpu_map = sys.argv[1]
76 tree = ET.parse(cpu_map)
77 for model in tree.getroot().iter("model"):
78 if model.get("name") == "gate64":
79 # gate64 model is already present
80 return
81 update_cpu_map(tree)
82 pretty_xml = format_xml(tree.getroot())
83 with open(cpu_map, 'w') as f:
84 f.write(pretty_xml)
85
86
87if __name__ == "__main__":
88 main()