forked from Sysdeploy/idlers-agent
getting os details with /api/os
This commit is contained in:
parent
75744e0010
commit
df525d2908
19
agent.py
19
agent.py
|
@ -234,7 +234,8 @@ class ServerData:
|
||||||
return '127.0.0.1'
|
return '127.0.0.1'
|
||||||
|
|
||||||
def get_os(self):
|
def get_os(self):
|
||||||
os_id = 27
|
server_manager = ServerManager(host, api_key)
|
||||||
|
os_id = server_manager.get_os_id()
|
||||||
logging.info("OS ID: {}".format(os_id))
|
logging.info("OS ID: {}".format(os_id))
|
||||||
return os_id
|
return os_id
|
||||||
|
|
||||||
|
@ -242,7 +243,7 @@ class ServerData:
|
||||||
ram, disk = self.get_ram_and_disk()
|
ram, disk = self.get_ram_and_disk()
|
||||||
post_data = {
|
post_data = {
|
||||||
"server_type": 1,
|
"server_type": 1,
|
||||||
"os_id": self.get_os(),
|
"os_id": self.get_os(host, api_key),
|
||||||
"provider_id": 10,
|
"provider_id": 10,
|
||||||
"location_id": 15,
|
"location_id": 15,
|
||||||
"ssh_port": 22,
|
"ssh_port": 22,
|
||||||
|
@ -404,6 +405,20 @@ class ServerManager:
|
||||||
return self.update_note(note_data, server_id)
|
return self.update_note(note_data, server_id)
|
||||||
else:
|
else:
|
||||||
return self.create_note(note_data)
|
return self.create_note(note_data)
|
||||||
|
|
||||||
|
|
||||||
|
def get_os_id(self):
|
||||||
|
try:
|
||||||
|
response = urllib.request.urlopen(f"{self.host}/api/os")
|
||||||
|
os_list = json.loads(response.read().decode())
|
||||||
|
current_os = os.uname().sysname.lower()
|
||||||
|
for os_entry in os_list:
|
||||||
|
if current_os in os_entry['name'].lower():
|
||||||
|
return os_entry['id']
|
||||||
|
return next(os['id'] for os in os_list if os['name'].lower() == "other")
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Failed to fetch OS IDs: {}".format(e))
|
||||||
|
return 27 # Default to 'Other' if unable to fetch
|
||||||
|
|
||||||
def validate_env_vars():
|
def validate_env_vars():
|
||||||
api_key = os.getenv('AGENT_API')
|
api_key = os.getenv('AGENT_API')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user