forked from Sysdeploy/idlers-agent
minor fixes
This commit is contained in:
parent
3940cbdbde
commit
f10d0b53b0
10
agent.py
10
agent.py
|
@ -3,6 +3,8 @@ import urllib.request
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import http.client
|
import http.client
|
||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
NON_UPDATABLE_KEYS = [
|
NON_UPDATABLE_KEYS = [
|
||||||
'server_type',
|
'server_type',
|
||||||
|
@ -25,10 +27,10 @@ class ServerData:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.hostname = os.uname().nodename
|
self.hostname = os.uname().nodename
|
||||||
self.public_ip = self.get_public_ip()
|
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)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
def parse_dmidecode_output():
|
def parse_dmidecode_output(self):
|
||||||
'''
|
'''
|
||||||
Example dmidecode output:
|
Example dmidecode output:
|
||||||
|
|
||||||
|
@ -177,7 +179,7 @@ class ServerData:
|
||||||
processor_model = processor_info[0].get('Version', 'Unknown') if processor_info else 'Unknown'
|
processor_model = processor_info[0].get('Version', 'Unknown') if processor_info else 'Unknown'
|
||||||
processor_count = len(processor_info)
|
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']))
|
chassis_model, chassis_serial, processor_model, processor_count, '\n'.join(['R1', 'R2', 'R3']))
|
||||||
|
|
||||||
note_data = {
|
note_data = {
|
||||||
|
@ -255,7 +257,7 @@ class ServerManager:
|
||||||
response = self.create_server(post_data)
|
response = self.create_server(post_data)
|
||||||
|
|
||||||
# Extract the server_id from the response
|
# 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:
|
if server_id is None:
|
||||||
logging.error('Failed to get server_id from response: {}'.format(response))
|
logging.error('Failed to get server_id from response: {}'.format(response))
|
||||||
raise ValueError('Failed to get server_id from response')
|
raise ValueError('Failed to get server_id from response')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user