forked from 3wordchant/capsul-flask
fixing get inconsistency and adding vm_state_command
This commit is contained in:
@ -45,6 +45,9 @@ class MockHub(VirtualizationInterface):
|
||||
def destroy(self, email: str, id: str):
|
||||
current_app.logger.info(f"mock destroy: {id} for {email}")
|
||||
|
||||
def vm_state_command(self, email: str, id: str, command: str):
|
||||
current_app.logger.info(f"mock {command}: {id} for {email}")
|
||||
|
||||
|
||||
class CapsulFlaskHub(VirtualizationInterface):
|
||||
|
||||
@ -236,3 +239,25 @@ class CapsulFlaskHub(VirtualizationInterface):
|
||||
|
||||
if not result_status == "success":
|
||||
raise ValueError(f"""failed to destroy vm "{id}" on host "{host.id}" for {email}: {result_json_string}""")
|
||||
|
||||
|
||||
def vm_state_command(self, email: str, id: str, command: str):
|
||||
validate_capsul_id(id)
|
||||
result_status = None
|
||||
host = get_model().host_of_capsul(id)
|
||||
if host is not None:
|
||||
payload = json.dumps(dict(type="vm_state_command", email=email, id=id, command=command))
|
||||
results = self.synchronous_operation([host], payload)
|
||||
result_json_string = "<no response from host>"
|
||||
for result in results:
|
||||
try:
|
||||
result_json_string = result.body
|
||||
result_body = json.loads(result_json_string)
|
||||
if isinstance(result_body, dict) and 'status' in result_body:
|
||||
result_status = result_body['status']
|
||||
except:
|
||||
pass
|
||||
|
||||
if not result_status == "success":
|
||||
raise ValueError(f"""failed to {command} vm "{id}" on host "{host.id}" for {email}: {result_json_string}""")
|
||||
|
||||
|
Reference in New Issue
Block a user