应用管理器客户端
App Manager Client
Provides API for managing application containers: - Install, start, stop, uninstall applications - Get application info and stats - Stream application logs
- class neoruntime_ipc_sdk.app.AppInfo(id, name, version, state, container_id, pid, installed_at, started_at, stopped_at, restart_count, manifest_path, instance_path)[source]
Bases:
objectApplication information
- __init__(id, name, version, state, container_id, pid, installed_at, started_at, stopped_at, restart_count, manifest_path, instance_path)
- class neoruntime_ipc_sdk.app.AppStats(app_id, cpu_usage_percent, memory_usage_bytes, memory_limit_bytes, thread_count, uptime_seconds)[source]
Bases:
objectApplication runtime statistics
- __init__(app_id, cpu_usage_percent, memory_usage_bytes, memory_limit_bytes, thread_count, uptime_seconds)
- class neoruntime_ipc_sdk.app.LogLine(timestamp, level, message)[source]
Bases:
objectSingle log line
- __init__(timestamp, level, message)
- class neoruntime_ipc_sdk.app.AppClient(endpoint=None)[source]
Bases:
GrpcClientApplication Container Management Client
Usage:
app_client = AppClient() # List all apps apps = app_client.list_apps() for app in apps: print(f"{app.name}: {app.state}") # Get logs (last 100 lines) for line in app_client.get_logs("my_app", max_lines=100): print(line) # Follow logs in real-time for line in app_client.get_logs("my_app", follow=True): print(line)
- register_web_url(path='/')[source]
Register a web access path for this app.
After calling this method, the web console will show a “Visit App” button linking to
http://{device_ip}:{inbound_port}{path}.Requires the
APP_IDenvironment variable to be set (injected automatically by the platform when the container starts).- Parameters:
path (str) – Web page path, default
"/"
- restart_app(app_id, timeout_seconds=30)[source]
Restart a running application (stop + start).
This is a composite operation since the gRPC service does not expose a dedicated RestartApp RPC. It stops the app and then starts it again.
- get_logs(app_id, max_lines=100, follow=False)[source]
Get application logs
- Parameters:
- Yields:
LogLine objects
Examples
# Get last 100 lines for line in app_client.get_logs("my_app", max_lines=100): print(line) # Follow logs in real-time for line in app_client.get_logs("my_app", follow=True): print(line)
使用示例
应用生命周期管理
from neoruntime_ipc_sdk import AppClient
app = AppClient()
# 列出所有应用
apps = app.list_apps()
for a in apps:
print(f"{a.name}: {a.state}")
# 安装应用
app_id = app.install_app(
manifest_path="/data/apps/my_app/app.yaml",
image_path="/data/apps/my_app/image.tar"
)
# 启动应用
app.start_app(app_id)
# 重启应用(停止+启动)
app.restart_app(app_id, timeout_seconds=30)
# 停止应用
app.stop_app(app_id)
# 卸载应用
app.uninstall_app(app_id, keep_logs=True)
获取应用信息
# 获取应用详情
info = app.get_app("my_app")
print(f"名称: {info.name}")
print(f"版本: {info.version}")
print(f"状态: {info.state}")
# 获取应用统计
stats = app.get_app_stats("my_app")
print(f"CPU: {stats.cpu_usage_percent}%")
print(f"内存: {stats.memory_usage_bytes / 1024 / 1024:.1f} MB")
查看应用日志
# 获取最近 100 行日志
for line in app.get_logs("my_app", max_lines=100):
print(line)
# 实时跟踪日志
for line in app.get_logs("my_app", follow=True):
print(line)
# 获取文本格式日志
for text in app.get_logs_text("my_app"):
print(text)
注册 Web 访问路径
# 在应用容器内注册 Web 访问路径
# 需要环境变量 APP_ID(平台自动注入)
app.register_web_url("/")
# 注册自定义路径
app.register_web_url("/dashboard")
上下文管理器
with AppClient() as app:
apps = app.list_apps()
for a in apps:
print(f"{a.name}: {a.state}")