Compare commits

...

3 Commits

View File

@ -4,6 +4,24 @@ import logging
import json import json
import http.client 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: class ServerData:
def __init__(self): def __init__(self):
self.hostname = os.uname().nodename self.hostname = os.uname().nodename
@ -46,6 +64,35 @@ class ServerData:
return os_id return os_id
def create_post_data(self): def create_post_data(self):
ram, disk = self.get_ram_and_disk()
post_data = {
"server_type": 1,
"os_id": self.get_os(),
"provider_id": 10,
"location_id": 15,
"ssh_port": 22,
"ram": ram >> 10, # convert to GB
"ram_as_mb": ram, # in MB
"disk": disk, # in GB
"disk_as_gb": disk, # in GB
"cpu": self.get_cpu_count(),
"bandwidth": self.get_bandwidth(),
"was_promo": 1,
"active": 1,
"show_public": 0,
"owned_since": "2022-01-01",
"ram_type": "GB",
"disk_type": "GB",
"currency": "USD",
"price": 4,
"payment_term": 1,
"hostname": self.hostname,
"next_due_date": "2022-02-01",
"ip1": self.public_ip,
}
logging.info("Post data created")
return post_data
class ServerManager: class ServerManager:
def __init__(self, host, api_key): def __init__(self, host, api_key):
@ -81,7 +128,7 @@ class ServerManager:
def update_server(self, post_data, server_id): def update_server(self, post_data, server_id):
# remove following keys from post_data # 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) post_data.pop(key, None)
logging.info(f"Updating server with id {server_id}...") logging.info(f"Updating server with id {server_id}...")
return self.send_request('PUT', '/api/servers/' + str(server_id), post_data) return self.send_request('PUT', '/api/servers/' + str(server_id), post_data)