Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export VERSION=0.1.4
export VERSION=0.1.5

.PHONY : build
build:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ complete -F /usr/local/bin/ucloud ucloud

## Getting Started

Run the command to get started and configure ucloud-cli follow the steps. The public & private keys will be saved automatically and locally.
Run the command to get started and configure ucloud-cli follow the steps. The public & private keys will be saved automatically and locally to directory ~/.ucloud.
You can delete the directory whenever you want.

```
$ ucloud init
Expand Down
3 changes: 3 additions & 0 deletions base/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package base
import (
"github.com/ucloud/ucloud-sdk-go/services/pathx"
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
"github.com/ucloud/ucloud-sdk-go/services/udisk"
"github.com/ucloud/ucloud-sdk-go/services/uhost"
"github.com/ucloud/ucloud-sdk-go/services/ulb"
"github.com/ucloud/ucloud-sdk-go/services/unet"
Expand All @@ -19,6 +20,7 @@ type Client struct {
ulb.ULBClient
vpc.VPCClient
pathx.PathXClient
udisk.UDiskClient
}

// NewClient will return a aggregate client
Expand All @@ -30,5 +32,6 @@ func NewClient(config *ucloud.Config, credential *auth.Credential) *Client {
*ulb.NewClient(config, credential),
*vpc.NewClient(config, credential),
*pathx.NewClient(config, credential),
*udisk.NewClient(config, credential),
}
}
2 changes: 1 addition & 1 deletion base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const configFile = "config.json"

//Version 版本号
const Version = "0.1.4"
const Version = "0.1.5"

//ConfigPath 配置文件路径

Expand Down
66 changes: 66 additions & 0 deletions base/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

sdk "github.com/ucloud/ucloud-sdk-go/ucloud"
uerr "github.com/ucloud/ucloud-sdk-go/ucloud/error"
"github.com/ucloud/ucloud-sdk-go/ucloud/helpers/waiter"
"github.com/ucloud/ucloud-sdk-go/ucloud/log"
"github.com/ucloud/ucloud-sdk-go/ucloud/response"

"github.com/ucloud/ucloud-cli/model"
Expand Down Expand Up @@ -260,3 +262,67 @@ var RegionLabel = map[string]string{
"uk-london": "London",
"afr-nigeria": "Lagos",
}

//Poll 轮询
func Poll(describeFunc func(string, string, string, string) (interface{}, error)) func(string, string, string, string, []string) chan bool {
stateFields := []string{"State", "Status"}
return func(resourceID, projectID, region, zone string, targetState []string) chan bool {
w := waiter.StateWaiter{
Pending: []string{"pending"},
Target: []string{"avaliable"},
Refresh: func() (interface{}, string, error) {
inst, err := describeFunc(resourceID, projectID, region, zone)
if err != nil {
return nil, "", err
}

if inst == nil {
return nil, "pending", nil
}
instValue := reflect.ValueOf(inst)
instValue = reflect.Indirect(instValue)
instType := instValue.Type()
if instValue.Kind() != reflect.Struct {
return nil, "", fmt.Errorf("Instance is not struct")
}
state := ""
for i := 0; i < instValue.NumField(); i++ {
for _, sf := range stateFields {
if instType.Field(i).Name == sf {
state = instValue.Field(i).String()
}
}
}
if state != "" {
for _, t := range targetState {
if t == state {
return inst, "avaliable", nil
}
}
}
return nil, "pending", nil

},
Timeout: 5 * time.Minute,
}

done := make(chan bool)
go func() {
if resp, err := w.Wait(); err != nil {
log.Error(err)
} else {
log.Infof("%#v", resp)
}
done <- true
}()
return done
}
}

//PickResourceID uhost-xxx/uhost-name => uhost-xxx
func PickResourceID(str string) string {
if strings.Index(str, "/") > -1 {
return strings.SplitN(str, "/", 2)[0]
}
return str
}
2 changes: 1 addition & 1 deletion cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewCmdInit() *cobra.Command {
Cxt.Println(err)
return
}
if confirm {
if !confirm {
printHello()
return
}
Expand Down
Loading