From 7ab3d18ae95c35a47ce6baadc31282150a072fae Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 20 Jun 2024 20:36:49 +0800 Subject: [PATCH] Add note support - note content is dummy for now --- agent.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/agent.py b/agent.py index 897db5a..f21703e 100644 --- a/agent.py +++ b/agent.py @@ -121,6 +121,17 @@ class ServerManager: def get_existing_servers(self): return self.send_request('GET', '/api/servers') + def get_note(self, service_id): + return self.send_request('GET', '/api/notes/' + str(service_id)) + + def create_note(self, post_data): + logging.info("Creating note...") + return self.send_request('POST', '/api/notes', post_data) + + def update_note(self, post_data, service_id): + logging.info(f"Updating note with id {service_id}...") + return self.send_request('PUT', '/api/notes/' + str(service_id), post_data) + def create_server(self, post_data): logging.info("Creating server...") return self.send_request('POST', '/api/servers', post_data) @@ -169,5 +180,18 @@ def main(): logging.info('Server does not exist, Creating...') logging.info(server_manager.create_server(post_data)) + note_data = { + 'service_id': server_id, + 'note': 'Bla bla bla' + } + try: + note = server_manager.get_note(server_id) + except urllib.error.HTTPError: + note = None + if note: + server_manager.update_note(note_data, server_id) + else: + server_manager.create_note(note_data) + if __name__ == '__main__': - main() \ No newline at end of file + main()