+ will default to a product of the topology values (see
cpu_info).
* memory *(optional)*: The amount of memory assigned to the VM.
Default is 1024M.
* cdrom *(optional)*: A volume name or URI to an ISO image.
@@ -201,6 +203,15 @@ Represents a snapshot of the Virtual Machine's
primary monitor.
Independent Computing Environments
* null: Graphics is disabled or type not supported
* listen: The network which the vnc/spice server listens on.
+ * cpu_info *(optional)*: CPU-specific information.
+ * topology: Specify sockets, threads, and cores to run the
virtual CPU
+ threads on.
+ All three are required in order to specify cpu topology.
+ * sockets - The number of sockets to use.
+ * cores - The number of cores per socket.
+ * threads - The number of threads per core.
+ If specifying both cpus and CPU topology, make sure cpus is
+ equal to the product of sockets, cores, and threads.
### Sub-Collection: Virtual Machine Network Interfaces
diff --git a/po/en_US.po b/po/en_US.po
index eb571ca..a88675c 100644
--- a/po/en_US.po
+++ b/po/en_US.po
@@ -371,6 +371,9 @@ msgstr ""
msgid "Cannot identify base image %(path)s format"
msgstr ""
+msgid "When specifying CPU topology, VCPUs must be a product of
sockets, cores, and threads."
+msgstr ""
+
#, python-format
msgid "Storage pool %(name)s already exists"
msgstr ""
diff --git a/po/pt_BR.po b/po/pt_BR.po
index f2fba64..1bebe30 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -424,6 +424,9 @@ msgstr "Imagem base do modelo deve ser um arquivo
de imagem local válido"
msgid "Cannot identify base image %(path)s format"
msgstr "Não foi possível identificar o formato da imagem base %(path)s"
+msgid "When specifying CPU topology, VCPUs must be a product of
sockets, cores, and threads."
+msgstr ""
+
#, python-format
msgid "Storage pool %(name)s already exists"
msgstr "Storage pool %(name)s já existe"
diff --git a/po/zh_CN.po b/po/zh_CN.po
index f77e405..f944b8d 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -392,6 +392,9 @@ msgstr "模板基础镜像必须为一个有效的本地镜像文件"
msgid "Cannot identify base image %(path)s format"
msgstr "未能识别基础镜像%(path)s格式"
+msgid "When specifying CPU topology, VCPUs must be a product of
sockets, cores, and threads."
+msgstr ""
+
#, python-format
msgid "Storage pool %(name)s already exists"
msgstr "存储池%(name)s已经存在"
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index 5b752dc..fe3df72 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -26,6 +26,33 @@
]
}
}
+ },
+ "cpu_info": {
+ "description": "Configure CPU specifics for a VM.",
+ "type": "object",
+ "properties": {
+ "topology": {
+ "description": "Configure the guest CPU topology.",
+ "type": "object",
+ "properties": {
+ "sockets": {
+ "type": "integer",
+ "required": true,
+ "minimum": 1
+ },
+ "cores": {
+ "type": "integer",
+ "required": true,
+ "minimum": 1
+ },
+ "threads": {
+ "type": "integer",
+ "required": true,
+ "minimum": 1
+ }
+ }
+ }
+ }
}
},
"properties": {
@@ -448,7 +475,8 @@
"type": "array",
"items": { "type": "string" }
},
- "graphics": { "$ref": "#/kimchitype/graphics" }
+ "graphics": { "$ref": "#/kimchitype/graphics" },
+ "cpu_info": { "$ref": "#/kimchitype/cpu_info" }
},
"additionalProperties": false,
"error": "KCHAPI0001E"
@@ -612,7 +640,8 @@
"type": "array",
"items": { "type": "string" }
},
- "graphics": { "$ref": "#/kimchitype/graphics" }
+ "graphics": { "$ref": "#/kimchitype/graphics" },
+ "cpu_info": { "$ref": "#/kimchitype/cpu_info" }
},
"additionalProperties": false,
"error": "KCHAPI0001E"
diff --git a/src/kimchi/control/templates.py
b/src/kimchi/control/templates.py
index e17fa54..54caa92 100644
--- a/src/kimchi/control/templates.py
+++ b/src/kimchi/control/templates.py
@@ -38,13 +38,14 @@ def __init__(self, model, ident):
self.update_params = ["name", "folder", "icon", "os_distro",
"storagepool", "os_version", "cpus",
"memory", "cdrom", "disks", "networks",
- "graphics"]
+ "graphics", "cpu_info"]
self.uri_fmt = "/templates/%s"
self.clone = self.generate_action_handler('clone')
@property
def data(self):
- return {'name': self.ident,
+ return_data = {
+ 'name': self.ident,
'icon': self.info['icon'],
'invalid': self.info['invalid'],
'os_distro': self.info['os_distro'],
@@ -56,4 +57,10 @@ def data(self):
'storagepool': self.info['storagepool'],
'networks': self.info['networks'],
'folder': self.info.get('folder', []),
- 'graphics': self.info['graphics']}
+ 'graphics': self.info['graphics']
+ }
+ if (self.info.get('cpu_info')):
+ return_data['cpu_info'] = self.info['cpu_info']
+ else:
+ return_data['cpu_info'] = ''
+ return return_data
diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 1b543ce..9ce8e86 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -131,6 +131,7 @@
"KCHTMPL0022E": _("Disk size must be an integer greater than
1GB."),
"KCHTMPL0023E": _("Template base image must be a valid local
image file"),
"KCHTMPL0024E": _("Cannot identify base image %(path)s format"),
+ "KCHTMPL0025E": _("When specifying CPU topology, VCPUs must be a
product of sockets, cores, and threads."),
"KCHPOOL0001E": _("Storage pool %(name)s already exists"),
"KCHPOOL0002E": _("Storage pool %(name)s does not exist"),
diff --git a/src/kimchi/model/templates.py
b/src/kimchi/model/templates.py
index 9278cdc..04d2af9 100644
--- a/src/kimchi/model/templates.py
+++ b/src/kimchi/model/templates.py
@@ -48,6 +48,22 @@ def create(self, params):
{'filename': iso, 'user': user,
'err': excp})
+ cpu_info = params.get('cpu_info')
+ if cpu_info:
+ cpu_info = dict(params['cpu_info'])
+ topology = cpu_info.get('topology')
+ # Check, even though currently only topology
+ # is supported.
+ if topology:
+ sockets = topology['sockets']
+ cores = topology['cores']
+ threads = topology['threads']
+ vcpus = params.get('cpus')
+ if vcpus is None:
+ params['cpus'] = sockets * cores * threads
+ elif sockets * cores * threads != vcpus:
+ raise InvalidParameter("KCHTMPL0025E")
+
conn = self.conn.get()
pool_uri = params.get(u'storagepool', '')
if pool_uri:
@@ -154,6 +170,9 @@ def delete(self, name):
def update(self, name, params):
old_t = self.lookup(name)
+ if not self._verify_updated_cpu_params(params, old_t):
+ raise InvalidParameter('KCHTMPL0025E')
+
new_t = copy.copy(old_t)
new_t.update(params)
ident = name
@@ -187,6 +206,39 @@ def update(self, name, params):
raise
return ident
+ def _verify_updated_cpu_params(self, params, old_t):
+ # Note: cpu_info is the parent of topology. cpus is vcpus
+ # Keep two check_ variables for what we'll verify at the end to
+ # keep from duplicating code.
+ check_cpu = None
+ check_topology = None
+ # First see what parameters were passed in.
+ new_vcpus = params.get('cpus')
+ new_cpu_info = params.get('cpu_info')
+ new_topology = ''
+ if new_cpu_info:
+ new_topology = new_cpu_info.get('topology')
+ # Now figure out what needs to be verified.
+ if new_vcpus and new_topology:
+ check_cpu = new_vcpus
+ check_topology = new_topology
+ elif new_vcpus:
+ old_cpu_info = old_t.get('cpu_info')
+ if old_cpu_info:
+ old_topology = old_cpu_info.get('topology')
+ if old_topology:
+ check_cpu = new_vcpus
+ check_topology = old_topology
+ elif new_topology:
+ check_cpu = old_t.get('cpus')
+ check_topology = new_topology
+ # Now verify the cpu and topoloy parameters
+ if check_cpu and (check_cpu != check_topology['sockets'] * \
+ check_topology['cores'] * check_topology['threads']):
+ return False
+
+ return True
+
class LibvirtVMTemplate(VMTemplate):
def __init__(self, args, scan=False, conn=None):
diff --git a/src/kimchi/osinfo.py b/src/kimchi/osinfo.py
index 6ee5e48..10d0ab0 100644
--- a/src/kimchi/osinfo.py
+++ b/src/kimchi/osinfo.py
@@ -32,7 +32,7 @@
'power': ('ppc', 'ppc64')}
-common_spec = {'cpus': 1, 'cpu_cores': 1, 'cpu_threads': 1,
'memory': 1024,
+common_spec = {'cpus': 1, 'cpu_sockets': '1', 'cpu_cores': 1,
'cpu_threads': 1, 'memory': 1024,