Skip to content

Commit b0b8582

Browse files
committed
ucloud 0.1.24
1 parent 029b044 commit b0b8582

10 files changed

Lines changed: 456 additions & 42 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
out
22
.vscode/
3+
.idea/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export VERSION=0.1.23
1+
export VERSION=0.1.24
22

33
.PHONY : install
44
install:

README-CN.md

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
[English](./README.md) | 简体中文
2+
## UCloud CLI
3+
4+
![](./docs/_static/ucloud_cli_demo.gif)
5+
6+
UCloud 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/software/cli/index
7+
8+
## 在macOS或Linux平台安装UCloud-CLI
9+
10+
**通过Homebrew安装(在macOS平台上推荐此方式)**
11+
12+
[Homebrew](https://docs.brew.sh/Installation) 是macOS平台上非常流行的包管理工具,您可以通过如下命令轻松安装或升级UCloud-CLI
13+
14+
安装UCloud-CLI
15+
```
16+
brew install ucloud
17+
```
18+
19+
升级到最新版本
20+
21+
```
22+
brew upgrade ucloud
23+
```
24+
25+
如果安装过程中遇到错误,请先执行如下命令更新Homebrew
26+
27+
```
28+
brew update
29+
```
30+
31+
如果问题依然存在,执行如下命令获取更多帮助
32+
33+
```
34+
brew doctor
35+
```
36+
37+
**基于源代码编译(需要本地安装golang)**
38+
39+
如果您已经安装了git和golang在您的平台上,您可以使用如下命令下载源代码并编译
40+
41+
```
42+
git clone https://github.com/ucloud/ucloud-cli.git
43+
cd ucloud-cli
44+
make install
45+
```
46+
47+
升级到最新版本
48+
```
49+
cd /path/to/ucloud-cli
50+
git pull
51+
make install
52+
```
53+
54+
**下载已编译好的二进制可执行文件(Linux上如果选不到非常方便的安装方式,推荐用此办法安装)**
55+
56+
打开ucloud-cli的[发布页面](https://github.com/ucloud/ucloud-cli/releases),找到适合您平台的ucloud-cli压缩包。点击链接进行下载,下载后,通过比对sha256摘要来检验下载文件未被劫持,然后把ucloud-cli可执行文件解压到$PATH环境变量包含的目录,操作命令如下:
57+
58+
举个例子
59+
```
60+
curl -OL https://github.com/ucloud/ucloud-cli/releases/download/0.1.23/ucloud-cli-linux-0.1.23-amd64.tgz
61+
echo "b480f8621e8d0bd2c121221857029320eb49be708f4d7cb1b197cdc58b071c09 *ucloud-cli-linux-0.1.23-amd64.tgz" | shasum -c //检查下载的tar包是否被劫持,从发布页面获取sha256摘要
62+
tar zxf ucloud-cli-linux-0.1.23-amd64.tgz -C /usr/local/bin/
63+
```
64+
65+
## 在Windows平台上安装UCloud-CLI
66+
67+
**基于源代码编译**
68+
69+
从UCloud-CLI的[发布页面](https://github.com/ucloud/ucloud-cli/releases)下载源代码并解压,您也可以通过git下载源代码,打开Git Bash, 执行命令```git clone https://github.com/ucloud/ucloud-cli.git```
70+
切换到源代码所在的目录,编译源代码(执行命令 ```go build -mod=vendor -o ucloud.exe```),然后把可执行文件ucloud.exe所在目录添加到PATH环境变量中,具体操作可参看[文档](https://www.java.com/en/download/help/path.xml)
71+
配置完成后,打开终端(cmd或power shell),执行命令```ucloud --version```检查是否安装成功。
72+
73+
74+
**下载二进制可执行文件**
75+
76+
打开ucloud-cli的[发布页面](https://github.com/ucloud/ucloud-cli/releases),找到适合您平台的ucloud-cli压缩包。点击链接进行下载并解压,然后把可执行文件ucloud.exe所在目录添加到PATH环境变量中,添加环境变量的操作可参考[文档](https://www.java.com/en/download/help/path.xml)
77+
78+
## 在Docker容器中使用UCloud-CLI
79+
如果您已安装Docker, 通过如下命令拉取已打包UCloud-CLI的镜像。镜像打包[Dockerfile](./Dockerfile)
80+
```
81+
docker pull uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code
82+
```
83+
84+
基于此镜像创建容器
85+
```
86+
docker run --name ucloud-cli -it -d uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code
87+
```
88+
连接到容器,开始使用UCloud-CLI
89+
```
90+
docker exec -it ucloud-cli zsh
91+
```
92+
93+
## 开启命令补全(bash或zsh shell)
94+
95+
UCloud-CLI支持命令自动补全,开启后,您只需要输入命令的部分字符,然后敲击Tab键即可自动补全命令的其余字符。
96+
97+
**Bash shell**
98+
99+
把如下代码添加到文件~/.bash_profile 或 ~/.bashrc中,然后source <~/.bash_profile|~/.bashrc>,或打开一个新终端,命令补全即生效
100+
101+
```
102+
complete -C $(which ucloud) ucloud
103+
```
104+
105+
**Zsh shell**
106+
107+
把如下代码添加到文件~/.zshrc中,然后source ~/.zshrc,或打开一个新终端,命令补全即生效
108+
109+
```
110+
autoload -U +X bashcompinit && bashcompinit
111+
complete -F $(which ucloud) ucloud
112+
```
113+
Zsh内置命令bashcompinit有可能在某些操作系统中不生效,如果以上脚本不生效,尝试用如下脚本替换
114+
```
115+
_ucloud() {
116+
read -l;
117+
local cl="$REPLY";
118+
read -ln;
119+
local cp="$REPLY";
120+
reply=(`COMP_SHELL=zsh COMP_LINE="$cl" COMP_POINT="$cp" ucloud`)
121+
}
122+
123+
compctl -K _ucloud ucloud
124+
```
125+
126+
127+
## 初始化配置
128+
UCloud CLI支持多个命名配置,这些配置存储在本地文件config.json和credential.json中,位于~/.ucloud目录。
129+
您可以使用```ucloud config add ```命令添加多个配置,使用--profile指定配置名称,或者直接在本地文件config.json和credential.json中添加配置。
130+
在本地没有已生效的配置的情况下,```ucloud init```命令会添加一个配置并命名为default,此命令尽可能简化了配置过程,适合第一次使用UCloud CLI的时候初始化配置。
131+
132+
总共有10个配置项
133+
- Profile: 配置名称, 此名称不允许重复。执行命令时可以被参数--profile覆盖
134+
- Active: 标识此配置是否生效,生效的配置只有一个
135+
- ProjectID: 默认项目ID,执行命令时可以被参数--project-id覆盖
136+
- Region: 默认地域,执行命令时可以被参数--region覆盖
137+
- Zone: 默认可用区,执行命令时可以被参数--zone覆盖
138+
- BaseURL: 默认的UCloud Open API地址,执行命令时可以被参数--base-url覆盖
139+
- Timeout: 默认的请求API超时时间,单位秒,执行命令是可以被参数--timeout覆盖
140+
- PublicKey: 账户公钥,执行命令时可以被参数--public-key覆盖
141+
- PrivateKey: 账户私钥,执行命令是可以被参数--private-key覆盖
142+
- MaxRetryTimes: 默认最大的API请求失败重试次数,只对幂等API生效,所谓幂API等是指不会因为多次调用而产生副作用,比如释放EIP(ReleaseEIP),执行命令时可以被参数--max-retry-times覆盖
143+
144+
添加或修改配置的命令如下
145+
146+
首次使用,初始化配置
147+
```
148+
$ ucloud init
149+
```
150+
查看所有配置
151+
```
152+
$ ucloud config list
153+
154+
Profile Active ProjectID Region Zone BaseURL Timeout PublicKey PrivateKey MaxRetryTimes
155+
default true org-oxjwoi cn-bj2 cn-bj2-05 https://api.ucloud.cn/ 15 YSQGIZrL*****nCRQ= jtma2eqQ*****+Avms 3
156+
uweb false org-bdks4e cn-bj2 cn-bj2-05 https://api.ucloud.cn/ 15 4E9UU0Vh*****PWQ== 694581ea*****a0d45 3
157+
```
158+
159+
添加配置
160+
```
161+
$ ucloud config add --profile <new-profie-name> --public-key xxx --private-key xxx
162+
```
163+
164+
修改某个配置的配置项
165+
166+
```
167+
$ ucloud config update --profile xxx --region cn-sh2
168+
```
169+
170+
更多信息,请参考命令帮助
171+
```
172+
$ ucloud config --help
173+
```
174+
175+
## 举例说明
176+
177+
用UCloud CLI在尼日利亚创建数据中心创建一台主机并绑定一个外网IP,然后配置GlobalSSH加速,加速中国大陆到目的主机的SSH登陆
178+
179+
首先,创建云主机
180+
```
181+
$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr
182+
183+
uhost[uhost-zbuxxxx] is initializing...done
184+
```
185+
186+
*备注*
187+
188+
执行以下命令查看创建主机命令的各参数含义
189+
190+
```
191+
$ ucloud uhost create --help
192+
```
193+
194+
其次,申请一个EIP,然后绑定到刚刚创建的主机上
195+
Secondly, we're going to allocate an EIP and then bind it to the uhost created above.
196+
197+
```
198+
$ ucloud eip allocate --bandwidth-mb 1
199+
allocate EIP[eip-xxx] IP:106.75.xx.xx Line:BGP
200+
201+
$ ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx
202+
bind EIP[eip-xxx] with uhost[uhost-xxx]
203+
```
204+
205+
以上操作也可以用一个命令完成
206+
```
207+
$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr --create-eip-bandwidth-mb 1
208+
```
209+
210+
配置GlobalSSH,然后通过GlobalSSH登陆主机
211+
212+
```
213+
$ ucloud gssh create --location Washington --target-ip 152.32.140.92
214+
gssh[uga-0psxxx] created
215+
216+
$ ssh root@152.32.140.92.ipssh.net
217+
root@152.32.140.92.ipssh.net's password: password of the uhost instance
218+
```

README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
English | [简体中文](./README-CN.md)
2+
13
## UCloud CLI
24

35
![](./docs/_static/ucloud_cli_demo.gif)
46

5-
The UCloud CLI provides a unified command line interface to UCloud services. It works on Golang SDK based on UCloud OpenAPI and supports Linux, macOS and Windows.
7+
The UCloud CLI provides a unified command line interface to UCloud services. It works on [ucloud-sdk-go](https://github.com/ucloud/ucloud-sdk-go) based on UCloud OpenAPI and supports Linux, macOS and Windows.
68
https://docs.ucloud.cn/software/cli/index
79

810
## Installing ucloud-cli on macOS or Linux
@@ -54,7 +56,7 @@ make install
5456

5557
**Downloading binary release(Recommended on Linux)**
5658

57-
Vist the [releases page](https://github.com/ucloud/ucloud-cli/releases) of ucloud cli, and find the appropriate archive for your operating system and architecture.
59+
Visit the [releases page](https://github.com/ucloud/ucloud-cli/releases) of ucloud cli, and find the appropriate archive for your operating system and architecture.
5860
Download the archive , check the shasum256 hashcode and extract it to your $PATH
5961

6062
For example
@@ -68,8 +70,8 @@ tar zxf ucloud-cli-linux-0.1.22-amd64.tgz -C /usr/local/bin/
6870

6971
**Building from source**
7072

71-
Download the source code of ucloud cli from [releases page](https://github.com/ucloud/ucloud-cli/releases). You can also download it by running ```git clone https://github.com/ucloud/ucloud-cli.git```
72-
Ensure you have git installed, because go will download packages using git. Go to the directory of the source code, and then compile the source code by running "go build -mod=vendor -o ucloud.exe"
73+
Download the source code of ucloud cli from [releases page](https://github.com/ucloud/ucloud-cli/releases) and extract it. You can also download it by running ```git clone https://github.com/ucloud/ucloud-cli.git```
74+
Go to the directory of the source code, and then compile the source code by running ```go build -mod=vendor -o ucloud.exe```
7375
After that add ucloud.exe to your environment variable PATH. You could follow [this document](https://www.java.com/en/download/help/path.xml) if you don't know how to do.
7476
Open CMD Terminal and run ```ucloud --version ``` to test installation.
7577

@@ -80,7 +82,7 @@ Vist the [releases page](https://github.com/ucloud/ucloud-cli/releases) of uclou
8082
Download the archive , and extract it. Add binary file ucloud.exe to your environment variable PATH following [this document](https://www.java.com/en/download/help/path.xml)
8183

8284
## Using ucloud cli in a Docker container
83-
If you have installed docker on your platform, pull the docker image embeded ucloud cli by follow command. Lookup Dockerfile from [here](./Dockerfile)
85+
If you have installed docker on your platform, pull the docker image embedded ucloud cli by follow command. Lookup Dockerfile from [here](./Dockerfile)
8486
```
8587
docker pull uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code
8688
```
@@ -102,15 +104,15 @@ UCloud CLI also has auto-completion support. It can be set up so that if you par
102104

103105
**Bash shell**
104106

105-
Add following scripts to ~/.bash_profile or ~/.bashrc
107+
Add following scripts to ~/.bash_profile or ~/.bashrc and then restart your terminal or run ```source <~/.bash_profile|~/.bashrc>```
106108

107109
```
108110
complete -C $(which ucloud) ucloud
109111
```
110112

111113
**Zsh shell**
112114

113-
Add following scripts to ~/.zshrc
115+
Add following scripts to ~/.zshrc and then restart your terminal or run ```source ~/.zshrc```
114116

115117
```
116118
autoload -U +X bashcompinit && bashcompinit
@@ -132,17 +134,45 @@ compctl -K _ucloud ucloud
132134

133135
## Setup configuration
134136

135-
Run the command below to get started and configure ucloud-cli. The private key and public key will be saved automatically and locally to directory ~/.ucloud.
136-
You can delete the directory whenever you want.
137+
The UCloud CLI supports using any of multiple named profiles that are stored in config.json and credential.json files which located in ~/.ucloud.
138+
You can configure additional profiles by using ```ucloud config add``` with the --profile flag, or by adding entries to the config.json and credential.json files.
139+
ucloud init will add profile named default if you do not have an active profile, and it does its best to reduce configuration items for first-time use of ucloud-cli.
140+
141+
There are 10 configuration items
142+
143+
- Profile: name of the profile, duplicated names are not allowed. It can be override by --profile flag
144+
- Active: Whether to take effect, Only one profile is active
145+
- ProjectID: ID of default project, and it can be override by --project-id flag
146+
- Region: default region, it can be override by --region flag
147+
- Zone: default zone, it can be override by --zone flag
148+
- BaseURL: default url of UCloud Open API, it can be override by --base-url flag
149+
- Timeout: default timeout value of querying UCloud Open API, unit second. It can be override by --timeout flag
150+
- PublicKey: public key of your account. It can be override by --public-key flag
151+
- PrivateKey: private key of your account. It can be override by --private-key flag
152+
- MaxRetryTimes: default max retry times for failed API request. It only works for idempotent APIs which can be called many times without side effect, for example 'ReleaseEIP', and it can be override by --max-retry-times flag
137153

154+
Run the command below to get started and configure ucloud-cli.
138155
```
139156
$ ucloud init
140157
```
158+
List all profiles (for example)
159+
```
160+
$ ucloud config list
141161
142-
To reset the configurations, run:
162+
Profile Active ProjectID Region Zone BaseURL Timeout PublicKey PrivateKey MaxRetryTimes
163+
default true org-oxjwoi cn-bj2 cn-bj2-05 https://api.ucloud.cn/ 15 YSQGIZrL*****nCRQ= jtma2eqQ*****+Avms 3
164+
uweb false org-bdks4e cn-bj2 cn-bj2-05 https://api.ucloud.cn/ 15 4E9UU0Vh*****PWQ== 694581ea*****a0d45 3
165+
```
143166

167+
Add additional profiles
144168
```
145-
$ ucloud config
169+
$ ucloud config add --profile <new-profie-name> --public-key xxx --private-key xxx
170+
```
171+
172+
To change configuration items of specified profile, run:
173+
174+
```
175+
$ ucloud config update --profile xxx --region cn-sh2
146176
```
147177

148178
For more information, run:
@@ -158,7 +188,7 @@ I want to create a uhost in Nigeria (region: air-nigeria) and bind a public IP,
158188
Firstly, create an uhost instance:
159189

160190
```
161-
$ ucloud uhost create --cpu 1 --memory 1 --password **** --image-id uimage-fya3qr
191+
$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr
162192
163193
uhost[uhost-zbuxxxx] is initializing...done
164194
```
@@ -174,13 +204,18 @@ $ ucloud uhost create --help
174204
Secondly, we're going to allocate an EIP and then bind it to the uhost created above.
175205

176206
```
177-
$ ucloud eip allocate --line International --bandwidth-mb 1
207+
$ ucloud eip allocate --bandwidth-mb 1
178208
allocate EIP[eip-xxx] IP:106.75.xx.xx Line:BGP
179209
180210
$ ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx
181211
bind EIP[eip-xxx] with uhost[uhost-xxx]
182212
```
183213

214+
The operations above also can be done by one command
215+
```
216+
$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr --create-eip-bandwidth-mb 1
217+
```
218+
184219
Configure the GlobalSSH to the uhost instance and login the instance via GlobalSSH
185220

186221
```

0 commit comments

Comments
 (0)