Skip to content

Commit 39eb7d8

Browse files
authored
Merge pull request #8 from lixiaojun629/develop
0.1.5
2 parents 879453e + 7ccaae8 commit 39eb7d8

55 files changed

Lines changed: 2277 additions & 376 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

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

33
.PHONY : build
44
build:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ complete -F /usr/local/bin/ucloud ucloud
5757

5858
## Getting Started
5959

60-
Run the command to get started and configure ucloud-cli follow the steps. The public & private keys will be saved automatically and locally.
60+
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.
61+
You can delete the directory whenever you want.
6162

6263
```
6364
$ ucloud init

base/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package base
33
import (
44
"github.com/ucloud/ucloud-sdk-go/services/pathx"
55
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
6+
"github.com/ucloud/ucloud-sdk-go/services/udisk"
67
"github.com/ucloud/ucloud-sdk-go/services/uhost"
78
"github.com/ucloud/ucloud-sdk-go/services/ulb"
89
"github.com/ucloud/ucloud-sdk-go/services/unet"
@@ -19,6 +20,7 @@ type Client struct {
1920
ulb.ULBClient
2021
vpc.VPCClient
2122
pathx.PathXClient
23+
udisk.UDiskClient
2224
}
2325

2426
// NewClient will return a aggregate client
@@ -30,5 +32,6 @@ func NewClient(config *ucloud.Config, credential *auth.Credential) *Client {
3032
*ulb.NewClient(config, credential),
3133
*vpc.NewClient(config, credential),
3234
*pathx.NewClient(config, credential),
35+
*udisk.NewClient(config, credential),
3336
}
3437
}

base/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const configFile = "config.json"
1717

1818
//Version 版本号
19-
const Version = "0.1.4"
19+
const Version = "0.1.5"
2020

2121
//ConfigPath 配置文件路径
2222

base/util.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515

1616
sdk "github.com/ucloud/ucloud-sdk-go/ucloud"
1717
uerr "github.com/ucloud/ucloud-sdk-go/ucloud/error"
18+
"github.com/ucloud/ucloud-sdk-go/ucloud/helpers/waiter"
19+
"github.com/ucloud/ucloud-sdk-go/ucloud/log"
1820
"github.com/ucloud/ucloud-sdk-go/ucloud/response"
1921

2022
"github.com/ucloud/ucloud-cli/model"
@@ -260,3 +262,67 @@ var RegionLabel = map[string]string{
260262
"uk-london": "London",
261263
"afr-nigeria": "Lagos",
262264
}
265+
266+
//Poll 轮询
267+
func Poll(describeFunc func(string, string, string, string) (interface{}, error)) func(string, string, string, string, []string) chan bool {
268+
stateFields := []string{"State", "Status"}
269+
return func(resourceID, projectID, region, zone string, targetState []string) chan bool {
270+
w := waiter.StateWaiter{
271+
Pending: []string{"pending"},
272+
Target: []string{"avaliable"},
273+
Refresh: func() (interface{}, string, error) {
274+
inst, err := describeFunc(resourceID, projectID, region, zone)
275+
if err != nil {
276+
return nil, "", err
277+
}
278+
279+
if inst == nil {
280+
return nil, "pending", nil
281+
}
282+
instValue := reflect.ValueOf(inst)
283+
instValue = reflect.Indirect(instValue)
284+
instType := instValue.Type()
285+
if instValue.Kind() != reflect.Struct {
286+
return nil, "", fmt.Errorf("Instance is not struct")
287+
}
288+
state := ""
289+
for i := 0; i < instValue.NumField(); i++ {
290+
for _, sf := range stateFields {
291+
if instType.Field(i).Name == sf {
292+
state = instValue.Field(i).String()
293+
}
294+
}
295+
}
296+
if state != "" {
297+
for _, t := range targetState {
298+
if t == state {
299+
return inst, "avaliable", nil
300+
}
301+
}
302+
}
303+
return nil, "pending", nil
304+
305+
},
306+
Timeout: 5 * time.Minute,
307+
}
308+
309+
done := make(chan bool)
310+
go func() {
311+
if resp, err := w.Wait(); err != nil {
312+
log.Error(err)
313+
} else {
314+
log.Infof("%#v", resp)
315+
}
316+
done <- true
317+
}()
318+
return done
319+
}
320+
}
321+
322+
//PickResourceID uhost-xxx/uhost-name => uhost-xxx
323+
func PickResourceID(str string) string {
324+
if strings.Index(str, "/") > -1 {
325+
return strings.SplitN(str, "/", 2)[0]
326+
}
327+
return str
328+
}

cmd/configure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewCmdInit() *cobra.Command {
5151
Cxt.Println(err)
5252
return
5353
}
54-
if confirm {
54+
if !confirm {
5555
printHello()
5656
return
5757
}

0 commit comments

Comments
 (0)