{"id":21518169,"url":"https://github.com/ucloud/ucloud-cli","last_synced_at":"2025-03-22T18:05:58.021Z","repository":{"id":34264046,"uuid":"146746377","full_name":"ucloud/ucloud-cli","owner":"ucloud","description":"UCloud Command Line Interface","archived":false,"fork":false,"pushed_at":"2024-09-20T06:38:25.000Z","size":8646,"stargazers_count":98,"open_issues_count":2,"forks_count":43,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-14T19:15:00.401Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ucloud.png","metadata":{"files":{"readme":"README-CN.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-30T12:28:56.000Z","updated_at":"2024-09-20T06:35:18.000Z","dependencies_parsed_at":"2023-01-15T05:46:21.712Z","dependency_job_id":"bcf48e71-1260-40fe-9bad-010ce700c30c","html_url":"https://github.com/ucloud/ucloud-cli","commit_stats":null,"previous_names":[],"tags_count":51,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fucloud-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fucloud-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fucloud-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ucloud%2Fucloud-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ucloud","download_url":"https://codeload.github.com/ucloud/ucloud-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244999386,"owners_count":20544871,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T00:50:24.542Z","updated_at":"2025-03-22T18:05:57.998Z","avatar_url":"https://github.com/ucloud.png","language":"Go","readme":"[English](./README.md) | 简体中文\n##  UCloud CLI \n\n![](./docs/_static/ucloud_cli_demo.gif)\n\nUCloud CLI为管理UCloud平台上的资源和服务提供了一致性的操作接口，它使用[ucloud-sdk-go](https://github.com/ucloud/ucloud-sdk-go)调用[UCloud OpenAPI](https://docs.ucloud.cn/api/summary/overview)，从而实现对资源和服务的操作，兼容Linux, macOS和Windows平台 https://docs.ucloud.cn/developer/cli/index\n\n## 在macOS或Linux平台安装UCloud-CLI\n\n**通过Homebrew安装(在macOS平台上推荐此方式)**\n\n[Homebrew](https://docs.brew.sh/Installation) 是macOS平台上非常流行的包管理工具，您可以通过如下命令轻松安装或升级UCloud-CLI\n\n安装UCloud-CLI\n```\nbrew install ucloud\n```\n\n升级到最新版本\n\n```\nbrew upgrade ucloud\n```\n\n如果安装过程中遇到错误，请先执行如下命令更新Homebrew\n\n```\nbrew update\n```\n\n如果问题依然存在，执行如下命令获取更多帮助\n\n```\nbrew doctor\n```\n\n**基于源代码编译(需要本地安装golang)**\n\n如果您已经安装了git和golang在您的平台上，您可以使用如下命令下载源代码并编译\n\n```\ngit clone https://github.com/ucloud/ucloud-cli.git\ncd ucloud-cli\nmake install\n```\n\n升级到最新版本\n```\ncd /path/to/ucloud-cli\ngit pull\nmake install\n```\n\n**下载已编译好的二进制可执行文件(Linux上如果选不到非常方便的安装方式，推荐用此办法安装)**\n\n打开ucloud-cli的[发布页面](https://github.com/ucloud/ucloud-cli/releases)，找到适合您平台的ucloud-cli压缩包。点击链接进行下载，下载后，通过比对sha256摘要来检验下载文件未被劫持，然后把ucloud-cli可执行文件解压到$PATH环境变量包含的目录，操作命令如下：\n\n举个例子\n```\ncurl -OL https://github.com/ucloud/ucloud-cli/releases/download/0.1.23/ucloud-cli-linux-0.1.23-amd64.tgz\necho \"b480f8621e8d0bd2c121221857029320eb49be708f4d7cb1b197cdc58b071c09 *ucloud-cli-linux-0.1.23-amd64.tgz\" | shasum -c //检查下载的tar包是否被劫持，从发布页面获取sha256摘要\ntar zxf ucloud-cli-linux-0.1.23-amd64.tgz -C /usr/local/bin/\n```\n\n## 在Windows平台上安装UCloud-CLI\n\n**基于源代码编译**\n\n从UCloud-CLI的[发布页面](https://github.com/ucloud/ucloud-cli/releases)下载源代码并解压，您也可以通过git下载源代码，打开Git Bash， 执行命令```git clone https://github.com/ucloud/ucloud-cli.git```。\n切换到源代码所在的目录，编译源代码（执行命令 ```go build -mod=vendor -o ucloud.exe```），然后把可执行文件ucloud.exe所在目录添加到PATH环境变量中，具体操作可参看[文档](https://www.java.com/en/download/help/path.xml)\n配置完成后，打开终端（cmd或power shell），执行命令```ucloud --version```检查是否安装成功。\n\n\n**下载二进制可执行文件**\n\n打开ucloud-cli的[发布页面](https://github.com/ucloud/ucloud-cli/releases)，找到适合您平台的ucloud-cli压缩包。点击链接进行下载并解压，然后把可执行文件ucloud.exe所在目录添加到PATH环境变量中，添加环境变量的操作可参考[文档](https://www.java.com/en/download/help/path.xml)\n\n## 在Docker容器中使用UCloud-CLI\n如果您已安装Docker, 通过如下命令拉取已打包UCloud-CLI的镜像。镜像打包[Dockerfile](./Dockerfile)\n```\ndocker pull uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code\n```\n\n基于此镜像创建容器\n```\ndocker run --name ucloud-cli -it -d uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code\n```\n连接到容器，开始使用UCloud-CLI\n```\ndocker exec -it ucloud-cli zsh\n```\n\n## 开启命令补全（bash或zsh shell）\n\nUCloud-CLI支持命令自动补全，开启后，您只需要输入命令的部分字符，然后敲击Tab键即可自动补全命令的其余字符。\n\n**Bash shell** \n\n把如下代码添加到文件~/.bash_profile 或 ~/.bashrc中，然后source \u003c~/.bash_profile|~/.bashrc\u003e，或打开一个新终端，命令补全即生效\n\n```\ncomplete -C $(which ucloud) ucloud\n```\n\n**Zsh shell** \n\n把如下代码添加到文件~/.zshrc中，然后source ~/.zshrc，或打开一个新终端，命令补全即生效\n\n```\nautoload -U +X bashcompinit \u0026\u0026 bashcompinit\ncomplete -F $(which ucloud) ucloud\n```\nZsh内置命令bashcompinit有可能在某些操作系统中不生效，如果以上脚本不生效，尝试用如下脚本替换\n```\n_ucloud() {\n        read -l;\n        local cl=\"$REPLY\";\n        read -ln;\n        local cp=\"$REPLY\";\n        reply=(`COMP_SHELL=zsh COMP_LINE=\"$cl\" COMP_POINT=\"$cp\" ucloud`)\n}\n\ncompctl -K _ucloud ucloud\n```\n\n\n## 初始化配置\nUCloud CLI支持多个命名配置，这些配置存储在本地文件config.json和credential.json中，位于~/.ucloud目录。\n您可以使用```ucloud config add ```命令添加多个配置，使用--profile指定配置名称，或者直接在本地文件config.json和credential.json中添加配置。\n在本地没有已生效的配置的情况下，```ucloud init```命令会添加一个配置并命名为default，此命令尽可能简化了配置过程，适合第一次使用UCloud CLI的时候初始化配置。\n\n总共有10个配置项\n- Profile: 配置名称, 此名称不允许重复。执行命令时可以被参数--profile覆盖\n- Active: 标识此配置是否生效，生效的配置只有一个\n- ProjectID: 默认项目ID，执行命令时可以被参数--project-id覆盖\n- Region: 默认地域，执行命令时可以被参数--region覆盖\n- Zone: 默认可用区，执行命令时可以被参数--zone覆盖\n- BaseURL: 默认的UCloud Open API地址，执行命令时可以被参数--base-url覆盖\n- Timeout: 默认的请求API超时时间，单位秒，执行命令是可以被参数--timeout覆盖\n- PublicKey: 账户公钥，执行命令时可以被参数--public-key覆盖\n- PrivateKey: 账户私钥，执行命令是可以被参数--private-key覆盖\n- MaxRetryTimes: 默认最大的API请求失败重试次数，只对幂等API生效，所谓幂API等是指不会因为多次调用而产生副作用，比如释放EIP(ReleaseEIP)，执行命令时可以被参数--max-retry-times覆盖\n\n添加或修改配置的命令如下\n\n首次使用，初始化配置\n```\n$ ucloud init\n```\n查看所有配置\n```\n$ ucloud config list\n\nProfile  Active  ProjectID   Region  Zone       BaseURL                 Timeout  PublicKey           PrivateKey          MaxRetryTimes\ndefault  true    org-oxjwoi  cn-bj2  cn-bj2-05  https://api.ucloud.cn/  15       YSQGIZrL*****nCRQ=  jtma2eqQ*****+Avms  3\nuweb     false   org-bdks4e  cn-bj2  cn-bj2-05  https://api.ucloud.cn/  15       4E9UU0Vh*****PWQ==  694581ea*****a0d45  3\n```\n\n添加配置\n```\n$ ucloud config add --profile \u003cnew-profie-name\u003e  --public-key xxx --private-key xxx\n```\n\n修改某个配置的配置项\n\n```\n$ ucloud config update --profile xxx --region cn-sh2\n```\n\n更多信息，请参考命令帮助\n```\n$ ucloud config --help\n```\n\n## 举例说明\n\n用UCloud CLI在尼日利亚创建数据中心创建一台主机并绑定一个外网IP，然后配置GlobalSSH加速，加速中国大陆到目的主机的SSH登陆\n\n首先，创建云主机\n```\n$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr\n\nuhost[uhost-zbuxxxx] is initializing...done\n```\n\n*备注* \n\n执行以下命令查看创建主机命令的各参数含义\n\n```\n$ ucloud uhost create --help\n```\n\n其次，申请一个EIP，然后绑定到刚刚创建的主机上\nSecondly, we're going to allocate an EIP and then bind it to the uhost created above.\n\n```\n$ ucloud eip allocate --bandwidth-mb 1\nallocate EIP[eip-xxx] IP:106.75.xx.xx  Line:BGP\n\n$ ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx\nbind EIP[eip-xxx] with uhost[uhost-xxx]\n```\n\n以上操作也可以用一个命令完成\n```\n$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr --create-eip-bandwidth-mb 1\n```\n\n配置GlobalSSH，然后通过GlobalSSH登陆主机\n\n```\n$ ucloud gssh create --location Washington --target-ip 152.32.140.92\ngssh[uga-0psxxx] created\n\n$ ssh root@152.32.140.92.ipssh.net\nroot@152.32.140.92.ipssh.net's password: password of the uhost instance\n```\n\n使用\"ucloud api\"命令调用任意API，根据API文档把某个API的参数依次填入。此命令比较特殊，不支持--public-key,--private-key,--debug,--profile,--timeout-sec等公共参数，如果要开启debug模式，可以设置环境变量$UCLOUD_CLI_DEBUG=on\n\n```\n$ ucloud api --Action \u003cAPIName\u003e  --Param1 \u003cvalue\u003e --Param2 \u003cvalue\u003e ...\n```\n或者把API参数写到JSON文件中，举例如下\n```\n$ ucloud api --local-file ./create_uhost.json\n\n//create_uhost.json文件内容\n{\n    \"Action\":\"CreateUHostInstance\",\n    \"Region\":\"cn-bj2\",\n    \"Zone\":\"cn-bj2-02\",\n    \"ImageId\":\"uimage-gk2x3x\",\n    \"NetworkInterface\": [{\n        \"EIP\":{\n            \"Bandwidth\":1,\n            \"OperatorName\":\"Bgp\",\n            \"PayMode\": \"Bandwidth\"\n        }\n    }],\n    \"LoginMode\":\"Password\",\n    \"Password\":\"dGVzdGx4ajEy\",\n    \"CPU\":1,\n    \"Memory\":2048,\n    \"Disks\":[\n        {\n            \"Size\":20,\n            \"Type\":\"LOCAL_NORMAL\",\n            \"IsBoot\":\"true\"\n        }\n    ]\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fucloud-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fucloud%2Fucloud-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fucloud%2Fucloud-cli/lists"}