refractor

This commit is contained in:
Shailaja Kumari 2024-07-05 15:03:11 +05:30
parent 9c581fb6dd
commit 49a3f63c34
Signed by: shailaja
GPG Key ID: 2B9455CAFBC4D75A

View File

@ -264,14 +264,14 @@ class ServerData:
def get_os_id(self, os_list):
try:
os_info = self.get_os_release_info()
if not os_info:
logging.error("No OS release info found.")
for os_entry in os_list:
if os_entry['name'].lower() in ["other", "custom"]:
return os_entry['id']
return None
return 1
if 'NAME' in os_info and 'VERSION' in os_info:
current_os = f"{os_info.get('NAME', 'Unknown')} {os_info.get('VERSION', '').strip()}".strip().lower()
@ -295,17 +295,13 @@ class ServerData:
for os_entry in os_list:
if os_entry['name'].lower() in ["other", "custom"]:
return os_entry['id']
return None
except Exception as e:
logging.error("Failed to fetch OS ID: {}".format(e))
for os_entry in os_list:
if os_entry['name'].lower() in ["other", "custom"]:
return os_entry['id']
return None
return 1
def create_post_data(self):
ram, disk = self.get_ram_and_disk()
os_list = self.get_os_list()
post_data = {
"server_type": 1,
"os_id": self.get_os_id(os_list),
@ -473,12 +469,8 @@ class ServerManager:
def get_os_list(self):
os_list = self.send_request('GET', '/api/v1/os')
if os_list:
logging.info("OS list fetched successfully")
return os_list
else:
logging.error("Failed to fetch OS list")
return []
logging.info("OS list fetched successfully") if os_list else logging.error("Failed to fetch OS list")
return os_list or []
def validate_env_vars():
api_key = os.getenv('AGENT_API')