@@ -73,24 +73,36 @@ def default_memory_for_version(host_mem_kib, platform_version):
7373 else :
7474 return default_memory_v3 (host_mem_kib )
7575
76- def default_memory (host_mem_kib ):
77- """Return the default for the amount of dom0 memory for the
78- specified amount of host memory for the current platform version"""
79-
80- # read current host version
81- platform_version = None
76+ def crash_kernel_memory_for_version (platform_version ):
77+ """Return the default crash kernel memory size in KiB for the given
78+ platform version."""
79+ # Need to update this if we change the crash kernel memory in the future version
80+ if platform_version >= version .Version ([3 , 99 , 90 ]):
81+ return 512 * 1024
82+ if platform_version >= version .Version ([3 , 0 , 50 ]):
83+ return 256 * 1024
84+ # Earlier versions are far past EOL, so don't consider them
85+ return 192 * 1024
86+
87+ def _read_platform_version ():
88+ """Read PLATFORM_VERSION from /etc/xensource-inventory."""
8289 with open_with_codec_handling ("/etc/xensource-inventory" ) as f :
8390 for l in f .readlines ():
8491 line = l .strip ()
8592 if line .startswith ('PLATFORM_VERSION=' ):
86- platform_version = version .Version .from_string (
87- line .split ('=' , 1 )[1 ].strip ("'" ))
88- break
93+ return version .Version .from_string (
94+ line .split ('=' , 1 )[1 ].strip ("'" ))
95+ raise RuntimeError ( 'Could not find PLATFORM_VERSION from inventory.' )
8996
90- if not platform_version :
91- raise RuntimeError ('Could not find PLATFORM_VERSION from inventory.' )
97+ def default_memory (host_mem_kib ):
98+ """Return the default for the amount of dom0 memory for the
99+ specified amount of host memory for the current platform version"""
100+ return default_memory_for_version (host_mem_kib , _read_platform_version ())
92101
93- return default_memory_for_version (host_mem_kib , platform_version )
102+ def crash_kernel_memory ():
103+ """Return the default crash kernel memory size in KiB for the
104+ current platform version."""
105+ return crash_kernel_memory_for_version (_read_platform_version ())
94106
95107
96108_size_and_unit_re = re .compile (r"^(-?\d+)([bkmg]?)$" , re .IGNORECASE )
0 commit comments