-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add endpoint to run containers out of Containernet
- Loading branch information
Showing
6 changed files
with
57 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from clusternet.apis.presentation.exceptions import BadRequestException | ||
from clusternet.apis.presentation.helpers import ( | ||
bad_request, created, error, internal_server_error, validate_required_params | ||
) | ||
from clusternet.apis.presentation.protocols import Controller, HttpRequest, HttpResponse | ||
from clusternet.apis.worker.helpers import get_hostname, run_container | ||
|
||
|
||
class RunServiceController(Controller): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def handle(self, request: HttpRequest) -> HttpResponse: | ||
required_params = ['name', 'image'] | ||
try: | ||
hostname = get_hostname() | ||
validate_required_params(request, required_params) | ||
|
||
name = str(request.body.pop('name')) | ||
image = str(request.body.pop('image')) | ||
run_container(name, image, **request.body) | ||
|
||
return created({'content': f'[{hostname}]: service {name} created'}) | ||
except BadRequestException as ex: | ||
return bad_request(error(f'{ex}')) | ||
except Exception as ex: | ||
return internal_server_error(error(f'{ex}')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters