forked from Sysdeploy/idlers-agent
Compare commits
3 Commits
b1c89e62e3
...
de3d5fb4ab
Author | SHA1 | Date | |
---|---|---|---|
de3d5fb4ab | |||
0072a07754 | |||
f1d1387dd6 |
49
agent.py
49
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
|
||||
|
@ -46,6 +64,35 @@ 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):
|
||||
|
@ -81,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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user