• Stars
    star
    98
  • Rank 345,882 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UCloud Command Line Interface

English | 简体中文

UCloud CLI

The UCloud CLI provides a unified command line interface to UCloud services. It works on ucloud-sdk-go based on UCloud OpenAPI and supports Linux, macOS and Windows. https://docs.ucloud.cn/developer/cli/index

Installing ucloud-cli on macOS or Linux

Using Homebrew(Recommended on macOS)

The Homebrew package manager may be used on macOS and Linux. It could install ucloud-cli and its dependencies automatically by running command below.

brew install ucloud

If you have installed ucloud-cli already and want to upgrade to the latest version, just run:

brew upgrade ucloud

If you come across some errors during the installation via homebrew, please update the homebrew first and try again.

brew update

If the error is still unresolved, try the following command for help.

brew doctor

Building from source(Recommended if you have golang installed)

If you have installed git and golang on your platform, you can fetch the source code of ucloud cli from github and complie it by yourself.

git clone https://github.com/ucloud/ucloud-cli.git
cd ucloud-cli
make install

Upgrade to latest version

cd ucloud-cli
git pull
make install

Downloading binary release(Recommended on Linux)

Visit the releases page of ucloud cli, and find the appropriate archive for your operating system and architecture. Download the archive , check the shasum256 hashcode and extract it to your $PATH

For example

curl -OL https://github.com/ucloud/ucloud-cli/releases/download/0.1.22/ucloud-cli-linux-0.1.22-amd64.tgz
echo "efbfb6d36d99f692b1f9cc7c9e3858047bb7b4fca6205c454098267e660b41d9 *ucloud-cli-linux-0.1.22-amd64.tgz" | shasum -c //check shasum to verify whether the downloaded tarball was hijacked. get the shasum from release page
tar zxf ucloud-cli-linux-0.1.22-amd64.tgz -C /usr/local/bin/

Installing ucloud cli on Windows

Building from source

Download the source code of ucloud cli from releases page and extract it. You can also download it by running git clone https://github.com/ucloud/ucloud-cli.git Go to the directory of the source code, and then compile the source code by running go build -mod=vendor -o ucloud.exe After that add ucloud.exe to your environment variable PATH. You could follow this document if you don't know how to do. Open CMD Terminal and run ucloud --version to test installation.

Downloading binary release

Vist the releases page of ucloud cli, and find the appropriate archive for your operating system and architecture. Download the archive , and extract it. Add binary file ucloud.exe to your environment variable PATH following this document

Using ucloud cli in a Docker container

If you have installed docker on your platform, pull the docker image embedded ucloud cli by follow command. Lookup Dockerfile from here

docker pull uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code

Create a docker container named ucloud-cli using the docker image your have pulled by following command.

docker run --name ucloud-cli -it -d uhub.service.ucloud.cn/ucloudcli/ucloud-cli:source-code

Run bash command in ucloud-cli container, and then you could play with ucloud cli.

docker exec -it ucloud-cli zsh

Enabling Shell Auto-Completion for bash or zsh shell user.

UCloud CLI also has auto-completion support. It can be set up so that if you partially type a command and then press TAB, the rest of the command is automatically filled in.

Bash shell

Add following scripts to ~/.bash_profile or ~/.bashrc and then restart your terminal or run source <~/.bash_profile|~/.bashrc>

complete -C $(which ucloud) ucloud

Zsh shell

Add following scripts to ~/.zshrc and then restart your terminal or run source ~/.zshrc

autoload -U +X bashcompinit && bashcompinit
complete -F $(which ucloud) ucloud

Zsh builtin command bashcompinit may not work on some platform. If the scripts don't work on your OS, try following scripts

_ucloud() {
        read -l;
        local cl="$REPLY";
        read -ln;
        local cp="$REPLY";
        reply=(`COMP_SHELL=zsh COMP_LINE="$cl" COMP_POINT="$cp" ucloud`)
}

compctl -K _ucloud ucloud

Setup configuration

The UCloud CLI supports using any of multiple named profiles that are stored in config.json and credential.json files which located in ~/.ucloud. 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. 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.

