forked from Sysdeploy/idlers-agent
Compare commits
No commits in common. "de3d5fb4abb42bd64a3f3751ef6a33b8acbe80aa" and "b1c89e62e3ab8e41f2caa2291c756844fbdf5d5a" have entirely different histories.
de3d5fb4ab
...
b1c89e62e3
49
agent.py
49
agent.py
|
@ -4,24 +4,6 @@ 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
|
||||
|
@ -64,35 +46,6 @@ class ServerData:
|
|||
return os_id
|
||||
|
||||
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:
|
||||
def __init__(self, host, api_key):
|
||||
|
@ -128,7 +81,7 @@ class ServerManager:
|
|||
|
||||
def update_server(self, post_data, server_id):
|
||||
# remove following keys from post_data
|
||||
for key in NON_UPDATABLE_KEYS:
|
||||
for key in ['ssh_port', 'ip1', 'currency', 'price', 'payment_term', 'next_due_date']:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user