got httpclient working, spoke heartbeat is working
This commit is contained in:
@ -12,33 +12,9 @@ from time import sleep
|
||||
from os.path import join
|
||||
from subprocess import run
|
||||
|
||||
from capsulflask.db_model import OnlineHost
|
||||
from capsulflask.spoke_model import validate_capsul_id
|
||||
from capsulflask.db import get_model, my_exec_info_message
|
||||
from capsulflask.db import get_model
|
||||
from capsulflask.http_client import HTTPResult
|
||||
|
||||
class VirtualMachine:
|
||||
def __init__(self, id, host, ipv4=None, ipv6=None):
|
||||
self.id = id
|
||||
self.host = host
|
||||
self.ipv4 = ipv4
|
||||
self.ipv6 = ipv6
|
||||
|
||||
class VirtualizationInterface:
|
||||
def capacity_avaliable(self, additional_ram_bytes: int) -> bool:
|
||||
pass
|
||||
|
||||
def get(self, id: str) -> VirtualMachine:
|
||||
pass
|
||||
|
||||
def list_ids(self) -> list:
|
||||
pass
|
||||
|
||||
def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory: int, ssh_public_keys: list):
|
||||
pass
|
||||
|
||||
def destroy(self, email: str, id: str):
|
||||
pass
|
||||
from capsulflask.shared import VirtualizationInterface, VirtualMachine, OnlineHost, validate_capsul_id, my_exec_info_message
|
||||
|
||||
class MockHub(VirtualizationInterface):
|
||||
def capacity_avaliable(self, additional_ram_bytes):
|
||||
@ -61,11 +37,11 @@ class MockHub(VirtualizationInterface):
|
||||
|
||||
|
||||
class CapsulFlaskHub(VirtualizationInterface):
|
||||
|
||||
|
||||
def generic_operation(self, hosts: List[OnlineHost], payload: str, immediate_mode: bool) -> Tuple[int, List[HTTPResult]]:
|
||||
operation_id = get_model().create_operation(hosts, payload)
|
||||
authorization_header = f"Bearer {current_app.config['HUB_TOKEN']}"
|
||||
results = current_app.config["HTTP_CLIENT"].make_requests_sync(hosts, payload, authorization_header=authorization_header)
|
||||
results = current_app.config["HTTP_CLIENT"].make_requests_sync(hosts, "/spoke/operation", payload, authorization_header=authorization_header)
|
||||
for i in range(len(hosts)):
|
||||
host = hosts[i]
|
||||
result = results[i]
|
||||
@ -137,7 +113,7 @@ class CapsulFlaskHub(VirtualizationInterface):
|
||||
host = get_model().host_of_capsul(id)
|
||||
if host is not None:
|
||||
payload = json.dumps(dict(type="get", id=id))
|
||||
op = await self.generic_operation([host], payload, True)
|
||||
op = self.generic_operation([host], payload, True)
|
||||
results = op[1]
|
||||
for result in results:
|
||||
try:
|
||||
@ -152,7 +128,7 @@ class CapsulFlaskHub(VirtualizationInterface):
|
||||
def list_ids(self) -> list:
|
||||
online_hosts = get_model().get_online_hosts()
|
||||
payload = json.dumps(dict(type="list_ids"))
|
||||
op = await self.generic_operation(online_hosts, payload, False)
|
||||
op = self.generic_operation(online_hosts, payload, False)
|
||||
operation_id = op[0]
|
||||
results = op[1]
|
||||
to_return = []
|
||||
@ -197,7 +173,7 @@ class CapsulFlaskHub(VirtualizationInterface):
|
||||
memory_mb=memory_mb,
|
||||
ssh_public_keys=ssh_public_keys,
|
||||
))
|
||||
op = await self.generic_operation(online_hosts, payload, False)
|
||||
op = self.generic_operation(online_hosts, payload, False)
|
||||
operation_id = op[0]
|
||||
results = op[1]
|
||||
number_of_assigned = 0
|
||||
@ -230,7 +206,7 @@ class CapsulFlaskHub(VirtualizationInterface):
|
||||
host = get_model().host_of_capsul(id)
|
||||
if host is not None:
|
||||
payload = json.dumps(dict(type="destroy", id=id))
|
||||
op = await self.generic_operation([host], payload, True)
|
||||
op = self.generic_operation([host], payload, True)
|
||||
results = op[1]
|
||||
result_json_string = "<no response from host>"
|
||||
for result in results:
|
||||
|
Reference in New Issue
Block a user