Compare commits

...

2 Commits

Author SHA1 Message Date
0e996333b2
updated cpu_count - use dmedecode 2024-06-23 14:26:58 +05:30
f73823cd07
removed show_public from non updatable keys 2024-06-18 11:06:21 +05:30

View File

@ -13,7 +13,6 @@ NON_UPDATABLE_KEYS = [
'bandwidth', 'bandwidth',
'was_promo', 'was_promo',
'active', 'active',
'show_public',
'owned_since', 'owned_since',
'currency', 'currency',
'price', 'price',
@ -39,6 +38,17 @@ class ServerData:
return ram, disk return ram, disk
def get_cpu_count(self): def get_cpu_count(self):
cpu_count = 0
if os.path.isfile('/usr/sbin/dmidecode'):
try:
output = subprocess.check_output(['sudo', '/usr/sbin/dmidecode', '-t', 'processor']).decode('utf-8')
core_match = re.search(r'Core Count: (\d+)', output)
thread_match = re.search(r'Thread Count: (\d+)', output)
if core_match and thread_match:
cpu_count = int(core_match.group(1)) * int(thread_match.group(1))
except subprocess.CalledProcessError:
pass
if cpu_count == 0:
with open('/proc/cpuinfo', 'r') as f: with open('/proc/cpuinfo', 'r') as f:
cpuinfo = f.read() cpuinfo = f.read()
cpu_count = cpuinfo.count('processor') cpu_count = cpuinfo.count('processor')