Skip to content

Commit

Permalink
Initial k exec + ollama update
Browse files Browse the repository at this point in the history
  • Loading branch information
NotChristianGarcia committed Jan 27, 2025
1 parent d25a061 commit e74618a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion scripts/Dockerfile.ollama
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# debian based - ghcr.io/open-webui/open-webui:ollama
# from ghcr.io/open-webui/open-webui:ollama
FROM ollama/ollama:0.4.4
FROM ollama/ollama:0.5.6
RUN apt update
RUN apt-get install -y wget btop htop
RUN apt-get install -y nix
Expand Down
44 changes: 42 additions & 2 deletions service/api_pods_podid_func.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse, RedirectResponse
from models_pods import Pod, Password, PodResponse, PodPermissionsResponse, PodCredentialsResponse, PodLogsResponse
from models_pods import Pod, Password, PodResponse, PodPermissionsResponse, PodCredentialsResponse, PodLogsResponse, ExecutePodCommand
from models_misc import SetPermission
from channels import CommandChannel
from codes import OFF, ON, RESTART, REQUESTED, STOPPED
Expand All @@ -9,7 +9,8 @@
from tapisservice.config import conf
from __init__ import t, BadRequestError
from models_templates_tags import combine_pod_and_template_recursively

from typing import List, Any
from kubernetes_utils import run_k8_exec

from tapisservice.logs import get_logger
logger = get_logger(__name__)
Expand Down Expand Up @@ -132,6 +133,45 @@ async def set_pod_permission(pod_id, set_permission: SetPermission):
return ok(result={"permissions": pod.permissions}, msg = "Pod permissions updated successfully.")


@router.post(
"/pods/{pod_id}/exec",
tags=["Executions"],
summary="exec_pod_command",
operation_id="exec_pod_command",
)#response_model=Any)
async def exec_pod_command(pod_id, command: ExecutePodCommand):
"""
Execute a command in a pod.
Returns the command output.
"""

# TODO .display(), search, permissions
logger.info(f"POST /pods/{pod_id}/exec - Top of exec_pod_command.")
pod = Pod.db_get_with_pk(pod_id, tenant=g.request_tenant_id, site=g.site_id)

try:
logger.error(f"Running command in pod {pod_id}: {command.command}")
stdout, stderr = run_k8_exec(pod.k8_name, command.command)
success = True
except Exception as e:
logger.error(f"Error executing command in pod {pod_id}: {e}")
stdout, stderr = "", str(e)
success = False

logs = {
"stdout": stdout,
"stderr": stderr,
"success": success
}

#pod.logs.append(f"exec_pod_command ran by {g.username}: {command} \n stdout: {stdout}")
pod.db_update(f"'{g.username}' ran exec_pod_command with command: {command} \n stdout: {stdout}")


return ok(result={"logs": logs}, msg="Pod execution ran successfully." if success else "Pod execution failed.")


@router.delete(
"/pods/{pod_id}/permissions/{user}",
tags=["Permissions"],
Expand Down
1 change: 1 addition & 0 deletions service/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def check_route_permissions(request):
["/pods/{pod_id}/start", "GET", codes.ADMIN],
["/pods/{pod_id}/restart", "GET", codes.ADMIN],
["/pods/{pod_id}/derived", "GET", codes.READ],
["/pods/{pod_id}/exec", "POST", codes.ADMIN],
["/pods/{pod_id_net}/auth", "GET", "NOT-API"],
["/pods/{pod_id_net}/auth/callback", "GET", "NOT-API"],
["/pods/{pod_id}", "GET", codes.READ],
Expand Down

0 comments on commit e74618a

Please sign in to comment.