guest: Move cpuset static functions to DomainNumatune
This commit is contained in:
parent
d36f953142
commit
3e158b80bf
|
@ -861,7 +861,7 @@ class TestXMLConfig(unittest.TestCase):
|
|||
g = utils.get_basic_fullyvirt_guest()
|
||||
|
||||
# Cpuset
|
||||
cpustr = g.generate_cpuset(g.conn, g.memory)
|
||||
cpustr = virtinst.DomainNumatune.generate_cpuset(g.conn, g.memory)
|
||||
g.cpuset = cpustr
|
||||
g.vcpus = 7
|
||||
|
||||
|
@ -1002,15 +1002,16 @@ class TestXMLConfig(unittest.TestCase):
|
|||
expect = base[:]
|
||||
expect[1] = expect[2] = expect[3] = True
|
||||
self.assertEquals(tuple(expect),
|
||||
virtinst.Guest.cpuset_str_to_tuple(conn, "1-3"))
|
||||
virtinst.DomainNumatune.cpuset_str_to_tuple(conn, "1-3"))
|
||||
|
||||
expect = base[:]
|
||||
expect[1] = expect[3] = expect[5] = expect[10] = expect[11] = True
|
||||
self.assertEquals(tuple(expect),
|
||||
virtinst.Guest.cpuset_str_to_tuple(conn, "1,3,5,10-11"))
|
||||
virtinst.DomainNumatune.cpuset_str_to_tuple(conn,
|
||||
"1,3,5,10-11"))
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
virtinst.Guest.cpuset_str_to_tuple,
|
||||
virtinst.DomainNumatune.cpuset_str_to_tuple,
|
||||
conn, "16")
|
||||
|
||||
def testManyVirtio(self):
|
||||
|
|
|
@ -1832,7 +1832,8 @@ class vmmDetails(vmmGObjectUI):
|
|||
|
||||
def generate_cpuset(self):
|
||||
mem = int(self.vm.get_memory()) / 1024
|
||||
return virtinst.Guest.generate_cpuset(self.conn.get_backend(), mem)
|
||||
return virtinst.DomainNumatune.generate_cpuset(self.conn.get_backend(),
|
||||
mem)
|
||||
|
||||
# VCPUS
|
||||
def config_get_vcpus(self):
|
||||
|
@ -2207,7 +2208,7 @@ class vmmDetails(vmmGObjectUI):
|
|||
try:
|
||||
new_text = new_text.strip()
|
||||
vcpu_num = int(row[0])
|
||||
pinlist = virtinst.Guest.cpuset_str_to_tuple(
|
||||
pinlist = virtinst.DomainNumatune.cpuset_str_to_tuple(
|
||||
conn.get_backend(), new_text)
|
||||
except Exception, e:
|
||||
self.err.val_err(_("Error building pin list"), e)
|
||||
|
@ -2229,7 +2230,7 @@ class vmmDetails(vmmGObjectUI):
|
|||
if self.vm.vcpu_pinning() == cpuset:
|
||||
return
|
||||
|
||||
pinlist = virtinst.Guest.cpuset_str_to_tuple(
|
||||
pinlist = virtinst.DomainNumatune.cpuset_str_to_tuple(
|
||||
conn.get_backend(), cpuset)
|
||||
for row in vcpu_model:
|
||||
vcpu_num = row[0]
|
||||
|
|
|
@ -37,7 +37,6 @@ import virtinst
|
|||
from virtinst import util
|
||||
from virtinst.util import listify
|
||||
|
||||
from virtinst import Guest
|
||||
from virtinst import VirtualNetworkInterface
|
||||
from virtinst import VirtualGraphics
|
||||
from virtinst import VirtualAudio
|
||||
|
@ -690,7 +689,7 @@ def get_cpuset(guest, cpuset, memory):
|
|||
elif cpuset == "auto":
|
||||
tmpset = None
|
||||
try:
|
||||
tmpset = Guest.generate_cpuset(conn, memory)
|
||||
tmpset = virtinst.DomainNumatune.generate_cpuset(conn, memory)
|
||||
except Exception, e:
|
||||
logging.debug("Not setting cpuset: %s", str(e))
|
||||
|
||||
|
|
|
@ -92,6 +92,57 @@ class DomainNumatune(XMLBuilder):
|
|||
|
||||
return tuple(pinlist)
|
||||
|
||||
@staticmethod
|
||||
def generate_cpuset(conn, mem):
|
||||
"""
|
||||
Generates a cpu pinning string based on host NUMA configuration.
|
||||
|
||||
If host doesn't have a suitable NUMA configuration, a RuntimeError
|
||||
is thrown.
|
||||
"""
|
||||
if conn.caps.host.topology is None:
|
||||
raise RuntimeError(_("No topology section in capabilities xml."))
|
||||
|
||||
cells = conn.caps.host.topology.cells
|
||||
if len(cells) <= 1:
|
||||
raise RuntimeError(_("Capabilities only show <= 1 cell. "
|
||||
"Not NUMA capable"))
|
||||
|
||||
# Capabilities tells us about the available memory 'cells' on the
|
||||
# system. Each 'cell' has associated 'cpu's.
|
||||
#
|
||||
# Use getCellsFreeMemory to determine which 'cell' has the smallest
|
||||
# amount of memory which fits the requested VM memory amount, then
|
||||
# pin the VM to that 'cell's associated 'cpu's
|
||||
|
||||
cell_mem = conn.getCellsFreeMemory(0, len(cells))
|
||||
cell_id = -1
|
||||
for i in range(len(cells)):
|
||||
if cell_mem[i] < mem:
|
||||
# Cell doesn't have enough mem to fit, skip it
|
||||
continue
|
||||
|
||||
if len(cells[i].cpus) == 0:
|
||||
# No cpus to use for the cell
|
||||
continue
|
||||
|
||||
# Find smallest cell that fits
|
||||
if cell_id < 0 or cell_mem[i] < cell_mem[cell_id]:
|
||||
cell_id = i
|
||||
|
||||
if cell_id < 0:
|
||||
raise RuntimeError(_("Could not find any usable NUMA "
|
||||
"cell/cpu combinations."))
|
||||
|
||||
# Build cpuset string
|
||||
cpustr = ""
|
||||
for cpu in cells[cell_id].cpus:
|
||||
if cpustr != "":
|
||||
cpustr += ","
|
||||
cpustr += str(cpu.id)
|
||||
|
||||
return cpustr
|
||||
|
||||
|
||||
MEMORY_MODES = ["interleave", "strict", "preferred"]
|
||||
|
||||
|
|
|
@ -102,61 +102,6 @@ class Guest(XMLBuilder):
|
|||
def get_os_variant_label(typ, variant):
|
||||
return Guest._OS_TYPES[typ]["variants"][variant]["label"]
|
||||
|
||||
@staticmethod
|
||||
def cpuset_str_to_tuple(conn, cpuset):
|
||||
return DomainNumatune.cpuset_str_to_tuple(conn, cpuset)
|
||||
|
||||
@staticmethod
|
||||
def generate_cpuset(conn, mem):
|
||||
"""
|
||||
Generates a cpu pinning string based on host NUMA configuration.
|
||||
|
||||
If host doesn't have a suitable NUMA configuration, a RuntimeError
|
||||
is thrown.
|
||||
"""
|
||||
if conn.caps.host.topology is None:
|
||||
raise RuntimeError(_("No topology section in capabilities xml."))
|
||||
|
||||
cells = conn.caps.host.topology.cells
|
||||
if len(cells) <= 1:
|
||||
raise RuntimeError(_("Capabilities only show <= 1 cell. "
|
||||
"Not NUMA capable"))
|
||||
|
||||
# Capabilities tells us about the available memory 'cells' on the
|
||||
# system. Each 'cell' has associated 'cpu's.
|
||||
#
|
||||
# Use getCellsFreeMemory to determine which 'cell' has the smallest
|
||||
# amount of memory which fits the requested VM memory amount, then
|
||||
# pin the VM to that 'cell's associated 'cpu's
|
||||
|
||||
cell_mem = conn.getCellsFreeMemory(0, len(cells))
|
||||
cell_id = -1
|
||||
for i in range(len(cells)):
|
||||
if cell_mem[i] < mem:
|
||||
# Cell doesn't have enough mem to fit, skip it
|
||||
continue
|
||||
|
||||
if len(cells[i].cpus) == 0:
|
||||
# No cpus to use for the cell
|
||||
continue
|
||||
|
||||
# Find smallest cell that fits
|
||||
if cell_id < 0 or cell_mem[i] < cell_mem[cell_id]:
|
||||
cell_id = i
|
||||
|
||||
if cell_id < 0:
|
||||
raise RuntimeError(_("Could not find any usable NUMA "
|
||||
"cell/cpu combinations."))
|
||||
|
||||
# Build cpuset string
|
||||
cpustr = ""
|
||||
for cpu in cells[cell_id].cpus:
|
||||
if cpustr != "":
|
||||
cpustr += ","
|
||||
cpustr += str(cpu.id)
|
||||
|
||||
return cpustr
|
||||
|
||||
@staticmethod
|
||||
def check_vm_collision(conn, name, do_remove):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue