Added note and refactor code #16

Merged
PeterSurda merged 6 commits from swapnil/idlers-agent:main into main 2024-06-26 01:47:20 +02:00
Showing only changes of commit f10d0b53b0 - Show all commits

View File

@ -3,6 +3,8 @@ import urllib.request
import logging
import json
import http.client
import subprocess
import re
NON_UPDATABLE_KEYS = [
'server_type',
@ -25,10 +27,10 @@ class ServerData:
def __init__(self):
self.hostname = os.uname().nodename
self.public_ip = self.get_public_ip()
self.dmidecode_data = parse_dmidecode_output()
self.dmidecode_data = self.parse_dmidecode_output()
logging.basicConfig(level=logging.INFO)
def parse_dmidecode_output():
def parse_dmidecode_output(self):
'''
Example dmidecode output:
@ -177,7 +179,7 @@ class ServerData:
processor_model = processor_info[0].get('Version', 'Unknown') if processor_info else 'Unknown'
processor_count = len(processor_info)
PeterSurda marked this conversation as resolved
Review

I need to verify how it works if there are multiple processors. I have a couple of dual-socket systems, but they always have the same processor model.

I need to verify how it works if there are multiple processors. I have a couple of dual-socket systems, but they always have the same processor model.
Review

Even this part of the code assumes multiple sections with 'DMIType' 4. But only gets 'Version' from the first section. Since you've said "they always have the same processor model", I assume this code should be fine.

Even this part of the code assumes multiple sections with `'DMIType'` 4. But only gets `'Version'` from the first section. Since you've said "they always have the same processor model", I assume this code should be fine.
Review

Yes looks like it's ok.

Yes looks like it's ok.
note = "Chassis Model: {}, Serial Number: {}\nProcessor Model: {}, Count: {}\nRAM Details:\n{}".format(
note = "Chassis Model: {} | Serial Number: {} ||| Processor Model: {} | Count: {} ||| RAM Details: {}".format(
chassis_model, chassis_serial, processor_model, processor_count, '\n'.join(['R1', 'R2', 'R3']))
note_data = {
@ -255,7 +257,7 @@ class ServerManager:
response = self.create_server(post_data)
# Extract the server_id from the response
server_id = response.get('server_id', None)
server_id = json.loads(response).get('server_id', None)
if server_id is None:
logging.error('Failed to get server_id from response: {}'.format(response))
raise ValueError('Failed to get server_id from response')