There are 10 configuration items

  • Profile: name of the profile, duplicated names are not allowed. It can be override by --profile flag
  • Active: Whether to take effect, Only one profile is active
  • ProjectID: ID of default project, and it can be override by --project-id flag
  • Region: default region, it can be override by --region flag
  • Zone: default zone, it can be override by --zone flag
  • BaseURL: default url of UCloud Open API, it can be override by --base-url flag
  • Timeout: default timeout value of querying UCloud Open API, unit second. It can be override by --timeout flag
  • PublicKey: public key of your account. It can be override by --public-key flag
  • PrivateKey: private key of your account. It can be override by --private-key flag
  • 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

Run the command below to get started and configure ucloud-cli.

$ ucloud init

List all profiles (for example)

$ ucloud config list

Profile  Active  ProjectID   Region  Zone       BaseURL                 Timeout  PublicKey           PrivateKey          MaxRetryTimes
default  true    org-oxjwoi  cn-bj2  cn-bj2-05  https://api.ucloud.cn/  15       YSQGIZrL*****nCRQ=  jtma2eqQ*****+Avms  3
uweb     false   org-bdks4e  cn-bj2  cn-bj2-05  https://api.ucloud.cn/  15       4E9UU0Vh*****PWQ==  694581ea*****a0d45  3

Add additional profiles

$ ucloud config add --profile <new-profie-name>  --public-key xxx --private-key xxx

To change configuration items of specified profile, run:

$ ucloud config update --profile xxx --region cn-sh2

For more information, run:

$ ucloud config --help

For example

I want to create a uhost in Nigeria (region: air-nigeria) and bind a public IP, and then configure GlobalSSH to accelerate efficiency of SSH service beyond China mainland.

Firstly, create an uhost instance:

$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr

uhost[uhost-zbuxxxx] is initializing...done

Note

Run command below to get details about the parameters of creating new uhost instance.

$ ucloud uhost create --help

Secondly, we're going to allocate an EIP and then bind it to the uhost created above.

$ ucloud eip allocate --bandwidth-mb 1
allocate EIP[eip-xxx] IP:106.75.xx.xx  Line:BGP

$ ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx
bind EIP[eip-xxx] with uhost[uhost-xxx]

The operations above also can be done by one command

$ ucloud uhost create --cpu 1 --memory-gb 1 --password **** --image-id uimage-fya3qr --create-eip-bandwidth-mb 1

Configure the GlobalSSH to the uhost instance and login the instance via GlobalSSH

$ ucloud gssh create --location Washington --target-ip 152.32.140.92
gssh[uga-0psxxx] created

$ ssh [email protected]
[email protected]'s password: password of the uhost instance

Using command "ucloud api" to call any API.Fill in the parameters of an API in sequence according to the API documentation. This command is quite special, and public parameters such as --public-key,--private-key,--debug,--profile,--timeout-sec are not supported. If you want to tune on debug mode, set environment variable $UCLOUD_CLI_DEBUG=on

$ ucloud api --Action <APIName>  --Param1 <value> --Param2 <value> ...

You can also put those API parameters into a json file, like this.

$ ucloud api --local-file ./create_uhost.json

//content of file create_uhost.json
{
    "Action":"CreateUHostInstance",
    "Region":"cn-bj2",
    "Zone":"cn-bj2-02",
    "ImageId":"uimage-gk2x3x",
    "NetworkInterface": [{
        "EIP":{
            "Bandwidth":1,
            "OperatorName":"Bgp",
            "PayMode": "Bandwidth"
        }
    }],
    "LoginMode":"Password",
    "Password":"dGVzdGx4ajEy",
    "CPU":1,
    "Memory":2048,
    "Disks":[
        {
            "Size":20,
            "Type":"LOCAL_NORMAL",
            "IsBoot":"true"
        }
    ]
}

More Repositories

1

redis-cluster-operator

Redis Cluster Operator creates and manages Redis Clusters atop Kubernetes.
Go
381
star
2

redis-operator

Redis operator build a Highly Available Redis cluster with Sentinel atop Kubernetes
Go
214
star
3

ucloud-sdk-go

UCloud SDK for Golang
Go
83
star
4

terraform-provider-ucloud

Terraform is an awesome tool to implement Infrastructure as Code and GitOps
Go
68
star
5

