Handle creating Qemu disk images and resizing

This commit is contained in:
grossmj
2022-04-07 16:21:47 +08:00
parent 888c773dc0
commit fda2a37b98
20 changed files with 701 additions and 472 deletions

View File

@ -30,10 +30,13 @@ from ..utils import parse_version
from ..utils.asyncio import locking
from ..controller.controller_error import (
ControllerError,
ControllerBadRequestError,
ControllerNotFoundError,
ControllerForbiddenError,
ControllerTimeoutError,
ControllerUnauthorizedError,
ComputeError,
ComputeConflictError
)
from ..version import __version__, __version_info__
@ -43,23 +46,6 @@ import logging
log = logging.getLogger(__name__)
class ComputeError(ControllerError):
pass
# FIXME: broken
class ComputeConflict(ComputeError):
"""
Raise when the compute send a 409 that we can handle
:param response: The response of the compute
"""
def __init__(self, response):
super().__init__(response["message"])
self.response = response
class Compute:
"""
A GNS3 compute.
@ -574,7 +560,9 @@ class Compute:
else:
msg = ""
if response.status == 401:
if response.status == 400:
raise ControllerBadRequestError(msg)
elif response.status == 401:
raise ControllerUnauthorizedError(f"Invalid authentication for compute '{self.name}' [{self.id}]")
elif response.status == 403:
raise ControllerForbiddenError(msg)
@ -584,7 +572,7 @@ class Compute:
raise ControllerTimeoutError(f"{method} {path} request timeout")
elif response.status == 409:
try:
raise ComputeConflict(json.loads(body))
raise ComputeConflictError(url, json.loads(body))
# If the 409 doesn't come from a GNS3 server
except ValueError:
raise ControllerError(msg)
@ -593,7 +581,7 @@ class Compute:
elif response.status == 503:
raise aiohttp.web.HTTPServiceUnavailable(text=f"Service unavailable {url} {body}")
else:
raise NotImplementedError(f"{response.status} status code is not supported for {method} '{url}'")
raise NotImplementedError(f"{response.status} status code is not supported for {method} '{url}'\n{body}")
if body and len(body):
if raw:
response.body = body