From f10d0b53b05a0e162df0c27500ff6ce5e89e64c7 Mon Sep 17 00:00:00 2001 From: Swapnil Date: Tue, 25 Jun 2024 15:32:51 +0530 Subject: [PATCH] minor fixes --- agent.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/agent.py b/agent.py index 2987fd1..a3b7b9d 100644 --- a/agent.py +++ b/agent.py @@ -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) - 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')