Skip to content

Commit

Permalink
fix uhost state refreshing (#90)
Browse files Browse the repository at this point in the history
* fix uhost state refreshing

* fix regexp of renaming check
  • Loading branch information
wangrzneu authored Sep 20, 2024
1 parent af20f46 commit 5024d91
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions cmd/uhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func NewCmdUHostCreate() *cobra.Command {
wg := &sync.WaitGroup{}
tokens := make(chan struct{}, concurrent)
wg.Add(count)
batchRename, err := regexp.Match(`[%d,%d]`, []byte(*req.Name))
batchRename, err := regexp.Match(`\[\d+,\d+\]`, []byte(*req.Name))
if err != nil || !batchRename {
batchRename = false
}
Expand Down Expand Up @@ -610,6 +610,11 @@ func createUhostWrapper(req *uhost.CreateUHostInstanceRequest, updateEIPReq *une
}

func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updateEIPReq *unet.UpdateEIPAttributeRequest, bindEipIDs []string, async bool) (bool, []string) {
if req.MaxCount == nil {
req.MaxCount = sdk.Int(1)
}
req.MaxCount = sdk.Int(count)

resp, err := base.BizClient.CreateUHostInstance(req)
block := ux.NewBlock()
ux.Doc.Append(block)
Expand All @@ -626,15 +631,15 @@ func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updat
}

logs = append(logs, fmt.Sprintf("resp:%#v", resp))
if req.MaxCount == nil {
req.MaxCount = sdk.Int(1)
}
req.MaxCount = sdk.Int(count)

if len(resp.UHostIds) != *req.MaxCount {
block.Append(fmt.Sprintf("expect uhost count %d, accept %d", count, len(resp.UHostIds)))
return false, logs
}
for i, uhostID := range resp.UHostIds {
block = ux.NewBlock()
ux.Doc.Append(block)

text := fmt.Sprintf("the uhost[%s]", uhostID)
if len(req.Disks) > 1 {
text = fmt.Sprintf("%s which attached a data disk", text)
Expand All @@ -649,9 +654,13 @@ func createMultipleUhost(req *uhost.CreateUHostInstanceRequest, count int, updat
if async {
block.Append(text)
} else {
uhostSpoller.Sspoll(resp.UHostIds[0], text, []string{status.HOST_RUNNING, status.HOST_FAIL}, block, &req.CommonBase)
uhostSpoller.Sspoll(uhostID, text, []string{status.HOST_RUNNING, status.HOST_FAIL}, block, &req.CommonBase)
}
bindEipID := ""
if len(bindEipIDs) > i {
bindEipID = bindEipIDs[i]
}
bindEipID := bindEipIDs[i]

if bindEipID != "" {
eip := base.PickResourceID(bindEipID)
logs = append(logs, fmt.Sprintf("bind eip: %s", eip))
Expand Down

0 comments on commit 5024d91

Please sign in to comment.