@@ -38,7 +38,7 @@ import (
3838
3939var uhostSpoller = base .NewSpoller (sdescribeUHostByID , base .Cxt .GetWriter ())
4040
41- //NewCmdUHost ucloud uhost
41+ // NewCmdUHost ucloud uhost
4242func NewCmdUHost () * cobra.Command {
4343 cmd := & cobra.Command {
4444 Use : "uhost" ,
@@ -65,7 +65,7 @@ func NewCmdUHost() *cobra.Command {
6565 return cmd
6666}
6767
68- //UHostRow UHost表格行
68+ // UHostRow UHost表格行
6969type UHostRow struct {
7070 UHostName string
7171 Remark string
@@ -209,7 +209,7 @@ func getAllUHosts(req *uhost.DescribeUHostInstanceRequest, pageOff bool, allRegi
209209 return uhosts , nil
210210}
211211
212- //NewCmdUHostList [ucloud uhost list]
212+ // NewCmdUHostList [ucloud uhost list]
213213func NewCmdUHostList (out io.Writer ) * cobra.Command {
214214 var allRegion , pageOff , idOnly bool
215215 var output string
@@ -281,12 +281,13 @@ func NewCmdUHostList(out io.Writer) *cobra.Command {
281281 return cmd
282282}
283283
284- //NewCmdUHostCreate [ucloud uhost create]
284+ // NewCmdUHostCreate [ucloud uhost create]
285285func NewCmdUHostCreate () * cobra.Command {
286286 var bindEipIDs []string
287287 var hotPlug string
288288 var async bool
289289 var count int
290+ var concurrent int
290291 var hotPlugImageFlag bool
291292 var userData string
292293 var userDataImageFlag bool
@@ -309,6 +310,10 @@ func NewCmdUHostCreate() *cobra.Command {
309310 return fmt .Errorf ("%q must be base64-encoded" , "user-data-base64" )
310311 }
311312 }
313+
314+ if concurrent > 50 {
315+ return fmt .Errorf ("%q should not be more than 50, current value is %v" , "concurrent" , concurrent )
316+ }
312317 return nil
313318 },
314319
@@ -364,7 +369,8 @@ func NewCmdUHostCreate() *cobra.Command {
364369 }
365370
366371 wg := & sync.WaitGroup {}
367- tokens := make (chan struct {}, 20 )
372+ fmt .Println (concurrent )
373+ tokens := make (chan struct {}, concurrent )
368374 wg .Add (count )
369375 if count <= 5 {
370376 for i := 0 ; i < count ; i ++ {
@@ -439,6 +445,7 @@ func NewCmdUHostCreate() *cobra.Command {
439445 req .ImageId = flags .String ("image-id" , "" , "Required. The ID of image. see 'ucloud image list'" )
440446 flags .BoolVar (& async , "async" , false , "Optional. Do not wait for the long-running operation to finish." )
441447 flags .IntVar (& count , "count" , 1 , "Optional. Number of uhost to create." )
448+ flags .IntVar (& concurrent , "concurrent" , 20 , "Optional. The count of concurrent uhost creation requests." )
442449 req .VPCId = flags .String ("vpc-id" , "" , "Optional. VPC ID. This field is required under VPC2.0. See 'ucloud vpc list'" )
443450 req .SubnetId = flags .String ("subnet-id" , "" , "Optional. Subnet ID. This field is required under VPC2.0. See 'ucloud subnet list'" )
444451 req .Name = flags .String ("name" , "UHost" , "Optional. UHost instance name" )
@@ -518,7 +525,7 @@ func NewCmdUHostCreate() *cobra.Command {
518525 return cmd
519526}
520527
521- //createUhostWrapper 处理UI和并发控制
528+ // createUhostWrapper 处理UI和并发控制
522529func createUhostWrapper (req * uhost.CreateUHostInstanceRequest , updateEIPReq * unet.UpdateEIPAttributeRequest , bindEipID string , async bool , retCh chan <- bool , wg * sync.WaitGroup , tokens chan struct {}, idx int ) {
523530 //控制并发数量
524531 tokens <- struct {}{}
@@ -640,7 +647,7 @@ func getEIPByUHostId(uhostId string) (*uhost.UHostIPSet, error) {
640647 return nil , fmt .Errorf ("can not get eip by uhost[%s]" , uhostId )
641648}
642649
643- //NewCmdUHostDelete ucloud uhost delete
650+ // NewCmdUHostDelete ucloud uhost delete
644651func NewCmdUHostDelete () * cobra.Command {
645652 var uhostIDs * []string
646653 var isDestroy = sdk .Bool (false )
@@ -740,7 +747,7 @@ func deleteUHost(creq request.Common) (bool, []string) {
740747 return true , logs
741748}
742749
743- //NewCmdUHostStop ucloud uhost stop
750+ // NewCmdUHostStop ucloud uhost stop
744751func NewCmdUHostStop (out io.Writer ) * cobra.Command {
745752 var uhostIDs * []string
746753 var async * bool
@@ -802,7 +809,7 @@ func stopUhostIns(req *uhost.StopUHostInstanceRequest, async bool, out io.Writer
802809 return poller .Poll (resp .UHostId , * req .ProjectId , * req .Region , * req .Zone , text , []string {status .HOST_STOPPED , status .HOST_FAIL })
803810}
804811
805- //可并发调用版本
812+ // 可并发调用版本
806813func stopUhostInsV2 (req * uhost.StopUHostInstanceRequest , async bool , block * ux.Block ) {
807814 resp , err := base .BizClient .StopUHostInstance (req )
808815 if err != nil {
@@ -818,7 +825,7 @@ func stopUhostInsV2(req *uhost.StopUHostInstanceRequest, async bool, block *ux.B
818825 }
819826}
820827
821- //NewCmdUHostStart ucloud uhost start
828+ // NewCmdUHostStart ucloud uhost start
822829func NewCmdUHostStart (out io.Writer ) * cobra.Command {
823830 var async * bool
824831 var uhostIDs * []string
@@ -860,7 +867,7 @@ func NewCmdUHostStart(out io.Writer) *cobra.Command {
860867 return cmd
861868}
862869
863- //NewCmdUHostReboot ucloud uhost restart
870+ // NewCmdUHostReboot ucloud uhost restart
864871func NewCmdUHostReboot (out io.Writer ) * cobra.Command {
865872 var uhostIDs * []string
866873 var async * bool
@@ -903,7 +910,7 @@ func NewCmdUHostReboot(out io.Writer) *cobra.Command {
903910 return cmd
904911}
905912
906- //NewCmdUHostPoweroff ucloud uhost poweroff
913+ // NewCmdUHostPoweroff ucloud uhost poweroff
907914func NewCmdUHostPoweroff (out io.Writer ) * cobra.Command {
908915 var yes * bool
909916 var uhostIDs * []string
@@ -992,7 +999,7 @@ func tryStopUhost(req *uhost.ResizeAttachedDiskRequest, uhostID, promptText stri
992999 return nil
9931000}
9941001
995- //NewCmdUHostResize ucloud uhost resize
1002+ // NewCmdUHostResize ucloud uhost resize
9961003func NewCmdUHostResize (out io.Writer ) * cobra.Command {
9971004 var yes , async * bool
9981005 var bootDiskSize , dataDiskSize int
@@ -1190,7 +1197,7 @@ func getUhostList(states []string, project, region, zone string) []string {
11901197 return list
11911198}
11921199
1193- //NewCmdUHostClone ucloud uhost clone
1200+ // NewCmdUHostClone ucloud uhost clone
11941201func NewCmdUHostClone (out io.Writer ) * cobra.Command {
11951202 var uhostID * string
11961203 var async * bool
@@ -1295,7 +1302,7 @@ func NewCmdUHostClone(out io.Writer) *cobra.Command {
12951302 return cmd
12961303}
12971304
1298- //NewCmdUhostCreateImage ucloud uhost create-image
1305+ // NewCmdUhostCreateImage ucloud uhost create-image
12991306func NewCmdUhostCreateImage (out io.Writer ) * cobra.Command {
13001307 var async * bool
13011308 req := base .BizClient .NewCreateCustomImageRequest ()
@@ -1339,7 +1346,7 @@ func NewCmdUhostCreateImage(out io.Writer) *cobra.Command {
13391346 return cmd
13401347}
13411348
1342- //NewCmdUhostResetPassword ucloud uhost reset-password
1349+ // NewCmdUhostResetPassword ucloud uhost reset-password
13431350func NewCmdUhostResetPassword (out io.Writer ) * cobra.Command {
13441351 var yes * bool
13451352 var uhostIDs * []string
@@ -1423,7 +1430,7 @@ func checkAndCloseUhost(yes, async bool, uhostID, project, region, zone string,
14231430 return nil
14241431}
14251432
1426- //NewCmdUhostReinstallOS ucloud uhost reinstall-os
1433+ // NewCmdUhostReinstallOS ucloud uhost reinstall-os
14271434func NewCmdUhostReinstallOS (out io.Writer ) * cobra.Command {
14281435 var isReserveDataDisk , yes , async * bool
14291436 req := base .BizClient .NewReinstallUHostInstanceRequest ()
@@ -1514,7 +1521,7 @@ func NewCmdUhostReinstallOS(out io.Writer) *cobra.Command {
15141521 return cmd
15151522}
15161523
1517- //NewCmdUhostLeaveIsolationGroup ucloud uhost leave-isolation-group
1524+ // NewCmdUhostLeaveIsolationGroup ucloud uhost leave-isolation-group
15181525func NewCmdUhostLeaveIsolationGroup (out io.Writer ) * cobra.Command {
15191526 var uhostIds []string
15201527 req := base .BizClient .NewLeaveIsolationGroupRequest ()
@@ -1562,7 +1569,7 @@ func NewCmdUhostLeaveIsolationGroup(out io.Writer) *cobra.Command {
15621569 return cmd
15631570}
15641571
1565- //NewCmdIsolation ucloud uhost isolation-gorup
1572+ // NewCmdIsolation ucloud uhost isolation-gorup
15661573func NewCmdIsolation (out io.Writer ) * cobra.Command {
15671574 cmd := & cobra.Command {
15681575 Use : "isolation-group" ,
@@ -1575,7 +1582,7 @@ func NewCmdIsolation(out io.Writer) *cobra.Command {
15751582 return cmd
15761583}
15771584
1578- //NewCmdIsolationCreate ucloud uhost isolation-group create
1585+ // NewCmdIsolationCreate ucloud uhost isolation-group create
15791586func NewCmdIsolationCreate (out io.Writer ) * cobra.Command {
15801587 req := base .BizClient .NewCreateIsolationGroupRequest ()
15811588 cmd := & cobra.Command {
@@ -1608,7 +1615,7 @@ func NewCmdIsolationCreate(out io.Writer) *cobra.Command {
16081615 return cmd
16091616}
16101617
1611- //NewCmdIsolationDelete ucloud uhost
1618+ // NewCmdIsolationDelete ucloud uhost
16121619func NewCmdIsolationDelete (out io.Writer ) * cobra.Command {
16131620 var ids []string
16141621 req := base .BizClient .NewDeleteIsolationGroupRequest ()
@@ -1650,7 +1657,7 @@ type isolationGroupRow struct {
16501657 UHostCount string
16511658}
16521659
1653- //NewCmdIsolationList ucloud uhost isolation-group list
1660+ // NewCmdIsolationList ucloud uhost isolation-group list
16541661func NewCmdIsolationList (out io.Writer ) * cobra.Command {
16551662 req := base .BizClient .NewDescribeIsolationGroupRequest ()
16561663 cmd := & cobra.Command {
0 commit comments