Skip to content

CLI 参考

umoo-cli 二进制文件提供对 Umoo 平台的命令行访问,用于脚本和自动化。

安装

从源码构建:

bash
make build
# 二进制文件:./bin/umoo-cli

或从发布包复制到 $PATH 中的目录。

配置

umoo-cli 从环境变量或命令行参数读取配置:

环境变量参数描述
UMOO_URL--url服务器基础 URL(例如 https://umoo.yun
UMOO_TOKEN--tokenJWT 访问令牌或 API 密钥
UMOO_TENANT_ID--tenant-id租户 UUID

也可以在当前目录的 .env 文件中设置。

认证

bash
# 登录并存储令牌
umoo-cli auth login --email admin@example.com --password secret

# 显示当前令牌信息
umoo-cli auth me

命令

设备

bash
# 列出设备
umoo-cli devices list
umoo-cli devices list --group <group-id>
umoo-cli devices list --status online

# 获取设备详情
umoo-cli devices get <device-id>

# 生成认领令牌
umoo-cli devices claim-token --group <group-id> --ttl 24h

# 更新设备
umoo-cli devices update <device-id> --name "new-name" --group <group-id>

设备组

bash
# 列出分组
umoo-cli groups list

# 创建分组
umoo-cli groups create --name "prod-fleet" --description "生产设备"

# 删除分组
umoo-cli groups delete <group-id>

应用

bash
# 列出应用
umoo-cli apps list

# 创建应用
umoo-cli apps create --name nginx --type container

# 创建版本
umoo-cli apps versions create <app-id> --version 1.0.0 --spec '{"image":"nginx:latest"}'

# 列出版本
umoo-cli apps versions list <app-id>

发布

bash
# 列出发布
umoo-cli rollouts list
umoo-cli rollouts list --status running

# 获取发布详情
umoo-cli rollouts get <rollout-id>

# 创建发布
umoo-cli rollouts create \
  --name "firmware-v2" \
  --group <group-id> \
  --strategy rolling \
  --batch-size 10 \
  --failure-threshold 20 \
  --target-version '{"firmware":"v2.0.0"}'

# 执行发布
umoo-cli rollouts execute <rollout-id>

# 暂停 / 恢复 / 取消
umoo-cli rollouts pause <rollout-id>
umoo-cli rollouts resume <rollout-id>
umoo-cli rollouts cancel <rollout-id>

影子状态

bash
# 获取设备影子
umoo-cli shadow get <device-id>

# 设置期望状态
umoo-cli shadow set <device-id> '{"apps":{"nginx":{"version":"1.0.0"}}}'

用户

bash
# 列出租户中的用户
umoo-cli users list

# 创建用户
umoo-cli users create --email user@example.com --password secret --role operator

# 更改用户角色
umoo-cli users set-role <user-id> --role tenant_admin

API 密钥

bash
# 列出 API 密钥
umoo-cli apikeys list

# 生成 API 密钥
umoo-cli apikeys generate --name ci-deploy --role operator --expires 2025-12-31

# 撤销 API 密钥
umoo-cli apikeys revoke <key-id>

事件

bash
# 列出事件
umoo-cli events list
umoo-cli events list --device <device-id> --type device.online
umoo-cli events list --from 2024-01-01 --to 2024-01-31

租户(超级管理员)

bash
# 列出所有租户
umoo-cli tenants list

# 创建租户
umoo-cli tenants create --name "Acme Corp"

# 获取租户详情
umoo-cli tenants get <tenant-id>

证书管理

详见证书管理获取完整的 umoo cert 命令参考。

输出格式

大多数列表命令支持 --output 参数:

bash
umoo-cli devices list --output json    # JSON 数组
umoo-cli devices list --output table   # ASCII 表格(默认)
umoo-cli devices list --output yaml    # YAML

退出码

代码含义
0成功
1一般错误
2认证错误
3权限被拒绝
4资源未找到

示例

跨设备集群部署应用更新

bash
# 创建新应用版本
APP_ID=$(umoo-cli apps list --output json | jq -r '.[] | select(.name=="nginx") | .id')
umoo-cli apps versions create "$APP_ID" --version 1.1.0 --spec '{"image":"nginx:1.25"}'

# 创建并执行滚动发布
ROLLOUT_ID=$(umoo-cli rollouts create \
  --name "nginx-1.1.0" \
  --group prod-fleet-group-id \
  --strategy rolling \
  --batch-size 5 \
  --failure-threshold 10 \
  --target-version "{\"apps\":{\"nginx\":{\"version\":\"1.1.0\"}}}" \
  --output json | jq -r '.id')

umoo-cli rollouts execute "$ROLLOUT_ID"

# 监控进度
watch umoo-cli rollouts get "$ROLLOUT_ID"

为新设备生成认领令牌

bash
TOKEN=$(umoo-cli devices claim-token --group prod-fleet-id --ttl 1h --output json | jq -r '.token')
echo "在设备上运行:umoo-agent --claim-token $TOKEN --server grpc.umoo.yun:8443"

Umoo — IoT Device Management Platform