mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-22 13:34:07 +03:00
osdict: return _OsResources to callers
Use the class helper routines to save some tedious dict management
This commit is contained in:
parent
e76e350a8d
commit
12440b00c1
@ -27,10 +27,11 @@ class TestOSDB(unittest.TestCase):
|
||||
def test_recommended_resources(self):
|
||||
conn = utils.URIs.open_testdefault_cached()
|
||||
guest = Guest(conn)
|
||||
assert not OSDB.lookup_os("generic").get_recommended_resources(guest)
|
||||
res = OSDB.lookup_os("generic").get_recommended_resources()
|
||||
self.assertEqual(res.get_recommended_ram(guest.os.arch), None)
|
||||
|
||||
res = OSDB.lookup_os("fedora21").get_recommended_resources(guest)
|
||||
assert res["n-cpus"] == 2
|
||||
res = OSDB.lookup_os("fedora21").get_recommended_resources()
|
||||
self.assertEqual(res.get_recommended_ncpus(guest.os.arch), 2)
|
||||
|
||||
def test_urldetct_matching_distros(self):
|
||||
allstores = urldetect.ALLSTORES
|
||||
|
15
virt-install
15
virt-install
@ -526,12 +526,15 @@ def set_resources_from_osinfo(options, guest):
|
||||
if options.disk:
|
||||
return
|
||||
|
||||
res = guest.osinfo.get_recommended_resources(guest)
|
||||
if res and res.get('storage') > 0:
|
||||
diskstr = 'size=%d' % (res.get('storage') // (1024 ** 3))
|
||||
logging.debug("Generated default libosinfo '--disk %s'", diskstr)
|
||||
options.disk = [diskstr]
|
||||
cli.ParserDisk(diskstr, guest=guest).parse(None)
|
||||
res = guest.osinfo.get_recommended_resources()
|
||||
storage = res.get_recommended_storage(guest.os.arch)
|
||||
if not storage:
|
||||
return
|
||||
|
||||
diskstr = 'size=%d' % (storage // (1024 ** 3))
|
||||
logging.debug("Generated default libosinfo '--disk %s'", diskstr)
|
||||
options.disk = [diskstr]
|
||||
cli.ParserDisk(diskstr, guest=guest).parse(None)
|
||||
|
||||
|
||||
def build_guest_instance(conn, options):
|
||||
|
@ -1674,23 +1674,24 @@ class vmmCreate(vmmGObjectUI):
|
||||
self._addstorage.check_path_search(
|
||||
self, self.conn, path)
|
||||
|
||||
res = self._guest.osinfo.get_recommended_resources(self._guest)
|
||||
logging.debug("Recommended resources for os=%s: %s",
|
||||
self._guest.osinfo.name, res)
|
||||
res = self._guest.osinfo.get_recommended_resources()
|
||||
ram = res.get_recommended_ram(self._guest.os.arch)
|
||||
n_cpus = res.get_recommended_ncpus(self._guest.os.arch)
|
||||
storage = res.get_recommended_storage(self._guest.os.arch)
|
||||
logging.debug("Recommended resources for os=%s: "
|
||||
"ram=%s ncpus=%s storage=%s",
|
||||
self._guest.osinfo.name, ram, n_cpus, storage)
|
||||
|
||||
# Change the default values suggested to the user.
|
||||
ram_size = DEFAULT_MEM
|
||||
if res and res.get("ram") > 0:
|
||||
ram_size = res["ram"] // (1024 ** 2)
|
||||
if ram:
|
||||
ram_size = ram // (1024 ** 2)
|
||||
self.widget("mem").set_value(ram_size)
|
||||
|
||||
n_cpus = 1
|
||||
if res and res.get("n-cpus") > 0:
|
||||
n_cpus = res["n-cpus"]
|
||||
self.widget("cpus").set_value(n_cpus)
|
||||
self.widget("cpus").set_value(n_cpus or 1)
|
||||
|
||||
if res and res.get("storage"):
|
||||
storage_size = int(res["storage"]) // (1024 ** 3)
|
||||
if storage:
|
||||
storage_size = storage // (1024 ** 3)
|
||||
self._addstorage.widget("storage-size").set_value(storage_size)
|
||||
|
||||
# Stash the installer in the _guest instance so we don't need
|
||||
|
@ -656,13 +656,16 @@ class Guest(XMLBuilder):
|
||||
########################
|
||||
|
||||
def _set_default_resources(self):
|
||||
res = self.osinfo.get_recommended_resources(self)
|
||||
res = self.osinfo.get_recommended_resources()
|
||||
|
||||
if not self.currentMemory and res and res.get('ram') > 0:
|
||||
self.currentMemory = res['ram'] // 1024
|
||||
if not self.currentMemory:
|
||||
ram = res.get_recommended_ram(self.os.arch)
|
||||
if ram:
|
||||
self.currentMemory = ram // 1024
|
||||
|
||||
if not self.vcpus:
|
||||
self.vcpus = res.get('n-cpus') if res and res.get('n-cpus') > 0 else 1
|
||||
ncpus = res.get_recommended_ncpus(self.os.arch)
|
||||
self.vcpus = ncpus or 1
|
||||
|
||||
|
||||
def _set_default_machine(self):
|
||||
|
@ -515,16 +515,10 @@ class _OsVariant(object):
|
||||
devids = ["http://qemu.org/chipset/x86/q35"]
|
||||
return bool(self._device_filter(devids=devids))
|
||||
|
||||
def get_recommended_resources(self, guest):
|
||||
def get_recommended_resources(self):
|
||||
minimum = self._os and self._os.get_minimum_resources() or None
|
||||
recommended = self._os and self._os.get_recommended_resources() or None
|
||||
osresources = _OsResources(minimum, recommended)
|
||||
|
||||
ret = {}
|
||||
ret["ram"] = osresources.get_recommended_ram(guest.os.arch)
|
||||
ret["n-cpus"] = osresources.get_recommended_ncpus(guest.os.arch)
|
||||
ret["storage"] = osresources.get_recommended_storage(guest.os.arch)
|
||||
return {k: v for k, v in ret.items() if v}
|
||||
return _OsResources(minimum, recommended)
|
||||
|
||||
def get_network_install_resources(self, guest):
|
||||
ret = {}
|
||||
|
Loading…
Reference in New Issue
Block a user