From de3d5fb4abb42bd64a3f3751ef6a33b8acbe80aa Mon Sep 17 00:00:00 2001 From: Shailaja Date: Thu, 13 Jun 2024 16:15:24 +0530 Subject: [PATCH] Implemented key categorization to distinguish between keys set only during server creation and those that can be updated --- agent.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/agent.py b/agent.py index f5deb03..b5f9418 100644 --- a/agent.py +++ b/agent.py @@ -4,6 +4,24 @@ import logging import json import http.client +NON_UPDATABLE_KEYS = [ + 'server_type', + 'os_id', + 'provider_id', + 'location_id', + 'ssh_port', + 'bandwidth', + 'was_promo', + 'active', + 'show_public', + 'owned_since', + 'currency', + 'price', + 'payment_term', + 'next_due_date', + 'ip1' +] + class ServerData: def __init__(self): self.hostname = os.uname().nodename @@ -110,7 +128,7 @@ class ServerManager: def update_server(self, post_data, server_id): # remove following keys from post_data - for key in ['ssh_port', 'ip1', 'currency', 'price', 'payment_term', 'next_due_date']: + for key in NON_UPDATABLE_KEYS: post_data.pop(key, None) logging.info(f"Updating server with id {server_id}...") return self.send_request('PUT', '/api/servers/' + str(server_id), post_data)