diff --git a/docs/xen_config.html b/docs/xen_config.html
index 81258c5189..00628c9bfe 100644
--- a/docs/xen_config.html
+++ b/docs/xen_config.html
@@ -61,6 +61,7 @@ The top-level element, a virtual machine configuration.
id: int, optional, default generated. Domain unique id.
memory: int, required. Domain memory in MB.
cpu: int, optional. Cpu to run on.
+ cpu_weight, float, optional, default 1. Cpu weight - controls share of CPU.
image: linux | netbsd | ..., required. Domain image (OS-specific element).
backend: any backend device type, optional, default none.
device: any device type, optional, repeats. Device.
diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py
index 8b47598c93..602575d0ba 100644
--- a/tools/python/xen/xend/XendDomainInfo.py
+++ b/tools/python/xen/xend/XendDomainInfo.py
@@ -369,6 +369,7 @@ class XendDomainInfo:
self.config = None
self.id = None
self.dom = None
+ self.cpu_weight = 1
self.start_time = None
self.name = None
self.memory = None
@@ -499,7 +500,10 @@ class XendDomainInfo:
try:
self.name = sxp.child_value(config, 'name')
self.check_name(self.name)
- self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+ try:
+ self.cpu_weight = float(sxp.child_value(config, 'cpu_weight', '1'))
+ except:
+ raise VmError('invalid cpu weight')
if self.restore and self.dom:
xc.domain_setname(self.dom, self.name)
self.memory = int(sxp.child_value(config, 'memory'))
diff --git a/tools/python/xen/xm/create.py b/tools/python/xen/xm/create.py
index 6d70bdcba6..1a05da4e14 100644
--- a/tools/python/xen/xm/create.py
+++ b/tools/python/xen/xm/create.py
@@ -101,9 +101,10 @@ gopts.var('memory', val='MEMORY',
fn=set_value, default=128,
use="Domain memory in MB.")
-gopts.var('cpu_weight', val='CPU_WEIGHT',
- fn=set_value, default=1,
- use="CPU weight.")
+gopts.var('cpu_weight', val='WEIGHT',
+ fn=set_float, default=1,
+ use="""Set the new domain's cpu weight. WEIGHT is a float that controls the
+domain's share of the cpu.""")
gopts.var('console', val='PORT',
fn=set_int, default=None,
diff --git a/tools/python/xen/xm/opts.py b/tools/python/xen/xm/opts.py
index 9f34b6773c..a46ab3c1f0 100644
--- a/tools/python/xen/xm/opts.py
+++ b/tools/python/xen/xm/opts.py
@@ -409,7 +409,7 @@ def set_bool(opt, k, v):
def set_value(opt, k, v):
- """Set an option to a valoue."""
+ """Set an option to a value."""
opt.set(v)
def set_int(opt, k, v):
@@ -420,6 +420,14 @@ def set_int(opt, k, v):
opt.opts.err('Invalid value: ' + str(v))
opt.set(v)
+def set_float(opt, k, v):
+ """Set an option to a float value."""
+ try:
+ v = float(v)
+ except:
+ opt.opts.err('Invalid value: ' + str(v))
+ opt.set(v)
+
def append_value(opt, k, v):
"""Append a value to a list option."""
opt.append(v)