Skip to content

Commit 5024d91

Browse files
authored
fix uhost state refreshing (#90)
* fix uhost state refreshing * fix regexp of renaming check
1 parent af20f46 commit 5024d91

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

cmd/uhost.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func NewCmdUHostCreate() *cobra.Command {
415415
wg := &sync.WaitGroup{}
416416
tokens := make(chan struct{}, concurrent)
417417
wg.Add(count)
418-
batchRename, err := regexp.Match(`[%d,%d]`, []byte(*req.Name))
418+
batchRename, err := regexp.Match(`\[\d+,\d+\]`, []byte(*req.Name))
419419
if err != nil || !batchRename {
420420
batchRename = false
421421
}
@@ -610,6 +610,11 @@ func createUhostWrapper(req *uhost.CreateUHostInstanceRequest, updateEIPReq *une
610610
}
611611

612612
func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updateEIPReq *unet.UpdateEIPAttributeRequest, bindEipIDs []string, async bool) (bool, []string) {
613+
if req.MaxCount == nil {
614+
req.MaxCount = sdk.Int(1)
615+
}
616+
req.MaxCount = sdk.Int(count)
617+
613618
resp, err := base.BizClient.CreateUHostInstance(req)
614619
block := ux.NewBlock()
615620
ux.Doc.Append(block)
@@ -626,15 +631,15 @@ func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updat
626631
}
627632

628633
logs = append(logs, fmt.Sprintf("resp:%#v", resp))
629-
if req.MaxCount == nil {
630-
req.MaxCount = sdk.Int(1)
631-
}
632-
req.MaxCount = sdk.Int(count)
634+
633635
if len(resp.UHostIds) != *req.MaxCount {
634636
block.Append(fmt.Sprintf("expect uhost count %d, accept %d", count, len(resp.UHostIds)))
635637
return false, logs
636638
}
637639
for i, uhostID := range resp.UHostIds {
640+
block = ux.NewBlock()
641+
ux.Doc.Append(block)
642+
638643
text := fmt.Sprintf("the uhost[%s]", uhostID)
639644
if len(req.Disks) > 1 {
640645
text = fmt.Sprintf("%s which attached a data disk", text)
@@ -649,9 +654,13 @@ func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updat
649654
if async {
650655
block.Append(text)
651656
} else {
652-
uhostSpoller.Sspoll(resp.UHostIds[0], text, []string{status.HOST_RUNNING, status.HOST_FAIL}, block, &req.CommonBase)
657+
uhostSpoller.Sspoll(uhostID, text, []string{status.HOST_RUNNING, status.HOST_FAIL}, block, &req.CommonBase)
658+
}
659+
bindEipID := ""
660+
if len(bindEipIDs) > i {
661+
bindEipID = bindEipIDs[i]
653662
}
654-
bindEipID := bindEipIDs[i]
663+
655664
if bindEipID != "" {
656665
eip := base.PickResourceID(bindEipID)
657666
logs = append(logs, fmt.Sprintf("bind eip: %s", eip))

0 commit comments

Comments
 (0)