mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
Guest: Switch memory units to KB to match default XML
This commit is contained in:
parent
69e1d66b53
commit
c12327cbd1
@ -170,8 +170,8 @@ def diff_compare(actual_out, filename=None, expect_out=None):
|
||||
def get_basic_paravirt_guest(installer=None):
|
||||
g = virtinst.Guest(_conn, type="xen")
|
||||
g.name = "TestGuest"
|
||||
g.memory = int(200)
|
||||
g.maxmemory = int(400)
|
||||
g.memory = int(200 * 1024)
|
||||
g.maxmemory = int(400 * 1024)
|
||||
g.uuid = "12345678-1234-1234-1234-123456789012"
|
||||
g.add_device(VirtualGraphics(_conn, "vnc", keymap="ja"))
|
||||
g.vcpus = 5
|
||||
@ -190,8 +190,8 @@ def get_basic_paravirt_guest(installer=None):
|
||||
def get_basic_fullyvirt_guest(typ="xen", installer=None):
|
||||
g = virtinst.Guest(_conn, type=typ)
|
||||
g.name = "TestGuest"
|
||||
g.memory = int(200)
|
||||
g.maxmemory = int(400)
|
||||
g.memory = int(200 * 1024)
|
||||
g.maxmemory = int(400 * 1024)
|
||||
g.uuid = "12345678-1234-1234-1234-123456789012"
|
||||
g.cdrom = "/dev/loop0"
|
||||
g.add_device(VirtualGraphics(_conn, "sdl"))
|
||||
|
@ -106,9 +106,9 @@ class XMLParseTest(unittest.TestCase):
|
||||
check("maxvcpus", 5, 12)
|
||||
check("vcpus", 12, 10)
|
||||
check("cpuset", "1-3", "1-8,^6", "1-5,15")
|
||||
check("maxmemory", 400, 500)
|
||||
check("memory", 200, 1000)
|
||||
check("maxmemory", 1000, 2000)
|
||||
check("maxmemory", 409600, 512000)
|
||||
check("memory", 204800, 1024000)
|
||||
check("maxmemory", 1024000, 2048000)
|
||||
check("uuid", "12345678-1234-1234-1234-123456789012",
|
||||
"11111111-2222-3333-4444-555555555555")
|
||||
check("emulator", "/usr/lib/xen/bin/qemu-dm", "/usr/binnnn/fooemu")
|
||||
|
@ -821,7 +821,7 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
def populate_summary(self):
|
||||
distro, version, dlabel, vlabel = self.get_config_os_info()
|
||||
mem = self.pretty_memory(int(self.guest.memory) * 1024)
|
||||
mem = self.pretty_memory(int(self.guest.memory))
|
||||
cpu = str(int(self.guest.vcpus))
|
||||
|
||||
instmethod = self.get_config_install_page()
|
||||
@ -1611,8 +1611,8 @@ class vmmCreate(vmmGObjectUI):
|
||||
|
||||
# Memory
|
||||
try:
|
||||
self.guest.memory = int(mem)
|
||||
self.guest.maxmemory = int(mem)
|
||||
self.guest.memory = int(mem) * 1024
|
||||
self.guest.maxmemory = int(mem) * 1024
|
||||
except Exception, e:
|
||||
return self.err.val_err(_("Error setting guest memory."), e)
|
||||
|
||||
|
@ -1823,7 +1823,7 @@ class vmmDetails(vmmGObjectUI):
|
||||
maxadj.set_range(mem, upper)
|
||||
|
||||
def generate_cpuset(self):
|
||||
mem = int(self.vm.get_memory()) / 1024 / 1024
|
||||
mem = int(self.vm.get_memory()) / 1024
|
||||
return virtinst.Guest.generate_cpuset(self.conn.get_backend(), mem)
|
||||
|
||||
# VCPUS
|
||||
|
@ -538,8 +538,8 @@ class vmmDomain(vmmLibvirtObject):
|
||||
|
||||
def define_both_mem(self, memory, maxmem):
|
||||
def change(guest):
|
||||
guest.memory = int(int(memory) / 1024)
|
||||
guest.maxmemory = int(int(maxmem) / 1024)
|
||||
guest.memory = int(memory)
|
||||
guest.maxmemory = int(maxmem)
|
||||
return self._redefine_guest(change)
|
||||
|
||||
# Security define methods
|
||||
@ -997,9 +997,9 @@ class vmmDomain(vmmLibvirtObject):
|
||||
return self._get_guest(inactive=True).description
|
||||
|
||||
def get_memory(self):
|
||||
return int(self._get_guest().memory * 1024)
|
||||
return int(self._get_guest().memory)
|
||||
def maximum_memory(self):
|
||||
return int(self._get_guest().maxmemory * 1024)
|
||||
return int(self._get_guest().maxmemory)
|
||||
|
||||
def vcpu_count(self):
|
||||
return int(self._get_guest().vcpus)
|
||||
|
@ -139,7 +139,6 @@ class Guest(XMLBuilder):
|
||||
|
||||
cell_mem = conn.getCellsFreeMemory(0, len(cells))
|
||||
cell_id = -1
|
||||
mem = mem * 1024
|
||||
for i in range(len(cells)):
|
||||
if cell_mem[i] < mem:
|
||||
# Cell doesn't have enough mem to fit, skip it
|
||||
@ -288,34 +287,21 @@ class Guest(XMLBuilder):
|
||||
def get_memory(self):
|
||||
return self._memory
|
||||
def set_memory(self, val):
|
||||
if not isinstance(val, int) or val <= 0:
|
||||
raise ValueError(_("Memory value must be an integer greater "
|
||||
"than 0"))
|
||||
self._memory = val
|
||||
|
||||
if self.maxmemory is None or self.maxmemory < val:
|
||||
self.maxmemory = val
|
||||
def _xml_memory_value(self):
|
||||
return int(self.memory) * 1024
|
||||
memory = XMLProperty(get_memory, set_memory,
|
||||
xpath="./currentMemory",
|
||||
get_converter=lambda s, x: int(x) / 1024,
|
||||
set_converter=lambda s, x: int(x) * 1024)
|
||||
memory = XMLProperty(get_memory, set_memory, is_int=True,
|
||||
xpath="./currentMemory")
|
||||
|
||||
# Memory allocated to the guest. Should be given in MB
|
||||
def get_maxmemory(self):
|
||||
return self._maxmemory
|
||||
def set_maxmemory(self, val):
|
||||
if not isinstance(val, int) or val <= 0:
|
||||
raise ValueError(_("Max Memory value must be an integer greater "
|
||||
"than 0"))
|
||||
self._maxmemory = val
|
||||
def _xml_maxmemory_value(self):
|
||||
return int(self.maxmemory) * 1024
|
||||
maxmemory = XMLProperty(get_maxmemory, set_maxmemory,
|
||||
xpath="./memory",
|
||||
get_converter=lambda s, x: int(x) / 1024,
|
||||
set_converter=lambda s, x: int(x) * 1024)
|
||||
maxmemory = XMLProperty(get_maxmemory, set_maxmemory, is_int=True,
|
||||
xpath="./memory")
|
||||
|
||||
def get_hugepage(self):
|
||||
return self._hugepage
|
||||
def set_hugepage(self, val):
|
||||
@ -927,8 +913,8 @@ class Guest(XMLBuilder):
|
||||
xml = add(" <name>%s</name>" % self.name)
|
||||
xml = add(" <uuid>%s</uuid>" % self.uuid)
|
||||
xml = add(desc_xml)
|
||||
xml = add(" <memory>%s</memory>" % (self.maxmemory * 1024))
|
||||
xml = add(" <currentMemory>%s</currentMemory>" % (self.memory * 1024))
|
||||
xml = add(" <memory>%s</memory>" % self.maxmemory)
|
||||
xml = add(" <currentMemory>%s</currentMemory>" % self.memory)
|
||||
|
||||
# <blkiotune>
|
||||
# <memtune>
|
||||
|
@ -636,10 +636,10 @@ def get_memory(memory, guest, image_memory=None):
|
||||
if mem < MIN_RAM:
|
||||
raise ValueError(_("Installs currently require %d megs "
|
||||
"of RAM.") % MIN_RAM)
|
||||
guest.memory = mem
|
||||
guest.memory = mem * 1024
|
||||
|
||||
if memory is None and image_memory is not None:
|
||||
memory = int(image_memory) / 1024
|
||||
memory = int(image_memory)
|
||||
prompt_loop(prompt_txt, err_txt, memory, guest, "memory",
|
||||
func=check_memory)
|
||||
|
||||
|
@ -248,9 +248,9 @@ class XMLProperty(property):
|
||||
@param get_converter:
|
||||
@param set_converter: optional function for converting the property
|
||||
value from the virtinst API to the guest XML. For example,
|
||||
the Guest.memory API is in MB, but the libvirt domain memory API
|
||||
is in KB. So, if xpath is specified, on a 'get' operation we need
|
||||
to convert the XML value with int(val) / 1024.
|
||||
the Guest.memory API was once in MB, but the libvirt domain
|
||||
memory API is in KB. So, if xpath is specified, on a 'get'
|
||||
operation we convert the XML value with int(val) / 1024.
|
||||
@param xml_get_xpath:
|
||||
@param xml_set_xpath: Not all props map cleanly to a static xpath.
|
||||
This allows passing functions which generate an xpath for getting
|
||||
|
Loading…
Reference in New Issue
Block a user