netanalysis-sdk-android

UCloud NetAnalysis SDK for Android
Java
42
star
6

ucloud-sdk-python3

UCloud SDK for Python
Python
37
star
7

uai-sdk

UCloud AI SDK
Python
33
star
8

ufile-sdk-java

UCloud 对象存储官方 SDK
Java
29
star
9

netanalysis-sdk-ios

UCloud NetAnalysis SDK for iOS
Objective-C
28
star
10

ucloud-sdk-python

[DEPRICATED] python sdk for ucloud api
Python
27
star
11

ucloud-toa

A kernel module to obtain source IPv4 address in the TCP option section.
C
21
star
12

ufile-sdk-python

This is an UFile(OSS) SDK for Python from UCloud
Python
20
star
13

ucloud-sdk-java

UCloud SDK for Java
Java
19
star
14

ucloud-sdk-python2

Python
18
star
15

urtc-android-demo

urtc android 端demo
Java
14
star
16

terraform-provider-ucloud-old

(Deprecated) Please see official repository https://github.com/terraform-providers/terraform-provider-ucloud
Go
12
star
17

urtc-sdk-web

URTC(UCloud实时音视频)web SDK
11
star
18

docker-machine-ucloud

docker machine driver for UCloud
Go
10
star
19

ucloud-developer-tools

The landscape of UCloud Developer Tools
9
star
20

ufile-sdk-ios

UCloud 对象存储官方 SDK
Objective-C
8
star
21

ucloud-sdk-php

UCloud SDK for PHP
PHP
8
star
22

urtc-js-demo

urtc js 端demo,demo网址:https://demo.urtc.com.cn/
JavaScript
7
star
23

ufile-sdk-android

UCloud 对象存储官方 SDK
Java
7
star
24

urtc-ios-demo

urtc ios 端demo
HTML
7
star
25

ucloud-iot-rtthread-package

基于RT-Thread操作系统用于快速连接uiot-core的软件包
C
6
star
26

mutualaid

JavaScript
6
star
27

packer-plugin-ucloud

Packer plugin for UCloud Image Builder
Go
6
star
28

ucloud-iot-device-sdk-c

UCloud UIoT-Core设备端C-SDK
C
5
star
29

uk8s-cni-vpc

The underlay container networking plugin for UK8S based on UVPC.
Go
5
star
30

uai-saas-sdk

UCloud AI SaaS SDK
Python
4
star
31

ufile-sdk-auth-server

Java
4
star
32

pulumi-ucloud

Pulumi is a cloud-native development kit to implement Infrastructure as Software
Python
4
star
33

stepflow-stepo

UCloud StepFlow function template
Python
4
star
34

uk8s-demo

3
star
35

urtc-electron-demo

urtc electron demo
C++
3
star
36

uma

JavaScript
3
star
37

urtc-web-demo

JavaScript
3
star
38

ugc-sdk

sdk for ucloud ugc
C++
2
star
39

urtc-win-demo

urtc windows 端demo
C++
2
star
40

urtc-linux-demo

C++
2
star
41

httpdns-sdk-android

Java
1
star
42

ucloud-developer-examples

The examples for developer
Go
1
star
43

ubox-auto-sdk-web

Web SDK for use ubox auto
TypeScript
1
star
44

umon_webhook

HTML
1
star
45

uiotedge-driver-sdk-c

C
1
star
46

uphone-android-sdk

1
star
47

uai-sdk-httpserver

Http Server designed for UAI-SDK task based on Flask
Python
1
star
48

urtc-mac-demo

HTML
1
star
49

ularm-monitor-subscribe-demo

Go
1
star
50

urtc-edu-demo

JavaScript
1
star
51

ubox-publisher

RTMP stream publisher with hardware accel
C
1
star
52

unvs-android-sdk

Java
1
star
53

iotstack-driver-sdk-c

C
1
star
54

go-lockfile

A Linux go library to lock cooperating processes based on syscall `flock`
Go
1
star
55

ucloud-sdk-python-3.0

ucloud-sdk-python-3.0
Python
1
star
56

ucloud-sdk-js

UCloud SDK for Node.js
TypeScript
1
star